db-migrate / node-db-migrate

Database migration framework for node
Other
2.32k stars 360 forks source link

Multiple schema support or tricks #818

Open legithubdeaymeric opened 1 year ago

legithubdeaymeric commented 1 year ago

I'm submitting a...

Current behavior

Good morning

Quick question. Is there a way to manipulate tables other than the default schema.

for example I would like to create a table in several schemas

db.createTable('OTHER_SCHEMA.table', { id: { type: 'int', primaryKey: true }, name: 'string' });

Thanks !

Environment


db-migrate version: 0.11.13
db-migrate-pg with versions: 1.3.0            
wzrdtales commented 1 year ago

not officially supported. You can have multiple scopes: https://db-migrate.readthedocs.io/en/latest/Getting%20Started/commands/#scoping . Scopes have db switching support.

https://github.com/db-migrate/pg/blob/b64a02aefff39af750099c5c57bb74ab47937d05/index.js#L128 This is the relevant endpoint, for pg you can actually only switch the schema not the database. Which is due to this method also theoretically callable from the driver and the non guarantee of being able to switch the db on the same connection.