Skip to content

Commit

Permalink
feat: remove uniqueness from sequelize storage (#602)
Browse files Browse the repository at this point in the history
…tries in case of rerun

---------

Co-authored-by: Guy Ephraim <guy.ephraim@safebreach.com>
Co-authored-by: Misha Kaletsky <15040698+mmkal@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 28, 2023
1 parent 5866758 commit 15fc2fe
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 48 deletions.
2 changes: 0 additions & 2 deletions src/storage/sequelize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ export class SequelizeStorage implements UmzugStorage {
[this.columnName]: {
type: this.columnType,
allowNull: false,
unique: true,
primaryKey: true,
autoIncrement: false,
},
},
Expand Down
126 changes: 80 additions & 46 deletions test/storage/sequelize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,27 @@ describe('sequelize', () => {
.then(describeModel)
.then((description: any) => {
expect(description).toMatchInlineSnapshot(`

Check failure on line 68 in test/storage/sequelize.test.ts

View workflow job for this annotation

GitHub Actions / build

Templates should be properly indented
{
"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();
});
});

Expand Down Expand Up @@ -111,16 +118,23 @@ describe('sequelize', () => {
.then(describeModel)
.then((description: any) => {
expect(description).toMatchInlineSnapshot(`

Check failure on line 120 in test/storage/sequelize.test.ts

View workflow job for this annotation

GitHub Actions / build

Templates should be properly indented
{
"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,
},
}
`);
});
});

Expand All @@ -134,30 +148,37 @@ describe('sequelize', () => {
.then(describeModel)
.then((description: any) => {
expect(description).toMatchInlineSnapshot(`

Check failure on line 150 in test/storage/sequelize.test.ts

View workflow job for this annotation

GitHub Actions / build

Templates should be properly indented
{
"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,
},
}
`);
});
});

Expand All @@ -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);
});
});

Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 15fc2fe

Please sign in to comment.