refactor: prepare multi-machine inventory associations
This commit is contained in:
42
scripts/cleanup-custom-fields.ts
Normal file
42
scripts/cleanup-custom-fields.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
async function main () {
|
||||
try {
|
||||
console.log('Starting custom fields cleanup...')
|
||||
|
||||
const deletedValues = await prisma.customFieldValue.deleteMany({
|
||||
where: {
|
||||
customField: {
|
||||
OR: [
|
||||
{ typeComposantId: { not: null } },
|
||||
{ typePieceId: { not: null } },
|
||||
{ typeMachineId: { not: null } }
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
console.log(`Deleted ${deletedValues.count} custom field values linked to type-level definitions.`)
|
||||
|
||||
const deletedFields = await prisma.customField.deleteMany({
|
||||
where: {
|
||||
OR: [
|
||||
{ typeComposantId: { not: null } },
|
||||
{ typePieceId: { not: null } },
|
||||
{ typeMachineId: { not: null } }
|
||||
]
|
||||
}
|
||||
})
|
||||
console.log(`Deleted ${deletedFields.count} custom field definitions linked to model types.`)
|
||||
|
||||
console.log('Cleanup complete.')
|
||||
} catch (error) {
|
||||
console.error('Cleanup failed:', error)
|
||||
process.exitCode = 1
|
||||
} finally {
|
||||
await prisma.$disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user