mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
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>
This commit is contained in:
parent
b8704f87d2
commit
c77c43e242
@ -786,6 +786,12 @@ export abstract class AbstractSqliteDriver implements Driver {
|
||||
tableColumn.asExpression !== columnMetadata.asExpression ||
|
||||
tableColumn.isUnique !==
|
||||
this.normalizeIsUnique(columnMetadata) ||
|
||||
(tableColumn.enum &&
|
||||
columnMetadata.enum &&
|
||||
!OrmUtils.isArraysEqual(
|
||||
tableColumn.enum,
|
||||
columnMetadata.enum.map((val) => val + ""),
|
||||
)) ||
|
||||
(columnMetadata.generationStrategy !== "uuid" &&
|
||||
tableColumn.isGenerated !== columnMetadata.isGenerated)
|
||||
|
||||
@ -844,6 +850,15 @@ export abstract class AbstractSqliteDriver implements Driver {
|
||||
// this.normalizeIsUnique(columnMetadata),
|
||||
// )
|
||||
// console.log(
|
||||
// "enum:",
|
||||
// tableColumn.enum &&
|
||||
// columnMetadata.enum &&
|
||||
// !OrmUtils.isArraysEqual(
|
||||
// tableColumn.enum,
|
||||
// columnMetadata.enum.map((val) => val + ""),
|
||||
// ),
|
||||
// )
|
||||
// console.log(
|
||||
// "isGenerated:",
|
||||
// tableColumn.isGenerated,
|
||||
// columnMetadata.isGenerated,
|
||||
|
||||
22
test/github-issues/9715/entity/ExampleEntity.ts
Normal file
22
test/github-issues/9715/entity/ExampleEntity.ts
Normal file
@ -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
|
||||
}
|
||||
42
test/github-issues/9715/issue-9715.ts
Normal file
42
test/github-issues/9715/issue-9715.ts
Normal file
@ -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
|
||||
})
|
||||
15
test/github-issues/9715/migration/1674040078325-init.ts
Normal file
15
test/github-issues/9715/migration/1674040078325-init.ts
Normal file
@ -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"`)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user