From 32850d13ecaa6a2a54581b3b088ca4a2d22112e8 Mon Sep 17 00:00:00 2001 From: Greg Lorenzen Date: Sun, 1 Dec 2024 01:49:50 +0000 Subject: [PATCH] Add migration to include isDownloadable column in mediaItemShares table --- .../v2.17.3-share-add-isdownloadable.js | 32 ++++++++++++++ .../v2.17.3-share-add-isdownloadable.test.js | 42 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 server/migrations/v2.17.3-share-add-isdownloadable.js create mode 100644 test/server/migrations/v2.17.3-share-add-isdownloadable.test.js diff --git a/server/migrations/v2.17.3-share-add-isdownloadable.js b/server/migrations/v2.17.3-share-add-isdownloadable.js new file mode 100644 index 000000000..31d274340 --- /dev/null +++ b/server/migrations/v2.17.3-share-add-isdownloadable.js @@ -0,0 +1,32 @@ +'use strict' + +const { DataTypes } = require('sequelize') + +/** + * @typedef MigrationContext + * @property {import('sequelize').QueryInterface} queryInterface - a Sequelize QueryInterface object. + * @property {import('../Logger')} logger - a Logger object. + * + * @typedef MigrationOptions + * @property {MigrationContext} context - an object containing the migration context. + */ + +/** + * This migration script adds the isDownloadable column to the mediaItemShares table. + * + * @param {MigrationOptions} options - an object containing the migration context. + * @returns {Promise} - A promise that resolves when the migration is complete. + */ +module.exports = { + up: async ({ context: { queryInterface, logger } }) => { + await queryInterface.addColumn('mediaItemShares', 'isDownloadable', { + type: DataTypes.BOOLEAN, + defaultValue: false, + allowNull: false + }) + }, + + down: async ({ context: { queryInterface, logger } }) => { + await queryInterface.removeColumn('mediaItemShares', 'isDownloadable') + } +} diff --git a/test/server/migrations/v2.17.3-share-add-isdownloadable.test.js b/test/server/migrations/v2.17.3-share-add-isdownloadable.test.js new file mode 100644 index 000000000..1d2a82a0a --- /dev/null +++ b/test/server/migrations/v2.17.3-share-add-isdownloadable.test.js @@ -0,0 +1,42 @@ +const chai = require('chai') +const sinon = require('sinon') +const { expect } = chai + +const { DataTypes } = require('sequelize') + +const { up, down } = require('../../../server/migrations/v2.17.3-share-add-isdownloadable') + +describe('Migration v2.17.3-share-add-isDownloadable', () => { + let queryInterface + + beforeEach(() => { + queryInterface = { + addColumn: sinon.stub().resolves(), + removeColumn: sinon.stub().resolves() + } + }) + + describe('up', () => { + it('should add the isDownloadable column to mediaItemShares table', async () => { + await up({ context: { queryInterface } }) + + expect(queryInterface.addColumn.calledOnce).to.be.true + expect( + queryInterface.addColumn.calledWith('mediaItemShares', 'isDownloadable', { + type: DataTypes.BOOLEAN, + defaultValue: false, + allowNull: false + }) + ).to.be.true + }) + }) + + describe('down', () => { + it('should remove the isDownloadable column from mediaItemShares table', async () => { + await down({ context: { queryInterface } }) + + expect(queryInterface.removeColumn.calledOnce).to.be.true + expect(queryInterface.removeColumn.calledWith('mediaItemShares', 'isDownloadable')).to.be.true + }) + }) +})