From f8b5d1413915234890b70e1395f6792caee8bc96 Mon Sep 17 00:00:00 2001 From: Guy Ephraim Date: Mon, 17 Apr 2023 17:44:40 +0300 Subject: [PATCH 1/2] remove uniqueness from the sequelize storage as it can be multiple entries in case of rerun --- src/storage/sequelize.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/storage/sequelize.ts b/src/storage/sequelize.ts index 93e75ce1..1badeeed 100644 --- a/src/storage/sequelize.ts +++ b/src/storage/sequelize.ts @@ -133,8 +133,6 @@ export class SequelizeStorage implements UmzugStorage { [this.columnName]: { type: this.columnType, allowNull: false, - unique: true, - primaryKey: true, autoIncrement: false, }, }, From 177691b00d832cb9716e686a8f17cd1989f650ca Mon Sep 17 00:00:00 2001 From: Guy Ephraim Date: Tue, 18 Apr 2023 12:25:50 +0300 Subject: [PATCH 2/2] sequelize requires a primary key so it add a default id --- test/storage/sequelize.test.ts | 126 +++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 46 deletions(-) diff --git a/test/storage/sequelize.test.ts b/test/storage/sequelize.test.ts index 76aa7df8..78cc8208 100644 --- a/test/storage/sequelize.test.ts +++ b/test/storage/sequelize.test.ts @@ -66,20 +66,27 @@ describe('sequelize', () => { .then(describeModel) .then((description: any) => { expect(description).toMatchInlineSnapshot(` - { - "name": { - "allowNull": false, - "defaultValue": undefined, - "primaryKey": true, - "type": "VARCHAR(255)", - "unique": true, - }, - } - `); + { + "id": { + "allowNull": true, + "defaultValue": undefined, + "primaryKey": true, + "type": "INTEGER", + "unique": false, + }, + "name": { + "allowNull": false, + "defaultValue": undefined, + "primaryKey": false, + "type": "VARCHAR(255)", + "unique": false, + }, + } + `); expect(description.name.type).toBe('VARCHAR(255)'); expect(description.name.defaultValue).toBeUndefined(); - expect(description.name.primaryKey).toBeTruthy(); + expect(description.name.primaryKey).toBeFalsy(); }); }); @@ -111,16 +118,23 @@ describe('sequelize', () => { .then(describeModel) .then((description: any) => { expect(description).toMatchInlineSnapshot(` - { - "customColumn": { - "allowNull": false, - "defaultValue": undefined, - "primaryKey": true, - "type": "VARCHAR(255)", - "unique": true, - }, - } - `); + { + "customColumn": { + "allowNull": false, + "defaultValue": undefined, + "primaryKey": false, + "type": "VARCHAR(255)", + "unique": false, + }, + "id": { + "allowNull": true, + "defaultValue": undefined, + "primaryKey": true, + "type": "INTEGER", + "unique": false, + }, + } + `); }); }); @@ -134,30 +148,37 @@ describe('sequelize', () => { .then(describeModel) .then((description: any) => { expect(description).toMatchInlineSnapshot(` - { - "createdAt": { - "allowNull": false, - "defaultValue": undefined, - "primaryKey": false, - "type": "DATETIME", - "unique": false, - }, - "name": { - "allowNull": false, - "defaultValue": undefined, - "primaryKey": true, - "type": "VARCHAR(255)", - "unique": true, - }, - "updatedAt": { - "allowNull": false, - "defaultValue": undefined, - "primaryKey": false, - "type": "DATETIME", - "unique": false, - }, - } - `); + { + "createdAt": { + "allowNull": false, + "defaultValue": undefined, + "primaryKey": false, + "type": "DATETIME", + "unique": false, + }, + "id": { + "allowNull": true, + "defaultValue": undefined, + "primaryKey": true, + "type": "INTEGER", + "unique": false, + }, + "name": { + "allowNull": false, + "defaultValue": undefined, + "primaryKey": false, + "type": "VARCHAR(255)", + "unique": false, + }, + "updatedAt": { + "allowNull": false, + "defaultValue": undefined, + "primaryKey": false, + "type": "DATETIME", + "unique": false, + }, + } + `); }); }); @@ -173,7 +194,7 @@ describe('sequelize', () => { expect(description.name.type).toBe('VARCHAR(190)'); expect(description.name.defaultValue).toBeUndefined(); - expect(description.name.primaryKey).toBe(true); + expect(description.name.primaryKey).toBe(false); }); }); @@ -266,6 +287,19 @@ describe('sequelize', () => { expect(migrations[0].createdAt.getTime()).toBeLessThanOrEqual(Date.now()); }); }); + + it('logMigration and re-logMigration', async () => { + const storage = new Storage({ + sequelize: helper.sequelize, + }); + + await storage.logMigration({ name: 'm1' }); + expect(await storage.executed()).toEqual(['m1']); + + await storage.logMigration({ name: 'm1' }); + await storage.logMigration({ name: 'm2' }); + expect(await storage.executed()).toEqual(['m1', 'm1', 'm2']); + }); }); describe('unlogMigration', () => {