Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Unnecessary migrations for fulltext indices #6634

Merged
merged 4 commits into from Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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.
*/
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([]);
}
))
);
});