2024-09-04 11:48:10 +02:00
|
|
|
const { DataTypes } = require('sequelize')
|
|
|
|
|
2024-09-10 22:57:07 +02:00
|
|
|
/**
|
|
|
|
* @typedef MigrationContext
|
|
|
|
* @property {import('sequelize').QueryInterface} queryInterface - a suquelize QueryInterface object.
|
|
|
|
* @property {import('../Logger')} logger - a Logger object.
|
|
|
|
*
|
|
|
|
* @typedef MigrationOptions
|
|
|
|
* @property {MigrationContext} context - an object containing the migration context.
|
|
|
|
*/
|
|
|
|
|
2024-09-04 11:48:10 +02:00
|
|
|
/**
|
|
|
|
* This is an example of an upward migration script.
|
|
|
|
*
|
2024-09-10 22:57:07 +02:00
|
|
|
* @param {MigrationOptions} options - an object containing the migration context.
|
2024-09-04 11:48:10 +02:00
|
|
|
* @returns {Promise<void>} - A promise that resolves when the migration is complete.
|
|
|
|
*/
|
2024-09-07 21:24:19 +02:00
|
|
|
async function up({ context: { queryInterface, logger } }) {
|
|
|
|
logger.info('Running migration_example up...')
|
|
|
|
logger.info('Creating example_table...')
|
2024-09-04 11:48:10 +02:00
|
|
|
await queryInterface.createTable('example_table', {
|
|
|
|
id: {
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
primaryKey: true,
|
|
|
|
autoIncrement: true
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: false
|
|
|
|
}
|
|
|
|
})
|
2024-09-07 21:24:19 +02:00
|
|
|
logger.info('example_table created.')
|
|
|
|
logger.info('migration_example up complete.')
|
2024-09-04 11:48:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is an example of a downward migration script.
|
|
|
|
*
|
2024-09-10 22:57:07 +02:00
|
|
|
* @param {MigrationOptions} options - an object containing the migration context.
|
2024-09-04 11:48:10 +02:00
|
|
|
* @returns {Promise<void>} - A promise that resolves when the migration is complete.
|
|
|
|
*/
|
2024-09-07 21:24:19 +02:00
|
|
|
async function down({ context: { queryInterface, logger } }) {
|
|
|
|
logger.info('Running migration_example down...')
|
|
|
|
logger.info('Dropping example_table...')
|
2024-09-04 11:48:10 +02:00
|
|
|
await queryInterface.dropTable('example_table')
|
2024-09-07 21:24:19 +02:00
|
|
|
logger.info('example_table dropped.')
|
|
|
|
logger.info('migration_example down complete.')
|
2024-09-04 11:48:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { up, down }
|