audiobookshelf/test/server/migrations/v0.0.1-migration_example.js

51 lines
1.6 KiB
JavaScript
Raw Normal View History

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.
*/
/**
* 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.
* @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...')
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.')
}
/**
* 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.
* @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...')
await queryInterface.dropTable('example_table')
2024-09-07 21:24:19 +02:00
logger.info('example_table dropped.')
logger.info('migration_example down complete.')
}
module.exports = { up, down }