mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Update migration to v2.14.0
This commit is contained in:
		
							parent
							
								
									c67b5e950e
								
							
						
					
					
						commit
						5154e31c1c
					
				@ -4,4 +4,4 @@ Please add a record of every database migration that you create to this file. Th
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
| Server Version | Migration Script Name        | Description                                       |
 | 
					| Server Version | Migration Script Name        | Description                                       |
 | 
				
			||||||
| -------------- | ---------------------------- | ------------------------------------------------- |
 | 
					| -------------- | ---------------------------- | ------------------------------------------------- |
 | 
				
			||||||
| v2.13.5        | v2.13.5-series-column-unique | Series must have unique names in the same library |
 | 
					| v2.14.0        | v2.14.0-series-column-unique | Series must have unique names in the same library |
 | 
				
			||||||
 | 
				
			|||||||
@ -16,13 +16,13 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
async function up({ context: { queryInterface, logger } }) {
 | 
					async function up({ context: { queryInterface, logger } }) {
 | 
				
			||||||
  // Upwards migration script
 | 
					  // Upwards migration script
 | 
				
			||||||
  logger.info('[2.13.5 migration] UPGRADE BEGIN: 2.13.5-series-column-unique ')
 | 
					  logger.info('[2.14.0 migration] UPGRADE BEGIN: 2.14.0-series-column-unique ')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Check if the unique index already exists
 | 
					  // Check if the unique index already exists
 | 
				
			||||||
  const seriesIndexes = await queryInterface.showIndex('Series')
 | 
					  const seriesIndexes = await queryInterface.showIndex('Series')
 | 
				
			||||||
  if (seriesIndexes.some((index) => index.name === 'unique_series_name_per_library')) {
 | 
					  if (seriesIndexes.some((index) => index.name === 'unique_series_name_per_library')) {
 | 
				
			||||||
    logger.info('[2.13.5 migration] Unique index on Series.name and Series.libraryId already exists')
 | 
					    logger.info('[2.14.0 migration] Unique index on Series.name and Series.libraryId already exists')
 | 
				
			||||||
    logger.info('[2.13.5 migration] UPGRADE END: 2.13.5-series-column-unique ')
 | 
					    logger.info('[2.14.0 migration] UPGRADE END: 2.14.0-series-column-unique ')
 | 
				
			||||||
    return
 | 
					    return
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -43,12 +43,12 @@ async function up({ context: { queryInterface, logger } }) {
 | 
				
			|||||||
  `)
 | 
					  `)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Print out how many duplicates were found
 | 
					  // Print out how many duplicates were found
 | 
				
			||||||
  logger.info(`[2.13.5 migration] Found ${duplicates.length} duplicate series`)
 | 
					  logger.info(`[2.14.0 migration] Found ${duplicates.length} duplicate series`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Iterate over each duplicate series
 | 
					  // Iterate over each duplicate series
 | 
				
			||||||
  for (const duplicate of duplicates) {
 | 
					  for (const duplicate of duplicates) {
 | 
				
			||||||
    // Report the series name that is being deleted
 | 
					    // Report the series name that is being deleted
 | 
				
			||||||
    logger.info(`[2.13.5 migration] Deduplicating series "${duplicate.name}" in library ${duplicate.libraryId}`)
 | 
					    logger.info(`[2.14.0 migration] Deduplicating series "${duplicate.name}" in library ${duplicate.libraryId}`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Determine any duplicate book IDs in the `bookSeries` table for the same series
 | 
					    // Determine any duplicate book IDs in the `bookSeries` table for the same series
 | 
				
			||||||
    const [duplicateBookIds] = await queryInterface.sequelize.query(
 | 
					    const [duplicateBookIds] = await queryInterface.sequelize.query(
 | 
				
			||||||
@ -73,7 +73,7 @@ async function up({ context: { queryInterface, logger } }) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Iterate over the duplicate book IDs if there is at least one and only keep the first row that has this bookId and seriesId
 | 
					    // Iterate over the duplicate book IDs if there is at least one and only keep the first row that has this bookId and seriesId
 | 
				
			||||||
    for (const { bookId } of duplicateBookIds) {
 | 
					    for (const { bookId } of duplicateBookIds) {
 | 
				
			||||||
      logger.info(`[2.13.5 migration] Deduplicating bookId ${bookId} in series "${duplicate.name}" of library ${duplicate.libraryId}`)
 | 
					      logger.info(`[2.14.0 migration] Deduplicating bookId ${bookId} in series "${duplicate.name}" of library ${duplicate.libraryId}`)
 | 
				
			||||||
      // Get all rows of `BookSeries` table that have the same `bookId` and `seriesId`. Sort by `sequence` with nulls sorted last
 | 
					      // Get all rows of `BookSeries` table that have the same `bookId` and `seriesId`. Sort by `sequence` with nulls sorted last
 | 
				
			||||||
      const [duplicateBookSeries] = await queryInterface.sequelize.query(
 | 
					      const [duplicateBookSeries] = await queryInterface.sequelize.query(
 | 
				
			||||||
        `
 | 
					        `
 | 
				
			||||||
@ -113,7 +113,7 @@ async function up({ context: { queryInterface, logger } }) {
 | 
				
			|||||||
          }
 | 
					          }
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      logger.info(`[2.13.5 migration] Finished cleanup of bookId ${bookId} in series "${duplicate.name}" of library ${duplicate.libraryId}`)
 | 
					      logger.info(`[2.14.0 migration] Finished cleanup of bookId ${bookId} in series "${duplicate.name}" of library ${duplicate.libraryId}`)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Get all the most recent series which matches the `name` and `libraryId`
 | 
					    // Get all the most recent series which matches the `name` and `libraryId`
 | 
				
			||||||
@ -174,16 +174,16 @@ async function up({ context: { queryInterface, logger } }) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  logger.info(`[2.13.5 migration] Deduplication complete`)
 | 
					  logger.info(`[2.14.0 migration] Deduplication complete`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Create a unique index based on the name and library ID for the `Series` table
 | 
					  // Create a unique index based on the name and library ID for the `Series` table
 | 
				
			||||||
  await queryInterface.addIndex('Series', ['name', 'libraryId'], {
 | 
					  await queryInterface.addIndex('Series', ['name', 'libraryId'], {
 | 
				
			||||||
    unique: true,
 | 
					    unique: true,
 | 
				
			||||||
    name: 'unique_series_name_per_library'
 | 
					    name: 'unique_series_name_per_library'
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
  logger.info('[2.13.5 migration] Added unique index on Series.name and Series.libraryId')
 | 
					  logger.info('[2.14.0 migration] Added unique index on Series.name and Series.libraryId')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  logger.info('[2.13.5 migration] UPGRADE END: 2.13.5-series-column-unique ')
 | 
					  logger.info('[2.14.0 migration] UPGRADE END: 2.14.0-series-column-unique ')
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -194,13 +194,13 @@ async function up({ context: { queryInterface, logger } }) {
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
async function down({ context: { queryInterface, logger } }) {
 | 
					async function down({ context: { queryInterface, logger } }) {
 | 
				
			||||||
  // Downward migration script
 | 
					  // Downward migration script
 | 
				
			||||||
  logger.info('[2.13.5 migration] DOWNGRADE BEGIN: 2.13.5-series-column-unique ')
 | 
					  logger.info('[2.14.0 migration] DOWNGRADE BEGIN: 2.14.0-series-column-unique ')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Remove the unique index
 | 
					  // Remove the unique index
 | 
				
			||||||
  await queryInterface.removeIndex('Series', 'unique_series_name_per_library')
 | 
					  await queryInterface.removeIndex('Series', 'unique_series_name_per_library')
 | 
				
			||||||
  logger.info('[2.13.5 migration] Removed unique index on Series.name and Series.libraryId')
 | 
					  logger.info('[2.14.0 migration] Removed unique index on Series.name and Series.libraryId')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  logger.info('[2.13.5 migration] DOWNGRADE END: 2.13.5-series-column-unique ')
 | 
					  logger.info('[2.14.0 migration] DOWNGRADE END: 2.14.0-series-column-unique ')
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = { up, down }
 | 
					module.exports = { up, down }
 | 
				
			||||||
@ -1,13 +1,13 @@
 | 
				
			|||||||
const { expect } = require('chai')
 | 
					const { expect } = require('chai')
 | 
				
			||||||
const sinon = require('sinon')
 | 
					const sinon = require('sinon')
 | 
				
			||||||
const { up, down } = require('../../../server/migrations/v2.13.5-series-column-unique')
 | 
					const { up, down } = require('../../../server/migrations/v2.14.0-series-column-unique')
 | 
				
			||||||
const { Sequelize } = require('sequelize')
 | 
					const { Sequelize } = require('sequelize')
 | 
				
			||||||
const Logger = require('../../../server/Logger')
 | 
					const Logger = require('../../../server/Logger')
 | 
				
			||||||
const { query } = require('express')
 | 
					const { query } = require('express')
 | 
				
			||||||
const { logger } = require('sequelize/lib/utils/logger')
 | 
					const { logger } = require('sequelize/lib/utils/logger')
 | 
				
			||||||
const e = require('express')
 | 
					const e = require('express')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe('migration-v2.13.5-series-column-unique', () => {
 | 
					describe('migration-v2.14.0-series-column-unique', () => {
 | 
				
			||||||
  let sequelize
 | 
					  let sequelize
 | 
				
			||||||
  let queryInterface
 | 
					  let queryInterface
 | 
				
			||||||
  let loggerInfoStub
 | 
					  let loggerInfoStub
 | 
				
			||||||
@ -105,11 +105,11 @@ describe('migration-v2.13.5-series-column-unique', () => {
 | 
				
			|||||||
      await up({ context: { queryInterface, logger: Logger } })
 | 
					      await up({ context: { queryInterface, logger: Logger } })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      expect(loggerInfoStub.callCount).to.equal(5)
 | 
					      expect(loggerInfoStub.callCount).to.equal(5)
 | 
				
			||||||
      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('UPGRADE BEGIN: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('[2.14.0 migration] UPGRADE BEGIN: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.13.5 migration] Found 0 duplicate series'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.14.0 migration] Found 0 duplicate series'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.13.5 migration] Deduplication complete'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.14.0 migration] Deduplication complete'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('[2.14.0 migration] Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('UPGRADE END: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('[2.14.0 migration] UPGRADE END: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      // Validate rows in tables
 | 
					      // Validate rows in tables
 | 
				
			||||||
      const series = await queryInterface.sequelize.query('SELECT "id", "name", "libraryId" FROM Series', { type: queryInterface.sequelize.QueryTypes.SELECT })
 | 
					      const series = await queryInterface.sequelize.query('SELECT "id", "name", "libraryId" FROM Series', { type: queryInterface.sequelize.QueryTypes.SELECT })
 | 
				
			||||||
      expect(series).to.have.length(3)
 | 
					      expect(series).to.have.length(3)
 | 
				
			||||||
@ -145,13 +145,13 @@ describe('migration-v2.13.5-series-column-unique', () => {
 | 
				
			|||||||
      await up({ context: { queryInterface, logger: Logger } })
 | 
					      await up({ context: { queryInterface, logger: Logger } })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      expect(loggerInfoStub.callCount).to.equal(7)
 | 
					      expect(loggerInfoStub.callCount).to.equal(7)
 | 
				
			||||||
      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('UPGRADE BEGIN: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('[2.14.0 migration] UPGRADE BEGIN: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.13.5 migration] Found 2 duplicate series'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.14.0 migration] Found 2 duplicate series'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.13.5 migration] Deduplicating series "Series 1" in library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.14.0 migration] Deduplicating series "Series 1" in library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('[2.13.5 migration] Deduplicating series "Series 3" in library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('[2.14.0 migration] Deduplicating series "Series 3" in library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('[2.13.5 migration] Deduplication complete'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('[2.14.0 migration] Deduplication complete'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(5).calledWith(sinon.match('Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(5).calledWith(sinon.match('[2.14.0 migration] Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(6).calledWith(sinon.match('UPGRADE END: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(6).calledWith(sinon.match('[2.14.0 migration] UPGRADE END: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      // Validate rows
 | 
					      // Validate rows
 | 
				
			||||||
      const series = await queryInterface.sequelize.query('SELECT "id", "name", "libraryId" FROM Series', { type: queryInterface.sequelize.QueryTypes.SELECT })
 | 
					      const series = await queryInterface.sequelize.query('SELECT "id", "name", "libraryId" FROM Series', { type: queryInterface.sequelize.QueryTypes.SELECT })
 | 
				
			||||||
      expect(series).to.have.length(3)
 | 
					      expect(series).to.have.length(3)
 | 
				
			||||||
@ -182,11 +182,11 @@ describe('migration-v2.13.5-series-column-unique', () => {
 | 
				
			|||||||
      await up({ context: { queryInterface, logger: Logger } })
 | 
					      await up({ context: { queryInterface, logger: Logger } })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      expect(loggerInfoStub.callCount).to.equal(5)
 | 
					      expect(loggerInfoStub.callCount).to.equal(5)
 | 
				
			||||||
      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('UPGRADE BEGIN: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('[2.14.0 migration] UPGRADE BEGIN: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.13.5 migration] Found 0 duplicate series'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.14.0 migration] Found 0 duplicate series'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.13.5 migration] Deduplication complete'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.14.0 migration] Deduplication complete'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('[2.14.0 migration] Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('UPGRADE END: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('[2.14.0 migration] UPGRADE END: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      // Validate rows
 | 
					      // Validate rows
 | 
				
			||||||
      const series = await queryInterface.sequelize.query('SELECT "id", "name", "libraryId" FROM Series', { type: queryInterface.sequelize.QueryTypes.SELECT })
 | 
					      const series = await queryInterface.sequelize.query('SELECT "id", "name", "libraryId" FROM Series', { type: queryInterface.sequelize.QueryTypes.SELECT })
 | 
				
			||||||
      expect(series).to.have.length(2)
 | 
					      expect(series).to.have.length(2)
 | 
				
			||||||
@ -212,14 +212,14 @@ describe('migration-v2.13.5-series-column-unique', () => {
 | 
				
			|||||||
      await up({ context: { queryInterface, logger: Logger } })
 | 
					      await up({ context: { queryInterface, logger: Logger } })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      expect(loggerInfoStub.callCount).to.equal(8)
 | 
					      expect(loggerInfoStub.callCount).to.equal(8)
 | 
				
			||||||
      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('UPGRADE BEGIN: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('[2.14.0 migration] UPGRADE BEGIN: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.13.5 migration] Found 1 duplicate series'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.14.0 migration] Found 1 duplicate series'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.13.5 migration] Deduplicating series "Series 1" in library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.14.0 migration] Deduplicating series "Series 1" in library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('[2.13.5 migration] Deduplicating bookId 4a38b6e5-0ae4-4de4-b119-4e33891bd63f in series "Series 1" of library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('[2.14.0 migration] Deduplicating bookId 4a38b6e5-0ae4-4de4-b119-4e33891bd63f in series "Series 1" of library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('[2.13.5 migration] Finished cleanup of bookId 4a38b6e5-0ae4-4de4-b119-4e33891bd63f in series "Series 1" of library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('[2.14.0 migration] Finished cleanup of bookId 4a38b6e5-0ae4-4de4-b119-4e33891bd63f in series "Series 1" of library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(5).calledWith(sinon.match('[2.13.5 migration] Deduplication complete'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(5).calledWith(sinon.match('[2.14.0 migration] Deduplication complete'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(6).calledWith(sinon.match('Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(6).calledWith(sinon.match('[2.14.0 migration] Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(7).calledWith(sinon.match('UPGRADE END: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(7).calledWith(sinon.match('[2.14.0 migration] UPGRADE END: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      // validate rows
 | 
					      // validate rows
 | 
				
			||||||
      const series = await queryInterface.sequelize.query('SELECT "id", "name", "libraryId" FROM Series', { type: queryInterface.sequelize.QueryTypes.SELECT })
 | 
					      const series = await queryInterface.sequelize.query('SELECT "id", "name", "libraryId" FROM Series', { type: queryInterface.sequelize.QueryTypes.SELECT })
 | 
				
			||||||
      expect(series).to.have.length(1)
 | 
					      expect(series).to.have.length(1)
 | 
				
			||||||
@ -244,14 +244,14 @@ describe('migration-v2.13.5-series-column-unique', () => {
 | 
				
			|||||||
      await up({ context: { queryInterface, logger: Logger } })
 | 
					      await up({ context: { queryInterface, logger: Logger } })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      expect(loggerInfoStub.callCount).to.equal(8)
 | 
					      expect(loggerInfoStub.callCount).to.equal(8)
 | 
				
			||||||
      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('UPGRADE BEGIN: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('[2.14.0 migration] UPGRADE BEGIN: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.13.5 migration] Found 1 duplicate series'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.14.0 migration] Found 1 duplicate series'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.13.5 migration] Deduplicating series "Series 1" in library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.14.0 migration] Deduplicating series "Series 1" in library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('[2.13.5 migration] Deduplicating bookId 4a38b6e5-0ae4-4de4-b119-4e33891bd63f in series "Series 1" of library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('[2.14.0 migration] Deduplicating bookId 4a38b6e5-0ae4-4de4-b119-4e33891bd63f in series "Series 1" of library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('[2.13.5 migration] Finished cleanup of bookId 4a38b6e5-0ae4-4de4-b119-4e33891bd63f in series "Series 1" of library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('[2.14.0 migration] Finished cleanup of bookId 4a38b6e5-0ae4-4de4-b119-4e33891bd63f in series "Series 1" of library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(5).calledWith(sinon.match('[2.13.5 migration] Deduplication complete'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(5).calledWith(sinon.match('[2.14.0 migration] Deduplication complete'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(6).calledWith(sinon.match('Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(6).calledWith(sinon.match('[2.14.0 migration] Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(7).calledWith(sinon.match('UPGRADE END: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(7).calledWith(sinon.match('[2.14.0 migration] UPGRADE END: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      // validate rows
 | 
					      // validate rows
 | 
				
			||||||
      const series = await queryInterface.sequelize.query('SELECT "id", "name", "libraryId" FROM Series', { type: queryInterface.sequelize.QueryTypes.SELECT })
 | 
					      const series = await queryInterface.sequelize.query('SELECT "id", "name", "libraryId" FROM Series', { type: queryInterface.sequelize.QueryTypes.SELECT })
 | 
				
			||||||
      expect(series).to.have.length(1)
 | 
					      expect(series).to.have.length(1)
 | 
				
			||||||
@ -275,14 +275,14 @@ describe('migration-v2.13.5-series-column-unique', () => {
 | 
				
			|||||||
      await up({ context: { queryInterface, logger: Logger } })
 | 
					      await up({ context: { queryInterface, logger: Logger } })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      expect(loggerInfoStub.callCount).to.equal(8)
 | 
					      expect(loggerInfoStub.callCount).to.equal(8)
 | 
				
			||||||
      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('UPGRADE BEGIN: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('[2.14.0 migration] UPGRADE BEGIN: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.13.5 migration] Found 1 duplicate series'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.14.0 migration] Found 1 duplicate series'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.13.5 migration] Deduplicating series "Series 1" in library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.14.0 migration] Deduplicating series "Series 1" in library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('[2.13.5 migration] Deduplicating bookId 4a38b6e5-0ae4-4de4-b119-4e33891bd63f in series "Series 1" of library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('[2.14.0 migration] Deduplicating bookId 4a38b6e5-0ae4-4de4-b119-4e33891bd63f in series "Series 1" of library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('[2.13.5 migration] Finished cleanup of bookId 4a38b6e5-0ae4-4de4-b119-4e33891bd63f in series "Series 1" of library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('[2.14.0 migration] Finished cleanup of bookId 4a38b6e5-0ae4-4de4-b119-4e33891bd63f in series "Series 1" of library 3a5a1c7c-a914-472e-88b0-b871ceae63e7'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(5).calledWith(sinon.match('[2.13.5 migration] Deduplication complete'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(5).calledWith(sinon.match('[2.14.0 migration] Deduplication complete'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(6).calledWith(sinon.match('Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(6).calledWith(sinon.match('[2.14.0 migration] Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(7).calledWith(sinon.match('UPGRADE END: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(7).calledWith(sinon.match('[2.14.0 migration] UPGRADE END: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      // validate rows
 | 
					      // validate rows
 | 
				
			||||||
      const series = await queryInterface.sequelize.query('SELECT "id", "name", "libraryId" FROM Series', { type: queryInterface.sequelize.QueryTypes.SELECT })
 | 
					      const series = await queryInterface.sequelize.query('SELECT "id", "name", "libraryId" FROM Series', { type: queryInterface.sequelize.QueryTypes.SELECT })
 | 
				
			||||||
      expect(series).to.have.length(1)
 | 
					      expect(series).to.have.length(1)
 | 
				
			||||||
@ -319,14 +319,14 @@ describe('migration-v2.13.5-series-column-unique', () => {
 | 
				
			|||||||
      await down({ context: { queryInterface, logger: Logger } })
 | 
					      await down({ context: { queryInterface, logger: Logger } })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      expect(loggerInfoStub.callCount).to.equal(8)
 | 
					      expect(loggerInfoStub.callCount).to.equal(8)
 | 
				
			||||||
      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('UPGRADE BEGIN: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(0).calledWith(sinon.match('[2.14.0 migration] UPGRADE BEGIN: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.13.5 migration] Found 0 duplicate series'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(1).calledWith(sinon.match('[2.14.0 migration] Found 0 duplicate series'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.13.5 migration] Deduplication complete'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(2).calledWith(sinon.match('[2.14.0 migration] Deduplication complete'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(3).calledWith(sinon.match('[2.14.0 migration] Added unique index on Series.name and Series.libraryId'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('UPGRADE END: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(4).calledWith(sinon.match('[2.14.0 migration] UPGRADE END: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(5).calledWith(sinon.match('DOWNGRADE BEGIN: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(5).calledWith(sinon.match('[2.14.0 migration] DOWNGRADE BEGIN: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(6).calledWith(sinon.match('Removed unique index on Series.name and Series.libraryId'))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(6).calledWith(sinon.match('[2.14.0 migration] Removed unique index on Series.name and Series.libraryId'))).to.be.true
 | 
				
			||||||
      expect(loggerInfoStub.getCall(7).calledWith(sinon.match('DOWNGRADE END: 2.13.5-series-column-unique '))).to.be.true
 | 
					      expect(loggerInfoStub.getCall(7).calledWith(sinon.match('[2.14.0 migration] DOWNGRADE END: 2.14.0-series-column-unique '))).to.be.true
 | 
				
			||||||
      // Ensure index does not exist
 | 
					      // Ensure index does not exist
 | 
				
			||||||
      const indexes = await queryInterface.showIndex('Series')
 | 
					      const indexes = await queryInterface.showIndex('Series')
 | 
				
			||||||
      expect(indexes).to.not.deep.include({ tableName: 'Series', unique: true, fields: ['name', 'libraryId'], name: 'unique_series_name_per_library' })
 | 
					      expect(indexes).to.not.deep.include({ tableName: 'Series', unique: true, fields: ['name', 'libraryId'], name: 'unique_series_name_per_library' })
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user