Skip to content

Commit

Permalink
fix: Unnecessary migrations for fulltext indices (#6634)
Browse files Browse the repository at this point in the history
* fix: Unnecessary migrations for fulltext indices

Fixes #6633 (see issue for root cause explanation)

* test: Enable all tests

* refactor: Add `isFullTextColumnTypeSupported()` method to Driver interface

* fix: Include isFullTextColumnTypeSupported method in SqlServerDriver
  • Loading branch information
michaelbromley committed Sep 4, 2020
1 parent df70dc3 commit c81b405
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/driver/Driver.ts
Expand Up @@ -193,6 +193,11 @@ export interface Driver {
*/
isUUIDGenerationSupported(): boolean;

/**
* Returns true if driver supports fulltext indices.
*/
isFullTextColumnTypeSupported(): boolean;

/**
* Creates an escaped parameter.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/driver/aurora-data-api/AuroraDataApiDriver.ts
Expand Up @@ -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.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/driver/cockroachdb/CockroachDriver.ts
Expand Up @@ -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.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/driver/mongodb/MongoDriver.ts
Expand Up @@ -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.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/driver/mysql/MysqlDriver.ts
Expand Up @@ -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.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/driver/oracle/OracleDriver.ts
Expand Up @@ -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.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/driver/postgres/PostgresDriver.ts
Expand Up @@ -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()";
}
Expand Down
7 changes: 7 additions & 0 deletions src/driver/sap/SapDriver.ts
Expand Up @@ -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.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/driver/sqlite-abstract/AbstractSqliteDriver.ts
Expand Up @@ -594,6 +594,13 @@ export abstract class AbstractSqliteDriver implements Driver {
return false;
}

/**
* Returns true if driver supports fulltext indices.
*/
isFullTextColumnTypeSupported(): boolean {
return false;
}

/**
* Creates an escaped parameter.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/driver/sqlserver/SqlServerDriver.ts
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/schema-builder/RdbmsSchemaBuilder.ts
Expand Up @@ -277,7 +277,7 @@ export class RdbmsSchemaBuilder implements SchemaBuilder {
if (indexMetadata.isSpatial !== tableIndex.isSpatial)
return true;

if (indexMetadata.isFulltext !== tableIndex.isFulltext)
if (this.connection.driver.isFullTextColumnTypeSupported() && indexMetadata.isFulltext !== tableIndex.isFulltext)
return true;

if (indexMetadata.columns.length !== tableIndex.columnNames.length)
Expand Down
6 changes: 3 additions & 3 deletions src/schema-builder/options/TableIndexOptions.ts
Expand Up @@ -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.
Expand All @@ -45,4 +45,4 @@ export interface TableIndexOptions {
*/
where?: string;

}
}
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("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 c81b405

Please sign in to comment.