Make migration management more robust

This commit is contained in:
mikiher 2024-09-07 22:24:19 +03:00
parent b3ce300d32
commit 8a28029809
6 changed files with 222 additions and 160 deletions

View file

@ -1,15 +1,15 @@
const { DataTypes } = require('sequelize')
const Logger = require('../../../server/Logger')
/**
* This is an example of an upward migration script.
*
* @param {import { QueryInterface } from "sequelize";} options.context.queryInterface - a suquelize QueryInterface object.
* @param {import { Logger } from "../../../server/Logger";} options.context.logger - a Logger object.
* @returns {Promise<void>} - A promise that resolves when the migration is complete.
*/
async function up({ context: queryInterface }) {
Logger.info('Running migration_example up...')
Logger.info('Creating example_table...')
async function up({ context: { queryInterface, logger } }) {
logger.info('Running migration_example up...')
logger.info('Creating example_table...')
await queryInterface.createTable('example_table', {
id: {
type: DataTypes.INTEGER,
@ -21,22 +21,23 @@ async function up({ context: queryInterface }) {
allowNull: false
}
})
Logger.info('example_table created.')
Logger.info('migration_example up complete.')
logger.info('example_table created.')
logger.info('migration_example up complete.')
}
/**
* This is an example of a downward migration script.
*
* @param {import { QueryInterface } from "sequelize";} options.context.queryInterface - a suquelize QueryInterface object.
* @param {import { Logger } from "../../../server/Logger";} options.context.logger - a Logger object.
* @returns {Promise<void>} - A promise that resolves when the migration is complete.
*/
async function down({ context: queryInterface }) {
Logger.info('Running migration_example down...')
Logger.info('Dropping example_table...')
async function down({ context: { queryInterface, logger } }) {
logger.info('Running migration_example down...')
logger.info('Dropping example_table...')
await queryInterface.dropTable('example_table')
Logger.info('example_table dropped.')
Logger.info('migration_example down complete.')
logger.info('example_table dropped.')
logger.info('migration_example down complete.')
}
module.exports = { up, down }