Repository navigation
Track when the migration is applied #90
Unanswered
gauravarora
asked this question in
Ideas
Replies: 5 comments 1 reply
|
I should have been clearer with my question. I would like to know the timestamp when the migration was applied. |
0 replies
|
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. |
0 replies
|
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}) |
0 replies
|
@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;
})
})
} |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Perhaps with a column in
sequelize_meta? This is just for informational purposes really.All reactions