Logging the DDL statements executed during a migration will greatly help troubleshooting, debugging, and manually recovering from a failed migration.
The current behaviour just appears to log the last error received from the database driver. If the error contains some identifiable context, maybe that helps, but if the error is more generic, we are completely lost.
Current behaviour when an error occurs:
We don't know which migration files were executed (ie. 0012_funky_horse_calipers.sql worked but 0013_sad_panda_noises.sql failed)
We don't know which DDL statement within a migration fail caused the error.
I suggest that when config.verbose is false, the migrate command should just log the name of each migration file before its DDL statements are executed. When config.verbose is true, the migrate command should also log each DDL right before it is executed. Then the migration command output should be detailed enough to troubleshoot the problem.
Here is an example error (caused by a manual edit of a migration file which was pushed without a local test)
npx drizzle-kit migrate --config=drizzle.config.ts
drizzle-kit: v0.21.2
drizzle-orm: v0.30.10
Custom config path was provided, using 'drizzle.config.ts'
Reading config file '{redacted}/drizzle.config.ts'
Using 'pg' driver for database querying
[⣷] applying migrations...error: type "bermy" does not exist
at /{redacted}/node_modules/drizzle-kit/bin.cjs:62266:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at <anonymous> ({redacted}/node_modules/src/pg-core/dialect.ts:89:7)
at NodePgSession.transaction ({redacted}/node_modules/src/node-postgres/session.ts:155:19)
at PgDialect.migrate ({redacted}/node_modules/src/pg-core/dialect.ts:82:3)
at migrate ({redacted}/node_modules/src/node-postgres/migrator.ts:10:2) {
length: 93,
severity: 'ERROR',
code: '42704',
detail: undefined,
hint: undefined,
position: '209',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_type.c',
line: '271',
routine: 'typenameType'
}
Logging the DDL statements executed during a migration will greatly help troubleshooting, debugging, and manually recovering from a failed migration.
The current behaviour just appears to log the last error received from the database driver. If the error contains some identifiable context, maybe that helps, but if the error is more generic, we are completely lost.
Current behaviour when an error occurs:
0012_funky_horse_calipers.sql
worked but0013_sad_panda_noises.sql
failed)I suggest that when
config.verbose
is false, themigrate
command should just log the name of each migration file before its DDL statements are executed. Whenconfig.verbose
is true, themigrate
command should also log each DDL right before it is executed. Then themigration
command output should be detailed enough to troubleshoot the problem.Here is an example error (caused by a manual edit of a migration file which was pushed without a local test)
My drizzle.config.ts is:
Thanks for the great work so far!