When getting started with sequelize, I simply used force:true
to keep the database working for development, but now that I'm transitioning to test/production this is obviously no longer a good choice.
I've defined my schema in my code like such:
this.Users = this.sequelize.define('Users', {
email: Sequelize.STRING,
display: Sequelize.STRING,
lastlogin: Sequelize.DATE,
});
this.Patterns = this.sequelize.define('Patterns', {
name: Sequelize.STRING,
type: Sequelize.STRING,
});
this.Patterns.belongsTo(this.Users, {as: 'Owner'});
... //a number of other models and relationships
What's the "correct" way to turn this into a database initialization workflow? In particular, I'm thinking that it makes sense to make this take place in an "init" migration so that future migrations and code changes work off of it and so that any time in the future I can just run the stack of migrations to get a fully up-to-date schema.
Edit: Things that I have considered and would likely work, but don't seem like sufficiently "elegant" solutions.
- Initting a new database with
force:true
and capturing the generated SQL to create a "setup.sql" that I can run on a new database. - Rewriting my entire schema in "migration notation" which is identical in what it describes but annoyingly different in syntax.