First
First
DTDrizzle Team
Created by First on 8/20/2024 in #help
Drizzle Migration but with TS code
Does anyone have an idea about running TS code during migration. I'm thinking of moving from knex.js to drizzle (a migration part). In knex.js, it's quite convenient since the migration is TS code, example: if I want to alter a nullable column to non-nullable column, I would want to run a script to set value for it before alter it and to do that, I could use a complex update like ...
# add value to null column
db
.update(table)
.set({ column: db.query.anotherTable.findFirst({...}).returning("id") })
.where(...)

# alter once all value is not null
db.table(table).alter(...).notNullable()
# add value to null column
db
.update(table)
.set({ column: db.query.anotherTable.findFirst({...}).returning("id") })
.where(...)

# alter once all value is not null
db.table(table).alter(...).notNullable()

Or I could even re-use the function I have been already wrote in service layer like, for example, since it's already tested and limit the risk.
# add value to null column
tableService.updateAllInColumn(anotherTable.getX())

# alter once all value is not null
db.table(table).alter(...).notNullable()
# add value to null column
tableService.updateAllInColumn(anotherTable.getX())

# alter once all value is not null
db.table(table).alter(...).notNullable()

Does anyone have this kind of use case? how do you run a one-time script, do you run it in TS migration file or how do you solve this case with SQL migration file?
7 replies