sequelize-migreat
v4.5.0
Published
Migreat makes migrations with Sequelize models easy. You define a schema with models and associations using a Migreat interface. Migreat generates Typescript migration files.
Downloads
124
Readme
Migreat
Migreat makes migrations with Sequelize models easy. You define a schema with models and associations using a Migreat interface. Migreat generates Typescript migration files.
Defining Schema's, Models and Associations
Define a model as follows:
const model = Migreat.defineModel<ModelType>({
name: 'table name',
attributes: {
key: Migreat.Attr.uuid()
},
associations: {
key: Migreat.Assoc.belongsTo(OtherModel, { localKey: string })
}
})
Attributes and association types described in .. ?
A schema is simply a set of models, defined like so:
const schemaDef = new Migreat.SchemaDef([modelA, modelB, ...])
Generate Migrations
Migrations are sorted by ascending name.
Generating a migration from a schema definition
To generate the first migration from a schema definition, do:
Migreat.generateMigrationFromSchema(schemaDef): Migration
Generating a migration from migrations
To generate subsequent migrations, do:
Migreat.generateMigrationFromMigration(migration, targetSchemaDef): Migration
Execute
To execute a migration, do
Migreat.executeMigration(migration, dbConfig)