diff --git a/packages/admin/src/server/migrations.ts b/packages/admin/src/server/migrations.ts index 937be38b..2b497b56 100644 --- a/packages/admin/src/server/migrations.ts +++ b/packages/admin/src/server/migrations.ts @@ -122,6 +122,7 @@ export const migrationsRotuer = trpc.router({ const {content, info} = await migrator.generateDownMigration({name: input.name}) const downPath = migrator.downPath(info.migration.path as string) + await fs.promises.mkdir(path.dirname(downPath), {recursive: true}) await fs.promises.writeFile(downPath, content) return {downPath, content} }), diff --git a/packages/migrator/src/migrator.ts b/packages/migrator/src/migrator.ts index c0b40639..24632301 100644 --- a/packages/migrator/src/migrator.ts +++ b/packages/migrator/src/migrator.ts @@ -384,7 +384,8 @@ export class Migrator extends umzug.Umzug { pgpOptions: this.client.pgpOptions, }) - const migrator = new Migrator({...this.migratorOptions, client}) + const MigratorClass = this.constructor as typeof Migrator // todo: how do we know we can pass the same kind of constructor parameters to this + const migrator = new MigratorClass({...this.migratorOptions, client}) const create = () => this.client.query(sql`create database ${sql.identifier([dbName])}`) diff --git a/packages/schemainspect/src/misc.ts b/packages/schemainspect/src/misc.ts index 7f1b505e..7a84bd67 100644 --- a/packages/schemainspect/src/misc.ts +++ b/packages/schemainspect/src/misc.ts @@ -51,17 +51,17 @@ export const unquoted_identifier = (identifier: string, schema?: string, identit return s } +export const canSkipQuotes = (identifier: string) => /^[_a-z]+$/.test(identifier) + export const quoted_identifier = (identifier: string, schema?: string, identity_arguments?: string) => { - // let s = [identifier, schema] - // .filter(Boolean) - // .map(s => (/^[\d_a-z]+$/.test(s) ? s : `"${s.replaceAll(`"`, `""`)}"`)) - // .join('.') + // if (canSkipQuotes(identifier) && !schema && !identity_arguments) { + // return identifier // no need for quotes + // } - // if (identity_arguments) { - // s += `(${identity_arguments})` + // if (canSkipQuotes(identifier) && canSkipQuotes(schema) && !identity_arguments) { + // return `${schema}.${identifier}` // no need for quotes // } - // return s if (!identifier && schema) { return `"${schema.replaceAll(`"`, '""')}"` }