references/details.md
GitHubdatabase-migration — additional patterns and templates
Zero-Downtime Migrations
Blue-Green Deployment Strategy
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn("users", "email_new", {
type: Sequelize.STRING,
});
},
};
module.exports = {
up: async (queryInterface) => {
await queryInterface.sequelize.query(`
UPDATE users
SET email_new = email
WHERE email_new IS NULL
`);
},
};
module.exports = {
up: async (queryInterface) => {
await queryInterface.removeColumn("users", "email");
},
};
Cross-Database Migrations
PostgreSQL to MySQL
module.exports = {
up: async (queryInterface, Sequelize) => {
const dialectName = queryInterface.sequelize.getDialect();
if (dialectName === "mysql") {
await queryInterface.createTable("users", {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
data: {
type: Sequelize.JSON,
},
});
} else if (dialectName === "postgres") {
await queryInterface.createTable("users", {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
data: {
type: Sequelize.JSONB,
},
});
}
},
};