orchid-orm icon indicating copy to clipboard operation
orchid-orm copied to clipboard

Running into this error when my db has more than one schema when using the migration generate command. Other commands are ok

Open NelsonMK opened this issue 9 months ago • 1 comments

For better context, I am using pg-boss for background jobs and it creates its own schema pgboss

Tried specifying which schema to use but no luck

export const change = rakeDb(
	{
		databaseURL: process.env.DATABASE_URL,
		schema: 'public',
	},
	{
		baseTable: BaseTable,
		snakeCase: true,
		migrationId: 'serial',
		migrationsPath: './migrations',
		migrationsTable: 'schema_migrations',
		dbPath: './db',
		import: (path) => import(path),
		log: true,
		async beforeChange({ db }) {
                        //confirm we are dealing with public schema
			console.log((await db.query`SHOW search_path`).rows[0]);
		},
	},
);

The error I get:

C:\development\node\project\node_modules\rake-db\src\generate\astToMigration.ts:121
        new Error(
        ^


Error: Cannot satisfy migration dependencies: [
  {
    "ast": {
      "type": "schema",
      "action": "drop",
      "name": "pgboss"
    },
    "add": [],
    "drop": [
      "pgboss"
    ],
    "deps": []
  }
]

NelsonMK avatar Apr 03 '25 17:04 NelsonMK

There is a generatorIgnore option to ignore tables, but not schemas yet, I'll add so you can list schemas and other db structures for the migrations generator to ignore.

Not sure why this error is happening, will fix.

romeerez avatar Apr 13 '25 09:04 romeerez

I added generatorIgnore config for this case, add the following to orchidORM:

export const db = orchidORM(
  {
    // ...other options
    generatorIgnore: {
      // pgboss library keeps all its db objects in the `pgboss` schema.
      schemas: ['pgboss'],
   }
   //...
)

And the generator will ignore everything in the pgboss schema.

Fixed one bug in the generator along the way, thank you for helping discovering it.

romeerez avatar May 05 '25 19:05 romeerez

Works like a charm. Thank you.

NelsonMK avatar May 07 '25 10:05 NelsonMK