From d91b05880862a2951d6eba16fb94ea3eecf696ef Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Fri, 28 Aug 2020 16:56:46 +0200 Subject: [PATCH 1/4] fix: Unnecessary migrations for fulltext indices Fixes #6633 (see issue for root cause explanation) --- src/schema-builder/RdbmsSchemaBuilder.ts | 3 ++- test/github-issues/6633/entity/Test.ts | 11 +++++++++ test/github-issues/6633/issue-6633.ts | 29 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/github-issues/6633/entity/Test.ts create mode 100644 test/github-issues/6633/issue-6633.ts diff --git a/src/schema-builder/RdbmsSchemaBuilder.ts b/src/schema-builder/RdbmsSchemaBuilder.ts index 2c625c9a6e..ab25175bf8 100644 --- a/src/schema-builder/RdbmsSchemaBuilder.ts +++ b/src/schema-builder/RdbmsSchemaBuilder.ts @@ -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) diff --git a/test/github-issues/6633/entity/Test.ts b/test/github-issues/6633/entity/Test.ts new file mode 100644 index 0000000000..61443c6dcd --- /dev/null +++ b/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; +} diff --git a/test/github-issues/6633/issue-6633.ts b/test/github-issues/6633/issue-6633.ts new file mode 100644 index 0000000000..fe5d99e114 --- /dev/null +++ b/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([]); + } + )) + ); +}); From 476209e169edf8918a603a0035cf3ee54bd81526 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Fri, 28 Aug 2020 21:47:41 +0200 Subject: [PATCH 2/4] test: Enable all tests --- test/github-issues/6633/issue-6633.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/github-issues/6633/issue-6633.ts b/test/github-issues/6633/issue-6633.ts index fe5d99e114..31df86b5b8 100644 --- a/test/github-issues/6633/issue-6633.ts +++ b/test/github-issues/6633/issue-6633.ts @@ -4,7 +4,7 @@ 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", () => { +describe("github issues > #6633 Fulltext indices continually dropped & re-created", () => { let connections: Connection[]; before(async () => { From 7040748ebb4afef23d06691fc1d673d197fd7a04 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Fri, 4 Sep 2020 10:37:45 +0200 Subject: [PATCH 3/4] refactor: Add `isFullTextColumnTypeSupported()` method to Driver interface --- src/driver/Driver.ts | 5 +++++ src/driver/aurora-data-api/AuroraDataApiDriver.ts | 7 +++++++ src/driver/cockroachdb/CockroachDriver.ts | 7 +++++++ src/driver/mongodb/MongoDriver.ts | 7 +++++++ src/driver/mysql/MysqlDriver.ts | 7 +++++++ src/driver/oracle/OracleDriver.ts | 7 +++++++ src/driver/postgres/PostgresDriver.ts | 7 +++++++ src/driver/sap/SapDriver.ts | 7 +++++++ src/driver/sqlite-abstract/AbstractSqliteDriver.ts | 7 +++++++ src/schema-builder/RdbmsSchemaBuilder.ts | 3 +-- src/schema-builder/options/TableIndexOptions.ts | 6 +++--- 11 files changed, 65 insertions(+), 5 deletions(-) diff --git a/src/driver/Driver.ts b/src/driver/Driver.ts index 4041f58693..3027e4afaf 100644 --- a/src/driver/Driver.ts +++ b/src/driver/Driver.ts @@ -193,6 +193,11 @@ export interface Driver { */ isUUIDGenerationSupported(): boolean; + /** + * Returns true if driver supports fulltext indices. + */ + isFullTextColumnTypeSupported(): boolean; + /** * Creates an escaped parameter. */ diff --git a/src/driver/aurora-data-api/AuroraDataApiDriver.ts b/src/driver/aurora-data-api/AuroraDataApiDriver.ts index 901ff22435..e85e545aa2 100644 --- a/src/driver/aurora-data-api/AuroraDataApiDriver.ts +++ b/src/driver/aurora-data-api/AuroraDataApiDriver.ts @@ -750,6 +750,13 @@ export class AuroraDataApiDriver implements Driver { return false; } + /** + * Returns true if driver supports fulltext indices. + */ + isFullTextColumnTypeSupported(): boolean { + return true; + } + /** * Creates an escaped parameter. */ diff --git a/src/driver/cockroachdb/CockroachDriver.ts b/src/driver/cockroachdb/CockroachDriver.ts index 3347250361..8cacf57118 100644 --- a/src/driver/cockroachdb/CockroachDriver.ts +++ b/src/driver/cockroachdb/CockroachDriver.ts @@ -649,6 +649,13 @@ export class CockroachDriver implements Driver { return true; } + /** + * Returns true if driver supports fulltext indices. + */ + isFullTextColumnTypeSupported(): boolean { + return false; + } + /** * Creates an escaped parameter. */ diff --git a/src/driver/mongodb/MongoDriver.ts b/src/driver/mongodb/MongoDriver.ts index 7106532467..f1d1b190e2 100644 --- a/src/driver/mongodb/MongoDriver.ts +++ b/src/driver/mongodb/MongoDriver.ts @@ -389,6 +389,13 @@ export class MongoDriver implements Driver { return false; } + /** + * Returns true if driver supports fulltext indices. + */ + isFullTextColumnTypeSupported(): boolean { + return false; + } + /** * Creates an escaped parameter. */ diff --git a/src/driver/mysql/MysqlDriver.ts b/src/driver/mysql/MysqlDriver.ts index 291beaa68f..d55a960ef4 100644 --- a/src/driver/mysql/MysqlDriver.ts +++ b/src/driver/mysql/MysqlDriver.ts @@ -798,6 +798,13 @@ export class MysqlDriver implements Driver { return false; } + /** + * Returns true if driver supports fulltext indices. + */ + isFullTextColumnTypeSupported(): boolean { + return true; + } + /** * Creates an escaped parameter. */ diff --git a/src/driver/oracle/OracleDriver.ts b/src/driver/oracle/OracleDriver.ts index 134ed6bba7..42575f6108 100644 --- a/src/driver/oracle/OracleDriver.ts +++ b/src/driver/oracle/OracleDriver.ts @@ -623,6 +623,13 @@ export class OracleDriver implements Driver { return false; } + /** + * Returns true if driver supports fulltext indices. + */ + isFullTextColumnTypeSupported(): boolean { + return false; + } + /** * Creates an escaped parameter. */ diff --git a/src/driver/postgres/PostgresDriver.ts b/src/driver/postgres/PostgresDriver.ts index e9eae242c6..59684c74bf 100644 --- a/src/driver/postgres/PostgresDriver.ts +++ b/src/driver/postgres/PostgresDriver.ts @@ -912,6 +912,13 @@ export class PostgresDriver implements Driver { return true; } + /** + * Returns true if driver supports fulltext indices. + */ + isFullTextColumnTypeSupported(): boolean { + return false; + } + get uuidGenerator(): string { return this.options.uuidExtension === "pgcrypto" ? "gen_random_uuid()" : "uuid_generate_v4()"; } diff --git a/src/driver/sap/SapDriver.ts b/src/driver/sap/SapDriver.ts index 9479277503..85b6a7f2f2 100644 --- a/src/driver/sap/SapDriver.ts +++ b/src/driver/sap/SapDriver.ts @@ -624,6 +624,13 @@ export class SapDriver implements Driver { return false; } + /** + * Returns true if driver supports fulltext indices. + */ + isFullTextColumnTypeSupported(): boolean { + return true; + } + /** * Creates an escaped parameter. */ diff --git a/src/driver/sqlite-abstract/AbstractSqliteDriver.ts b/src/driver/sqlite-abstract/AbstractSqliteDriver.ts index 09cb044e17..b5834c075c 100644 --- a/src/driver/sqlite-abstract/AbstractSqliteDriver.ts +++ b/src/driver/sqlite-abstract/AbstractSqliteDriver.ts @@ -575,6 +575,13 @@ export abstract class AbstractSqliteDriver implements Driver { return false; } + /** + * Returns true if driver supports fulltext indices. + */ + isFullTextColumnTypeSupported(): boolean { + return false; + } + /** * Creates an escaped parameter. */ diff --git a/src/schema-builder/RdbmsSchemaBuilder.ts b/src/schema-builder/RdbmsSchemaBuilder.ts index ab25175bf8..d5bd9f2aa0 100644 --- a/src/schema-builder/RdbmsSchemaBuilder.ts +++ b/src/schema-builder/RdbmsSchemaBuilder.ts @@ -277,8 +277,7 @@ export class RdbmsSchemaBuilder implements SchemaBuilder { if (indexMetadata.isSpatial !== tableIndex.isSpatial) return true; - // Only MySQL supports fulltext indices - if (this.connection.driver instanceof MysqlDriver && indexMetadata.isFulltext !== tableIndex.isFulltext) + if (this.connection.driver.isFullTextColumnTypeSupported() && indexMetadata.isFulltext !== tableIndex.isFulltext) return true; if (indexMetadata.columns.length !== tableIndex.columnNames.length) diff --git a/src/schema-builder/options/TableIndexOptions.ts b/src/schema-builder/options/TableIndexOptions.ts index c75228e2fd..b37be3d790 100644 --- a/src/schema-builder/options/TableIndexOptions.ts +++ b/src/schema-builder/options/TableIndexOptions.ts @@ -30,10 +30,10 @@ export interface TableIndexOptions { /** * The FULLTEXT modifier indexes the entire column and does not allow prefixing. - * Works only in MySQL. + * Supported only in MySQL & SAP HANA. */ isFulltext?: boolean; - + /** * Fulltext parser. * Works only in MySQL. @@ -45,4 +45,4 @@ export interface TableIndexOptions { */ where?: string; -} \ No newline at end of file +} From 69bdd06d349efc8c6c70029804f2d47d51b5f024 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Fri, 4 Sep 2020 11:08:52 +0200 Subject: [PATCH 4/4] fix: Include isFullTextColumnTypeSupported method in SqlServerDriver --- src/driver/sqlserver/SqlServerDriver.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/driver/sqlserver/SqlServerDriver.ts b/src/driver/sqlserver/SqlServerDriver.ts index 20e7f9e11d..5954431de0 100644 --- a/src/driver/sqlserver/SqlServerDriver.ts +++ b/src/driver/sqlserver/SqlServerDriver.ts @@ -640,6 +640,13 @@ export class SqlServerDriver implements Driver { return true; } + /** + * Returns true if driver supports fulltext indices. + */ + isFullTextColumnTypeSupported(): boolean { + return false; + } + /** * Creates an escaped parameter. */