Performance: Migrations for schema changes
This affects page load speed indirectly by controlling database schema updates without blocking server responses or causing downtime.
const migrate = require('migrate'); migrate.load({}, (err, set) => { if (err) throw err; set.up((err) => { if (err) throw err; app.listen(3000, () => { console.log('Server started after migrations'); }); }); });
// Directly run ALTER TABLE queries before server start db.query('ALTER TABLE users ADD COLUMN age INT', (err) => { if (err) throw err; app.listen(3000, () => { console.log('Server started'); }); }); // Server blocks startup until migration finishes
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous migrations on server start | 0 | 0 | 0 | [X] Bad |
| Asynchronous migrations before server start | 0 | 0 | 0 | [OK] Good |
sequelize migration:create --name <name>.module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn('Users', 'age', { type: Sequelize.INTEGER });
},
down: async (queryInterface) => {
await queryInterface.removeColumn('Users', 'age');
}
};
What will happen when this migration is run?module.exports = {
up: async (queryInterface) => {
await queryInterface.renameColumn('Users', 'username', 'user_name');
},
down: async (queryInterface) => {
await queryInterface.renameColumn('Users', 'user_name', 'username');
}
};
What is the most likely cause of the error?Pass the test and this pattern moves unknown