Skip to content

Commit

Permalink
fix: Unnecessary migrations for fulltext indices
Browse files Browse the repository at this point in the history
Fixes typeorm#6633 (see issue for root cause explanation)
  • Loading branch information
michaelbromley committed Aug 28, 2020
1 parent d1ed572 commit d91b058
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/schema-builder/RdbmsSchemaBuilder.ts
Expand Up @@ -277,7 +277,8 @@ export class RdbmsSchemaBuilder implements SchemaBuilder {
if (indexMetadata.isSpatial !== tableIndex.isSpatial)
return true;

if (indexMetadata.isFulltext !== tableIndex.isFulltext)
// Only MySQL supports fulltext indices
if (this.connection.driver instanceof MysqlDriver && indexMetadata.isFulltext !== tableIndex.isFulltext)
return true;

if (indexMetadata.columns.length !== tableIndex.columnNames.length)
Expand Down
11 changes: 11 additions & 0 deletions test/github-issues/6633/entity/Test.ts
@@ -0,0 +1,11 @@
import { Entity, PrimaryColumn, Index, Column } from "../../../../src";

@Entity()
export class Test {
@PrimaryColumn()
id: number;

@Index("description_index", { fulltext: true })
@Column()
description: string;
}
29 changes: 29 additions & 0 deletions test/github-issues/6633/issue-6633.ts
@@ -0,0 +1,29 @@
import "reflect-metadata";
import { expect } from "chai";
import { Connection } from "../../../src";
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils";
import { Post } from "../4440/entity/Post";

describe.only("github issues > #6633 Fulltext indices continually dropped & re-created", () => {

let connections: Connection[];
before(async () => {
connections = await createTestingConnections({
entities: [Post],
schemaCreate: true,
dropSchema: true
});
});
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));

it("should not create migrations for fulltext indices", () =>
Promise.all(connections.map(async (connection) => {
const sqlInMemory = await connection.driver.createSchemaBuilder().log();

expect(sqlInMemory.upQueries).to.eql([]);
expect(sqlInMemory.downQueries).to.eql([]);
}
))
);
});

0 comments on commit d91b058

Please sign in to comment.