Track when the migration is applied #90
Replies: 5 comments 1 reply
-
Yeah, it is possible with events. |
Beta Was this translation helpful? Give feedback.
-
I should have been clearer with my question. I would like to know the timestamp when the migration was applied. |
Beta Was this translation helpful? Give feedback.
-
Aha, it is possible if and only if storage supports it. Currently official storages don't save timestamp but you can always write your own storage. I think someone else would appreciate timestamps too. I add this to v2.0 backlog. |
Beta Was this translation helpful? Give feedback.
-
easy with CustomStorage (and sequelize) const sequelize = require('sequelize'); //your sequelize instance with models
class CustomStorage {
logMigration(migrationName) {
return sequelize.models.Migration.create({name: migrationName, finished_at: new Date()})
}
unlogMigration(migrationName) {
return sequelize.models.Migration.findOne({name: migrationName})
.then((model) => {
return model.destroy();
})
}
executed() {
return sequelize.models.Migration.findAll()
.then((results) => {
return results.map((item) => {
return item.name;
})
})
}
}
let umzug = new Umzug({
storage: new CustomStorage(),
//possible other options
}); ...and migrations table const Sequelize = require('sequelize');
let sequelize = new Sequelize(...);
sequelize.define('Migration', {
id: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true},
name: Sequelize.STRING(255),
finished_at: Sequelize.DATE
}, {tableName: 'migrations', timestamps: false}) |
Beta Was this translation helpful? Give feedback.
-
@geosaj great example, thnx. But it doesn't work for executed() {
return sequelize.models.Migration.findAll({ order: [ ['id', 'DESC'] ] })
.then((results) => {
return results.map((item) => {
return item.name;
})
})
} |
Beta Was this translation helpful? Give feedback.
-
Perhaps with a column in
sequelize_meta
? This is just for informational purposes really.Beta Was this translation helpful? Give feedback.
All reactions