Update index creation migration to be idempotent

This commit is contained in:
advplyr 2024-10-19 15:45:14 -05:00
parent 84012d9090
commit 35e2681ea9

View File

@ -19,15 +19,25 @@ async function up({ context: { queryInterface, logger } }) {
// Create index for bookAuthors // Create index for bookAuthors
logger.info('[2.15.2 migration] Creating index for bookAuthors') logger.info('[2.15.2 migration] Creating index for bookAuthors')
const bookAuthorsIndexes = await queryInterface.showIndex('bookAuthors')
if (!bookAuthorsIndexes.some((index) => index.name === 'bookAuthor_authorId')) {
await queryInterface.addIndex('bookAuthors', ['authorId'], { await queryInterface.addIndex('bookAuthors', ['authorId'], {
name: 'bookAuthor_authorId' name: 'bookAuthor_authorId'
}) })
} else {
logger.info('[2.15.2 migration] Index bookAuthor_authorId already exists')
}
// Create index for bookSeries // Create index for bookSeries
logger.info('[2.15.2 migration] Creating index for bookSeries') logger.info('[2.15.2 migration] Creating index for bookSeries')
const bookSeriesIndexes = await queryInterface.showIndex('bookSeries')
if (!bookSeriesIndexes.some((index) => index.name === 'bookSeries_seriesId')) {
await queryInterface.addIndex('bookSeries', ['seriesId'], { await queryInterface.addIndex('bookSeries', ['seriesId'], {
name: 'bookSeries_seriesId' name: 'bookSeries_seriesId'
}) })
} else {
logger.info('[2.15.2 migration] Index bookSeries_seriesId already exists')
}
// Delete existing podcastEpisode index // Delete existing podcastEpisode index
logger.info('[2.15.2 migration] Deleting existing podcastEpisode index') logger.info('[2.15.2 migration] Deleting existing podcastEpisode index')
@ -35,9 +45,14 @@ async function up({ context: { queryInterface, logger } }) {
// Create index for podcastEpisode and createdAt // Create index for podcastEpisode and createdAt
logger.info('[2.15.2 migration] Creating index for podcastEpisode and createdAt') logger.info('[2.15.2 migration] Creating index for podcastEpisode and createdAt')
const podcastEpisodesIndexes = await queryInterface.showIndex('podcastEpisodes')
if (!podcastEpisodesIndexes.some((index) => index.name === 'podcastEpisode_createdAt_podcastId')) {
await queryInterface.addIndex('podcastEpisodes', ['createdAt', 'podcastId'], { await queryInterface.addIndex('podcastEpisodes', ['createdAt', 'podcastId'], {
name: 'podcastEpisode_createdAt_podcastId' name: 'podcastEpisode_createdAt_podcastId'
}) })
} else {
logger.info('[2.15.2 migration] Index podcastEpisode_createdAt_podcastId already exists')
}
// Completed migration // Completed migration
logger.info('[2.15.2 migration] UPGRADE END: 2.15.2-index-creation') logger.info('[2.15.2 migration] UPGRADE END: 2.15.2-index-creation')