'How to run migrations with dynamic schemas?
I'm using Sequelize (Postgres) and I'm trying to dynamically create schemas and run migrations in them. In other words, I'm not using sequelize.define
, because I have no purpose for it. I create the migrations with npx sequelize-cli model:generate
and I want to run the migrations with npx sequelize-cli db:migrate
.
However, this keeps throwing the error,
ERROR: no schema has been selected to create in
I've tried instantiation sequilize
as so,
// at this point, the schema already exists
const sequelize = new Sequelize(sequelizeConnectionString(schema.schema_name)); // generates dynamic connection string with required schema
await sequelize.authenticate();
// . . . logic for generating
// . . . the migrations with
await sequelize.sync(); // no error thrown
But this doesn't do anything.
How can I take my dynamically generated migration scripts and run them with npx sequelize-cli db:migrate
with the needed schema?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|