-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve issue with "simple-enum" synchronization in SQLite (#9716)
* fix: resolve issue with "simple-enum" in sqlite Closes: #9715 * trying to re-trigger CircleCI tests --------- Co-authored-by: Dmitry Zotov <dmzt08@gmail.com>
- Loading branch information
1 parent
b8704f8
commit c77c43e
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Entity } from "../../../../src/decorator/entity/Entity" | ||
import { Column } from "../../../../src/decorator/columns/Column" | ||
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn" | ||
|
||
export enum ExampleEnum { | ||
EnumValue1 = "enumvalue1", | ||
EnumValue2 = "enumvalue2", | ||
EnumValue3 = "enumvalue3", | ||
EnumValue4 = "enumvalue4", | ||
} | ||
|
||
@Entity() | ||
export class ExampleEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Column({ | ||
type: "simple-enum", | ||
enum: ExampleEnum, | ||
}) | ||
enumcolumn: ExampleEnum | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import "reflect-metadata" | ||
import { | ||
createTestingConnections, | ||
closeTestingConnections, | ||
} from "../../utils/test-utils" | ||
import { DataSource } from "../../../src/data-source/DataSource" | ||
|
||
describe("github issues > #9715 Database schema is not updated by sync/migration when 'simple-enum' is changed.", () => { | ||
let dataSources: DataSource[] | ||
before( | ||
async () => | ||
(dataSources = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
migrations: [__dirname + "/migration/*{.js,.ts}"], | ||
schemaCreate: false, | ||
dropSchema: true, | ||
enabledDrivers: ["sqlite"], | ||
})), | ||
) | ||
after(() => closeTestingConnections(dataSources)) | ||
|
||
it("should update 'CHECK' constraint to match enum values", () => | ||
Promise.all( | ||
dataSources.map(async (dataSource) => { | ||
await dataSource.runMigrations() | ||
|
||
const sqlInMemory = await dataSource.driver | ||
.createSchemaBuilder() | ||
.log() | ||
|
||
sqlInMemory.upQueries | ||
.filter((i) => | ||
i.query.includes( | ||
`CHECK( "enumcolumn" IN ('enumvalue1','enumvalue2','enumvalue3','enumvalue4') )`, | ||
), | ||
) | ||
.length.should.be.greaterThan(0) | ||
}), | ||
)) | ||
|
||
// you can add additional tests if needed | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { MigrationInterface, QueryRunner } from "../../../../src" | ||
|
||
export class init1674040078325 implements MigrationInterface { | ||
name = "init1674040078325" | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE "example_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "enumcolumn" varchar CHECK( "enumcolumn" IN ('enumvalue1','enumvalue2','enumvalue3') ) NOT NULL)`, | ||
) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP TABLE "example_entity"`) | ||
} | ||
} |