@strapi/database 5.56.0 → 5.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dialects/dialect.d.ts +28 -0
- package/dist/dialects/dialect.d.ts.map +1 -1
- package/dist/dialects/dialect.js +29 -0
- package/dist/dialects/dialect.js.map +1 -1
- package/dist/dialects/dialect.mjs +29 -0
- package/dist/dialects/dialect.mjs.map +1 -1
- package/dist/dialects/mysql/index.d.ts +9 -0
- package/dist/dialects/mysql/index.d.ts.map +1 -1
- package/dist/dialects/mysql/index.js +37 -0
- package/dist/dialects/mysql/index.js.map +1 -1
- package/dist/dialects/mysql/index.mjs +37 -0
- package/dist/dialects/mysql/index.mjs.map +1 -1
- package/dist/dialects/postgresql/index.d.ts +7 -0
- package/dist/dialects/postgresql/index.d.ts.map +1 -1
- package/dist/dialects/postgresql/index.js +50 -0
- package/dist/dialects/postgresql/index.js.map +1 -1
- package/dist/dialects/postgresql/index.mjs +50 -0
- package/dist/dialects/postgresql/index.mjs.map +1 -1
- package/dist/dialects/sqlite/index.d.ts +9 -0
- package/dist/dialects/sqlite/index.d.ts.map +1 -1
- package/dist/dialects/sqlite/index.js +16 -0
- package/dist/dialects/sqlite/index.js.map +1 -1
- package/dist/dialects/sqlite/index.mjs +16 -0
- package/dist/dialects/sqlite/index.mjs.map +1 -1
- package/dist/entity-manager/entity-repository.js +1 -1
- package/dist/entity-manager/entity-repository.js.map +1 -1
- package/dist/entity-manager/entity-repository.mjs +1 -1
- package/dist/entity-manager/entity-repository.mjs.map +1 -1
- package/dist/entity-manager/index.d.ts.map +1 -1
- package/dist/entity-manager/index.js +38 -36
- package/dist/entity-manager/index.js.map +1 -1
- package/dist/entity-manager/index.mjs +38 -36
- package/dist/entity-manager/index.mjs.map +1 -1
- package/dist/entity-manager/morph-relations.d.ts.map +1 -1
- package/dist/entity-manager/morph-relations.js +3 -5
- package/dist/entity-manager/morph-relations.js.map +1 -1
- package/dist/entity-manager/morph-relations.mjs +3 -5
- package/dist/entity-manager/morph-relations.mjs.map +1 -1
- package/dist/entity-manager/regular-relations.js +3 -3
- package/dist/entity-manager/regular-relations.js.map +1 -1
- package/dist/entity-manager/regular-relations.mjs +3 -3
- package/dist/entity-manager/regular-relations.mjs.map +1 -1
- package/dist/entity-manager/relations-orderer.d.ts.map +1 -1
- package/dist/entity-manager/relations-orderer.js +4 -5
- package/dist/entity-manager/relations-orderer.js.map +1 -1
- package/dist/entity-manager/relations-orderer.mjs +2 -3
- package/dist/entity-manager/relations-orderer.mjs.map +1 -1
- package/dist/fields/biginteger.js +1 -1
- package/dist/fields/biginteger.js.map +1 -1
- package/dist/fields/biginteger.mjs +1 -1
- package/dist/fields/biginteger.mjs.map +1 -1
- package/dist/fields/boolean.js +1 -1
- package/dist/fields/boolean.js.map +1 -1
- package/dist/fields/boolean.mjs +1 -1
- package/dist/fields/boolean.mjs.map +1 -1
- package/dist/fields/number.js +1 -1
- package/dist/fields/number.js.map +1 -1
- package/dist/fields/number.mjs +1 -1
- package/dist/fields/number.mjs.map +1 -1
- package/dist/fields/shared/parsers.js +2 -2
- package/dist/fields/shared/parsers.js.map +1 -1
- package/dist/fields/shared/parsers.mjs +2 -2
- package/dist/fields/shared/parsers.mjs.map +1 -1
- package/dist/fields/string.js +1 -1
- package/dist/fields/string.js.map +1 -1
- package/dist/fields/string.mjs +1 -1
- package/dist/fields/string.mjs.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/metadata/attribute-naming.d.ts +31 -0
- package/dist/metadata/attribute-naming.d.ts.map +1 -0
- package/dist/metadata/attribute-naming.js +39 -0
- package/dist/metadata/attribute-naming.js.map +1 -0
- package/dist/metadata/attribute-naming.mjs +37 -0
- package/dist/metadata/attribute-naming.mjs.map +1 -0
- package/dist/metadata/index.d.ts +5 -2
- package/dist/metadata/index.d.ts.map +1 -1
- package/dist/metadata/index.js +3 -0
- package/dist/metadata/index.js.map +1 -1
- package/dist/metadata/index.mjs +3 -1
- package/dist/metadata/index.mjs.map +1 -1
- package/dist/metadata/metadata.d.ts +10 -0
- package/dist/metadata/metadata.d.ts.map +1 -1
- package/dist/metadata/metadata.js +10 -2
- package/dist/metadata/metadata.js.map +1 -1
- package/dist/metadata/metadata.mjs +10 -2
- package/dist/metadata/metadata.mjs.map +1 -1
- package/dist/metadata/relations.d.ts.map +1 -1
- package/dist/metadata/relations.js +6 -5
- package/dist/metadata/relations.js.map +1 -1
- package/dist/metadata/relations.mjs +6 -5
- package/dist/metadata/relations.mjs.map +1 -1
- package/dist/migrations/common.d.ts +2 -0
- package/dist/migrations/common.d.ts.map +1 -1
- package/dist/migrations/common.js.map +1 -1
- package/dist/migrations/common.mjs.map +1 -1
- package/dist/migrations/file-builder.d.ts +97 -0
- package/dist/migrations/file-builder.d.ts.map +1 -0
- package/dist/migrations/file-builder.js +251 -0
- package/dist/migrations/file-builder.js.map +1 -0
- package/dist/migrations/file-builder.mjs +240 -0
- package/dist/migrations/file-builder.mjs.map +1 -0
- package/dist/migrations/index.d.ts +3 -2
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +6 -0
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +6 -0
- package/dist/migrations/index.mjs.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.js +1 -1
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.js.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.mjs +1 -1
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.mjs.map +1 -1
- package/dist/migrations/resolver.d.ts.map +1 -1
- package/dist/migrations/resolver.js +4 -1
- package/dist/migrations/resolver.js.map +1 -1
- package/dist/migrations/resolver.mjs +4 -1
- package/dist/migrations/resolver.mjs.map +1 -1
- package/dist/query/helpers/order-by.d.ts.map +1 -1
- package/dist/query/helpers/order-by.js +3 -4
- package/dist/query/helpers/order-by.js.map +1 -1
- package/dist/query/helpers/order-by.mjs +3 -4
- package/dist/query/helpers/order-by.mjs.map +1 -1
- package/dist/query/helpers/populate/apply.d.ts.map +1 -1
- package/dist/query/helpers/populate/apply.js +46 -30
- package/dist/query/helpers/populate/apply.js.map +1 -1
- package/dist/query/helpers/populate/apply.mjs +46 -30
- package/dist/query/helpers/populate/apply.mjs.map +1 -1
- package/dist/query/helpers/populate/process.js +3 -3
- package/dist/query/helpers/populate/process.js.map +1 -1
- package/dist/query/helpers/populate/process.mjs +3 -3
- package/dist/query/helpers/populate/process.mjs.map +1 -1
- package/dist/query/helpers/search.js +2 -2
- package/dist/query/helpers/search.js.map +1 -1
- package/dist/query/helpers/search.mjs +2 -2
- package/dist/query/helpers/search.mjs.map +1 -1
- package/dist/query/helpers/streams/readable.js +3 -3
- package/dist/query/helpers/streams/readable.js.map +1 -1
- package/dist/query/helpers/streams/readable.mjs +3 -3
- package/dist/query/helpers/streams/readable.mjs.map +1 -1
- package/dist/query/helpers/transform.d.ts.map +1 -1
- package/dist/query/helpers/transform.js +6 -13
- package/dist/query/helpers/transform.js.map +1 -1
- package/dist/query/helpers/transform.mjs +6 -9
- package/dist/query/helpers/transform.mjs.map +1 -1
- package/dist/query/helpers/where.js +13 -9
- package/dist/query/helpers/where.js.map +1 -1
- package/dist/query/helpers/where.mjs +13 -9
- package/dist/query/helpers/where.mjs.map +1 -1
- package/dist/query/query-builder.d.ts.map +1 -1
- package/dist/query/query-builder.js +35 -29
- package/dist/query/query-builder.js.map +1 -1
- package/dist/query/query-builder.mjs +35 -29
- package/dist/query/query-builder.mjs.map +1 -1
- package/dist/schema/builder.js +5 -5
- package/dist/schema/builder.js.map +1 -1
- package/dist/schema/builder.mjs +5 -5
- package/dist/schema/builder.mjs.map +1 -1
- package/dist/schema/diff.js +12 -12
- package/dist/schema/diff.js.map +1 -1
- package/dist/schema/diff.mjs +12 -12
- package/dist/schema/diff.mjs.map +1 -1
- package/dist/schema/index.d.ts +3 -1
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +6 -0
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/index.mjs +6 -0
- package/dist/schema/index.mjs.map +1 -1
- package/dist/schema/rename-helpers.d.ts +78 -0
- package/dist/schema/rename-helpers.d.ts.map +1 -0
- package/dist/schema/rename-helpers.js +235 -0
- package/dist/schema/rename-helpers.js.map +1 -0
- package/dist/schema/rename-helpers.mjs +233 -0
- package/dist/schema/rename-helpers.mjs.map +1 -0
- package/dist/utils/async-curry.d.ts.map +1 -1
- package/dist/utils/async-curry.js +1 -2
- package/dist/utils/async-curry.js.map +1 -1
- package/dist/utils/async-curry.mjs +1 -2
- package/dist/utils/async-curry.mjs.map +1 -1
- package/dist/utils/identifiers/hash.d.ts.map +1 -1
- package/dist/utils/identifiers/hash.js +1 -2
- package/dist/utils/identifiers/hash.js.map +1 -1
- package/dist/utils/identifiers/hash.mjs +1 -2
- package/dist/utils/identifiers/hash.mjs.map +1 -1
- package/dist/utils/identifiers/index.js +8 -10
- package/dist/utils/identifiers/index.js.map +1 -1
- package/dist/utils/identifiers/index.mjs +8 -6
- package/dist/utils/identifiers/index.mjs.map +1 -1
- package/dist/validations/relations/bidirectional.js +1 -1
- package/dist/validations/relations/bidirectional.js.map +1 -1
- package/dist/validations/relations/bidirectional.mjs +1 -1
- package/dist/validations/relations/bidirectional.mjs.map +1 -1
- package/package.json +6 -5
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
1
2
|
import type { Database } from '..';
|
|
2
3
|
import type { ForeignKey, Index, Schema } from '../schema';
|
|
3
4
|
export interface SchemaInspector {
|
|
@@ -26,6 +27,33 @@ export default class Dialect {
|
|
|
26
27
|
message: string;
|
|
27
28
|
}): void;
|
|
28
29
|
canAddIncrements(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether indexes and constraints can be renamed in place (used by the rename
|
|
32
|
+
* migration helpers to keep index/constraint names in sync with a renamed
|
|
33
|
+
* column or table). When false, schema sync drops and recreates them by name.
|
|
34
|
+
*/
|
|
35
|
+
canRenameSchemaObjects(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Renames the index or constraint `from` on `table` to `to`, if it exists and
|
|
38
|
+
* `to` is free. Runs on the given transaction. Returns whether a rename happened.
|
|
39
|
+
*/
|
|
40
|
+
renameSchemaObject(trx: Knex, params: {
|
|
41
|
+
table: string;
|
|
42
|
+
from: string;
|
|
43
|
+
to: string;
|
|
44
|
+
}): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Drops the index (and, where foreign keys are named, the foreign-key
|
|
47
|
+
* constraint) called `name` on `table`, if it exists. Used by the rename
|
|
48
|
+
* migration helpers on dialects that cannot rename schema objects in place,
|
|
49
|
+
* so a renamed table/column does not keep an index under its old name
|
|
50
|
+
* (schema sync never drops it and would collide when re-creating it). Runs on
|
|
51
|
+
* the given transaction. Returns whether anything was dropped.
|
|
52
|
+
*/
|
|
53
|
+
dropSchemaObject(trx: Knex, params: {
|
|
54
|
+
table: string;
|
|
55
|
+
name: string;
|
|
56
|
+
}): Promise<boolean>;
|
|
29
57
|
/**
|
|
30
58
|
* Max rows per batch for bulk inserts.
|
|
31
59
|
* Some databases limit multi-row insert size; override in dialect when a lower limit is required.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../../src/dialects/dialect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAE3D,MAAM,WAAW,eAAe;IAC9B,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IA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IAInB;;;OAGG;IACH,kBAAkB,IAAI,MAAM;IAI5B;;;;;;OAMG;IACH,0BAA0B,CAExB,WAAW,EAAE,MAAM,EAEnB,UAAU,EAAE,MAAM,GACjB;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;CAGhE"}
|
package/dist/dialects/dialect.js
CHANGED
|
@@ -44,6 +44,35 @@ class Dialect {
|
|
|
44
44
|
return true;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
+
* Whether indexes and constraints can be renamed in place (used by the rename
|
|
48
|
+
* migration helpers to keep index/constraint names in sync with a renamed
|
|
49
|
+
* column or table). When false, schema sync drops and recreates them by name.
|
|
50
|
+
*/ canRenameSchemaObjects() {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Renames the index or constraint `from` on `table` to `to`, if it exists and
|
|
55
|
+
* `to` is free. Runs on the given transaction. Returns whether a rename happened.
|
|
56
|
+
*/ // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
57
|
+
async renameSchemaObject(// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
58
|
+
trx, // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
59
|
+
params) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Drops the index (and, where foreign keys are named, the foreign-key
|
|
64
|
+
* constraint) called `name` on `table`, if it exists. Used by the rename
|
|
65
|
+
* migration helpers on dialects that cannot rename schema objects in place,
|
|
66
|
+
* so a renamed table/column does not keep an index under its old name
|
|
67
|
+
* (schema sync never drops it and would collide when re-creating it). Runs on
|
|
68
|
+
* the given transaction. Returns whether anything was dropped.
|
|
69
|
+
*/ // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
70
|
+
async dropSchemaObject(// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
71
|
+
trx, // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
72
|
+
params) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
47
76
|
* Max rows per batch for bulk inserts.
|
|
48
77
|
* Some databases limit multi-row insert size; override in dialect when a lower limit is required.
|
|
49
78
|
*/ getBatchInsertSize() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialect.js","sources":["../../src/dialects/dialect.ts"],"sourcesContent":["import type { Database } from '..';\nimport type { ForeignKey, Index, Schema } from '../schema';\n\nexport interface SchemaInspector {\n getSchema(): Promise<Schema>;\n getIndexes(tableName: string): Promise<Index[]>;\n getForeignKeys(tableName: string): Promise<ForeignKey[]>;\n getTables(): Promise<string[]>;\n}\n\nexport default class Dialect {\n db: Database;\n\n schemaInspector: SchemaInspector = {} as SchemaInspector;\n\n client: string;\n\n constructor(db: Database, client: string) {\n this.db = db;\n this.client = client;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n configure(conn?: any) {}\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async initialize(_nativeConnection?: unknown) {\n // noop\n }\n\n getTables() {\n throw new Error('getTables not implemented for this dialect');\n }\n\n getSqlType(type: unknown) {\n return type;\n }\n\n canAlterConstraints() {\n return true;\n }\n\n usesForeignKeys() {\n return false;\n }\n\n useReturning() {\n return false;\n }\n\n supportsUnsigned() {\n return false;\n }\n\n supportsOperator(operator?: string): boolean;\n supportsOperator(): boolean {\n return true;\n }\n\n async startSchemaUpdate() {\n // noop\n }\n\n async endSchemaUpdate() {\n // noop\n }\n\n transformErrors(error: Error | { message: string }) {\n if (error instanceof Error) {\n throw error;\n }\n\n throw new Error(error.message);\n }\n\n canAddIncrements() {\n return true;\n }\n\n /**\n * Max rows per batch for bulk inserts.\n * Some databases limit multi-row insert size; override in dialect when a lower limit is required.\n */\n getBatchInsertSize(): number {\n return 1000;\n }\n\n /**\n * Get column type conversion SQL for complex type changes\n * Override in specific dialects to handle database-specific conversions\n * @param currentType - The current database data type\n * @param targetType - The target Strapi type\n * @returns Conversion SQL details or null if no special handling needed\n */\n getColumnTypeConversionSQL(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n currentType: string,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n targetType: string\n ): { sql: string; typeClause: string; warning?: string } | null {\n return null;\n }\n}\n"],"names":["Dialect","configure","conn","initialize","_nativeConnection","getTables","Error","getSqlType","type","canAlterConstraints","usesForeignKeys","useReturning","supportsUnsigned","supportsOperator","startSchemaUpdate","endSchemaUpdate","transformErrors","error","message","canAddIncrements","getBatchInsertSize","getColumnTypeConversionSQL","currentType","targetType","db","client","schemaInspector"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"dialect.js","sources":["../../src/dialects/dialect.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Database } from '..';\nimport type { ForeignKey, Index, Schema } from '../schema';\n\nexport interface SchemaInspector {\n getSchema(): Promise<Schema>;\n getIndexes(tableName: string): Promise<Index[]>;\n getForeignKeys(tableName: string): Promise<ForeignKey[]>;\n getTables(): Promise<string[]>;\n}\n\nexport default class Dialect {\n db: Database;\n\n schemaInspector: SchemaInspector = {} as SchemaInspector;\n\n client: string;\n\n constructor(db: Database, client: string) {\n this.db = db;\n this.client = client;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n configure(conn?: any) {}\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async initialize(_nativeConnection?: unknown) {\n // noop\n }\n\n getTables() {\n throw new Error('getTables not implemented for this dialect');\n }\n\n getSqlType(type: unknown) {\n return type;\n }\n\n canAlterConstraints() {\n return true;\n }\n\n usesForeignKeys() {\n return false;\n }\n\n useReturning() {\n return false;\n }\n\n supportsUnsigned() {\n return false;\n }\n\n supportsOperator(operator?: string): boolean;\n supportsOperator(): boolean {\n return true;\n }\n\n async startSchemaUpdate() {\n // noop\n }\n\n async endSchemaUpdate() {\n // noop\n }\n\n transformErrors(error: Error | { message: string }) {\n if (error instanceof Error) {\n throw error;\n }\n\n throw new Error(error.message);\n }\n\n canAddIncrements() {\n return true;\n }\n\n /**\n * Whether indexes and constraints can be renamed in place (used by the rename\n * migration helpers to keep index/constraint names in sync with a renamed\n * column or table). When false, schema sync drops and recreates them by name.\n */\n canRenameSchemaObjects() {\n return false;\n }\n\n /**\n * Renames the index or constraint `from` on `table` to `to`, if it exists and\n * `to` is free. Runs on the given transaction. Returns whether a rename happened.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async renameSchemaObject(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n trx: Knex,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n params: { table: string; from: string; to: string }\n ): Promise<boolean> {\n return false;\n }\n\n /**\n * Drops the index (and, where foreign keys are named, the foreign-key\n * constraint) called `name` on `table`, if it exists. Used by the rename\n * migration helpers on dialects that cannot rename schema objects in place,\n * so a renamed table/column does not keep an index under its old name\n * (schema sync never drops it and would collide when re-creating it). Runs on\n * the given transaction. Returns whether anything was dropped.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async dropSchemaObject(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n trx: Knex,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n params: { table: string; name: string }\n ): Promise<boolean> {\n return false;\n }\n\n /**\n * Max rows per batch for bulk inserts.\n * Some databases limit multi-row insert size; override in dialect when a lower limit is required.\n */\n getBatchInsertSize(): number {\n return 1000;\n }\n\n /**\n * Get column type conversion SQL for complex type changes\n * Override in specific dialects to handle database-specific conversions\n * @param currentType - The current database data type\n * @param targetType - The target Strapi type\n * @returns Conversion SQL details or null if no special handling needed\n */\n getColumnTypeConversionSQL(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n currentType: string,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n targetType: string\n ): { sql: string; typeClause: string; warning?: string } | null {\n return null;\n }\n}\n"],"names":["Dialect","configure","conn","initialize","_nativeConnection","getTables","Error","getSqlType","type","canAlterConstraints","usesForeignKeys","useReturning","supportsUnsigned","supportsOperator","startSchemaUpdate","endSchemaUpdate","transformErrors","error","message","canAddIncrements","canRenameSchemaObjects","renameSchemaObject","trx","params","dropSchemaObject","getBatchInsertSize","getColumnTypeConversionSQL","currentType","targetType","db","client","schemaInspector"],"mappings":";;AAYe,MAAMA,OAAAA,CAAAA;;IAanBC,SAAAA,CAAUC,IAAU,EAAE,CAAC;;IAGvB,MAAMC,UAAAA,CAAWC,iBAA2B,EAAE;;AAE9C,IAAA;IAEAC,SAAAA,GAAY;AACV,QAAA,MAAM,IAAIC,KAAAA,CAAM,4CAAA,CAAA;AAClB,IAAA;AAEAC,IAAAA,UAAAA,CAAWC,IAAa,EAAE;QACxB,OAAOA,IAAAA;AACT,IAAA;IAEAC,mBAAAA,GAAsB;QACpB,OAAO,IAAA;AACT,IAAA;IAEAC,eAAAA,GAAkB;QAChB,OAAO,KAAA;AACT,IAAA;IAEAC,YAAAA,GAAe;QACb,OAAO,KAAA;AACT,IAAA;IAEAC,gBAAAA,GAAmB;QACjB,OAAO,KAAA;AACT,IAAA;IAGAC,gBAAAA,GAA4B;QAC1B,OAAO,IAAA;AACT,IAAA;AAEA,IAAA,MAAMC,iBAAAA,GAAoB;;AAE1B,IAAA;AAEA,IAAA,MAAMC,eAAAA,GAAkB;;AAExB,IAAA;AAEAC,IAAAA,eAAAA,CAAgBC,KAAkC,EAAE;AAClD,QAAA,IAAIA,iBAAiBX,KAAAA,EAAO;YAC1B,MAAMW,KAAAA;AACR,QAAA;QAEA,MAAM,IAAIX,KAAAA,CAAMW,KAAAA,CAAMC,OAAO,CAAA;AAC/B,IAAA;IAEAC,gBAAAA,GAAmB;QACjB,OAAO,IAAA;AACT,IAAA;AAEA;;;;AAIC,MACDC,sBAAAA,GAAyB;QACvB,OAAO,KAAA;AACT,IAAA;AAEA;;;AAGC;AAED,IAAA,MAAMC;AAEJC,IAAAA,GAAS;AAETC,IAAAA,MAAmD,EACjC;QAClB,OAAO,KAAA;AACT,IAAA;AAEA;;;;;;;AAOC;AAED,IAAA,MAAMC;AAEJF,IAAAA,GAAS;AAETC,IAAAA,MAAuC,EACrB;QAClB,OAAO,KAAA;AACT,IAAA;AAEA;;;AAGC,MACDE,kBAAAA,GAA6B;QAC3B,OAAO,IAAA;AACT,IAAA;AAEA;;;;;;AAMC,MACDC;AAEEC,IAAAA,WAAmB;AAEnBC,IAAAA,UAAkB,EAC4C;QAC9D,OAAO,IAAA;AACT,IAAA;IA7HA,WAAA,CAAYC,EAAY,EAAEC,MAAc,CAAE;AAJ1CC,QAAAA,IAAAA,CAAAA,eAAAA,GAAmC,EAAC;QAKlC,IAAI,CAACF,EAAE,GAAGA,EAAAA;QACV,IAAI,CAACC,MAAM,GAAGA,MAAAA;AAChB,IAAA;AA2HF;;;;"}
|
|
@@ -42,6 +42,35 @@ class Dialect {
|
|
|
42
42
|
return true;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
+
* Whether indexes and constraints can be renamed in place (used by the rename
|
|
46
|
+
* migration helpers to keep index/constraint names in sync with a renamed
|
|
47
|
+
* column or table). When false, schema sync drops and recreates them by name.
|
|
48
|
+
*/ canRenameSchemaObjects() {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Renames the index or constraint `from` on `table` to `to`, if it exists and
|
|
53
|
+
* `to` is free. Runs on the given transaction. Returns whether a rename happened.
|
|
54
|
+
*/ // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
55
|
+
async renameSchemaObject(// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
56
|
+
trx, // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
57
|
+
params) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Drops the index (and, where foreign keys are named, the foreign-key
|
|
62
|
+
* constraint) called `name` on `table`, if it exists. Used by the rename
|
|
63
|
+
* migration helpers on dialects that cannot rename schema objects in place,
|
|
64
|
+
* so a renamed table/column does not keep an index under its old name
|
|
65
|
+
* (schema sync never drops it and would collide when re-creating it). Runs on
|
|
66
|
+
* the given transaction. Returns whether anything was dropped.
|
|
67
|
+
*/ // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
68
|
+
async dropSchemaObject(// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
69
|
+
trx, // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
70
|
+
params) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
45
74
|
* Max rows per batch for bulk inserts.
|
|
46
75
|
* Some databases limit multi-row insert size; override in dialect when a lower limit is required.
|
|
47
76
|
*/ getBatchInsertSize() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialect.mjs","sources":["../../src/dialects/dialect.ts"],"sourcesContent":["import type { Database } from '..';\nimport type { ForeignKey, Index, Schema } from '../schema';\n\nexport interface SchemaInspector {\n getSchema(): Promise<Schema>;\n getIndexes(tableName: string): Promise<Index[]>;\n getForeignKeys(tableName: string): Promise<ForeignKey[]>;\n getTables(): Promise<string[]>;\n}\n\nexport default class Dialect {\n db: Database;\n\n schemaInspector: SchemaInspector = {} as SchemaInspector;\n\n client: string;\n\n constructor(db: Database, client: string) {\n this.db = db;\n this.client = client;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n configure(conn?: any) {}\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async initialize(_nativeConnection?: unknown) {\n // noop\n }\n\n getTables() {\n throw new Error('getTables not implemented for this dialect');\n }\n\n getSqlType(type: unknown) {\n return type;\n }\n\n canAlterConstraints() {\n return true;\n }\n\n usesForeignKeys() {\n return false;\n }\n\n useReturning() {\n return false;\n }\n\n supportsUnsigned() {\n return false;\n }\n\n supportsOperator(operator?: string): boolean;\n supportsOperator(): boolean {\n return true;\n }\n\n async startSchemaUpdate() {\n // noop\n }\n\n async endSchemaUpdate() {\n // noop\n }\n\n transformErrors(error: Error | { message: string }) {\n if (error instanceof Error) {\n throw error;\n }\n\n throw new Error(error.message);\n }\n\n canAddIncrements() {\n return true;\n }\n\n /**\n * Max rows per batch for bulk inserts.\n * Some databases limit multi-row insert size; override in dialect when a lower limit is required.\n */\n getBatchInsertSize(): number {\n return 1000;\n }\n\n /**\n * Get column type conversion SQL for complex type changes\n * Override in specific dialects to handle database-specific conversions\n * @param currentType - The current database data type\n * @param targetType - The target Strapi type\n * @returns Conversion SQL details or null if no special handling needed\n */\n getColumnTypeConversionSQL(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n currentType: string,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n targetType: string\n ): { sql: string; typeClause: string; warning?: string } | null {\n return null;\n }\n}\n"],"names":["Dialect","configure","conn","initialize","_nativeConnection","getTables","Error","getSqlType","type","canAlterConstraints","usesForeignKeys","useReturning","supportsUnsigned","supportsOperator","startSchemaUpdate","endSchemaUpdate","transformErrors","error","message","canAddIncrements","getBatchInsertSize","getColumnTypeConversionSQL","currentType","targetType","db","client","schemaInspector"],"mappings":"
|
|
1
|
+
{"version":3,"file":"dialect.mjs","sources":["../../src/dialects/dialect.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Database } from '..';\nimport type { ForeignKey, Index, Schema } from '../schema';\n\nexport interface SchemaInspector {\n getSchema(): Promise<Schema>;\n getIndexes(tableName: string): Promise<Index[]>;\n getForeignKeys(tableName: string): Promise<ForeignKey[]>;\n getTables(): Promise<string[]>;\n}\n\nexport default class Dialect {\n db: Database;\n\n schemaInspector: SchemaInspector = {} as SchemaInspector;\n\n client: string;\n\n constructor(db: Database, client: string) {\n this.db = db;\n this.client = client;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n configure(conn?: any) {}\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async initialize(_nativeConnection?: unknown) {\n // noop\n }\n\n getTables() {\n throw new Error('getTables not implemented for this dialect');\n }\n\n getSqlType(type: unknown) {\n return type;\n }\n\n canAlterConstraints() {\n return true;\n }\n\n usesForeignKeys() {\n return false;\n }\n\n useReturning() {\n return false;\n }\n\n supportsUnsigned() {\n return false;\n }\n\n supportsOperator(operator?: string): boolean;\n supportsOperator(): boolean {\n return true;\n }\n\n async startSchemaUpdate() {\n // noop\n }\n\n async endSchemaUpdate() {\n // noop\n }\n\n transformErrors(error: Error | { message: string }) {\n if (error instanceof Error) {\n throw error;\n }\n\n throw new Error(error.message);\n }\n\n canAddIncrements() {\n return true;\n }\n\n /**\n * Whether indexes and constraints can be renamed in place (used by the rename\n * migration helpers to keep index/constraint names in sync with a renamed\n * column or table). When false, schema sync drops and recreates them by name.\n */\n canRenameSchemaObjects() {\n return false;\n }\n\n /**\n * Renames the index or constraint `from` on `table` to `to`, if it exists and\n * `to` is free. Runs on the given transaction. Returns whether a rename happened.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async renameSchemaObject(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n trx: Knex,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n params: { table: string; from: string; to: string }\n ): Promise<boolean> {\n return false;\n }\n\n /**\n * Drops the index (and, where foreign keys are named, the foreign-key\n * constraint) called `name` on `table`, if it exists. Used by the rename\n * migration helpers on dialects that cannot rename schema objects in place,\n * so a renamed table/column does not keep an index under its old name\n * (schema sync never drops it and would collide when re-creating it). Runs on\n * the given transaction. Returns whether anything was dropped.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async dropSchemaObject(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n trx: Knex,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n params: { table: string; name: string }\n ): Promise<boolean> {\n return false;\n }\n\n /**\n * Max rows per batch for bulk inserts.\n * Some databases limit multi-row insert size; override in dialect when a lower limit is required.\n */\n getBatchInsertSize(): number {\n return 1000;\n }\n\n /**\n * Get column type conversion SQL for complex type changes\n * Override in specific dialects to handle database-specific conversions\n * @param currentType - The current database data type\n * @param targetType - The target Strapi type\n * @returns Conversion SQL details or null if no special handling needed\n */\n getColumnTypeConversionSQL(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n currentType: string,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n targetType: string\n ): { sql: string; typeClause: string; warning?: string } | null {\n return null;\n }\n}\n"],"names":["Dialect","configure","conn","initialize","_nativeConnection","getTables","Error","getSqlType","type","canAlterConstraints","usesForeignKeys","useReturning","supportsUnsigned","supportsOperator","startSchemaUpdate","endSchemaUpdate","transformErrors","error","message","canAddIncrements","canRenameSchemaObjects","renameSchemaObject","trx","params","dropSchemaObject","getBatchInsertSize","getColumnTypeConversionSQL","currentType","targetType","db","client","schemaInspector"],"mappings":"AAYe,MAAMA,OAAAA,CAAAA;;IAanBC,SAAAA,CAAUC,IAAU,EAAE,CAAC;;IAGvB,MAAMC,UAAAA,CAAWC,iBAA2B,EAAE;;AAE9C,IAAA;IAEAC,SAAAA,GAAY;AACV,QAAA,MAAM,IAAIC,KAAAA,CAAM,4CAAA,CAAA;AAClB,IAAA;AAEAC,IAAAA,UAAAA,CAAWC,IAAa,EAAE;QACxB,OAAOA,IAAAA;AACT,IAAA;IAEAC,mBAAAA,GAAsB;QACpB,OAAO,IAAA;AACT,IAAA;IAEAC,eAAAA,GAAkB;QAChB,OAAO,KAAA;AACT,IAAA;IAEAC,YAAAA,GAAe;QACb,OAAO,KAAA;AACT,IAAA;IAEAC,gBAAAA,GAAmB;QACjB,OAAO,KAAA;AACT,IAAA;IAGAC,gBAAAA,GAA4B;QAC1B,OAAO,IAAA;AACT,IAAA;AAEA,IAAA,MAAMC,iBAAAA,GAAoB;;AAE1B,IAAA;AAEA,IAAA,MAAMC,eAAAA,GAAkB;;AAExB,IAAA;AAEAC,IAAAA,eAAAA,CAAgBC,KAAkC,EAAE;AAClD,QAAA,IAAIA,iBAAiBX,KAAAA,EAAO;YAC1B,MAAMW,KAAAA;AACR,QAAA;QAEA,MAAM,IAAIX,KAAAA,CAAMW,KAAAA,CAAMC,OAAO,CAAA;AAC/B,IAAA;IAEAC,gBAAAA,GAAmB;QACjB,OAAO,IAAA;AACT,IAAA;AAEA;;;;AAIC,MACDC,sBAAAA,GAAyB;QACvB,OAAO,KAAA;AACT,IAAA;AAEA;;;AAGC;AAED,IAAA,MAAMC;AAEJC,IAAAA,GAAS;AAETC,IAAAA,MAAmD,EACjC;QAClB,OAAO,KAAA;AACT,IAAA;AAEA;;;;;;;AAOC;AAED,IAAA,MAAMC;AAEJF,IAAAA,GAAS;AAETC,IAAAA,MAAuC,EACrB;QAClB,OAAO,KAAA;AACT,IAAA;AAEA;;;AAGC,MACDE,kBAAAA,GAA6B;QAC3B,OAAO,IAAA;AACT,IAAA;AAEA;;;;;;AAMC,MACDC;AAEEC,IAAAA,WAAmB;AAEnBC,IAAAA,UAAkB,EAC4C;QAC9D,OAAO,IAAA;AACT,IAAA;IA7HA,WAAA,CAAYC,EAAY,EAAEC,MAAc,CAAE;AAJ1CC,QAAAA,IAAAA,CAAAA,eAAAA,GAAmC,EAAC;QAKlC,IAAI,CAACF,EAAE,GAAGA,EAAAA;QACV,IAAI,CAACC,MAAM,GAAGA,MAAAA;AAChB,IAAA;AA2HF;;;;"}
|
|
@@ -15,6 +15,15 @@ export default class MysqlDialect extends Dialect {
|
|
|
15
15
|
endSchemaUpdate(): Promise<void>;
|
|
16
16
|
supportsUnsigned(): boolean;
|
|
17
17
|
usesForeignKeys(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Drops the foreign-key constraint named `name` on `table` (MySQL FK names
|
|
20
|
+
* are unique per database, so a stale one blocks re-creating it on any
|
|
21
|
+
* table), then the index of the same name. Runs on `trx`.
|
|
22
|
+
*/
|
|
23
|
+
dropSchemaObject(trx: Knex, { table, name }: {
|
|
24
|
+
table: string;
|
|
25
|
+
name: string;
|
|
26
|
+
}): Promise<boolean>;
|
|
18
27
|
transformErrors(error: Error): void;
|
|
19
28
|
}
|
|
20
29
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialects/mysql/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,oBAAoB,MAAM,oBAAoB,CAAC;AACtD,OAAO,sBAAsB,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,OAAO;IAC/C,eAAe,EAAE,oBAAoB,CAAC;IAEtC,iBAAiB,EAAE,sBAAsB,CAAC;IAE1C,IAAI,EAAE,WAAW,GAAG,IAAI,CAAQ;gBAEpB,EAAE,EAAE,QAAQ;IAOxB,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,qBAAqB;IA+BrC,UAAU,CAAC,gBAAgB,EAAE,OAAO;IAoBpC,iBAAiB;IASjB,eAAe;IAIrB,gBAAgB;IAIhB,eAAe;IAIf,eAAe,CAAC,KAAK,EAAE,KAAK;CAG7B"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialects/mysql/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,oBAAoB,MAAM,oBAAoB,CAAC;AACtD,OAAO,sBAAsB,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,OAAO;IAC/C,eAAe,EAAE,oBAAoB,CAAC;IAEtC,iBAAiB,EAAE,sBAAsB,CAAC;IAE1C,IAAI,EAAE,WAAW,GAAG,IAAI,CAAQ;gBAEpB,EAAE,EAAE,QAAQ;IAOxB,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,qBAAqB;IA+BrC,UAAU,CAAC,gBAAgB,EAAE,OAAO;IAoBpC,iBAAiB;IASjB,eAAe;IAIrB,gBAAgB;IAIhB,eAAe;IAIf;;;;OAIG;IACG,gBAAgB,CACpB,GAAG,EAAE,IAAI,EACT,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC/C,OAAO,CAAC,OAAO,CAAC;IA+BnB,eAAe,CAAC,KAAK,EAAE,KAAK;CAG7B"}
|
|
@@ -60,6 +60,43 @@ class MysqlDialect extends dialect {
|
|
|
60
60
|
usesForeignKeys() {
|
|
61
61
|
return true;
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Drops the foreign-key constraint named `name` on `table` (MySQL FK names
|
|
65
|
+
* are unique per database, so a stale one blocks re-creating it on any
|
|
66
|
+
* table), then the index of the same name. Runs on `trx`.
|
|
67
|
+
*/ async dropSchemaObject(trx, { table, name }) {
|
|
68
|
+
let dropped = false;
|
|
69
|
+
const [foreignKeys] = await trx.raw(`SELECT 1
|
|
70
|
+
FROM information_schema.table_constraints
|
|
71
|
+
WHERE table_schema = database() AND table_name = ? AND constraint_name = ?
|
|
72
|
+
AND constraint_type = 'FOREIGN KEY'
|
|
73
|
+
LIMIT 1`, [
|
|
74
|
+
table,
|
|
75
|
+
name
|
|
76
|
+
]);
|
|
77
|
+
if (foreignKeys.length > 0) {
|
|
78
|
+
await trx.raw('ALTER TABLE ?? DROP FOREIGN KEY ??', [
|
|
79
|
+
table,
|
|
80
|
+
name
|
|
81
|
+
]);
|
|
82
|
+
dropped = true;
|
|
83
|
+
}
|
|
84
|
+
const [indexes] = await trx.raw(`SELECT 1
|
|
85
|
+
FROM information_schema.statistics
|
|
86
|
+
WHERE table_schema = database() AND table_name = ? AND index_name = ?
|
|
87
|
+
LIMIT 1`, [
|
|
88
|
+
table,
|
|
89
|
+
name
|
|
90
|
+
]);
|
|
91
|
+
if (indexes.length > 0) {
|
|
92
|
+
await trx.raw('ALTER TABLE ?? DROP INDEX ??', [
|
|
93
|
+
table,
|
|
94
|
+
name
|
|
95
|
+
]);
|
|
96
|
+
dropped = true;
|
|
97
|
+
}
|
|
98
|
+
return dropped;
|
|
99
|
+
}
|
|
63
100
|
transformErrors(error) {
|
|
64
101
|
super.transformErrors(error);
|
|
65
102
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/dialects/mysql/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport Dialect from '../dialect';\nimport MysqlSchemaInspector from './schema-inspector';\nimport MysqlDatabaseInspector from './database-inspector';\nimport type { Database } from '../..';\n\nimport type { Information } from './database-inspector';\n\nexport default class MysqlDialect extends Dialect {\n schemaInspector: MysqlSchemaInspector;\n\n databaseInspector: MysqlDatabaseInspector;\n\n info: Information | null = null;\n\n constructor(db: Database) {\n super(db, 'mysql');\n\n this.schemaInspector = new MysqlSchemaInspector(db);\n this.databaseInspector = new MysqlDatabaseInspector(db);\n }\n\n configure(conn?: Knex.MySqlConnectionConfig) {\n const connection = conn || (this.db.config.connection.connection as Knex.MySqlConnectionConfig);\n\n connection.supportBigNumbers = true;\n // Only allow bigNumberStrings option set to be true if no connection option passed\n // Otherwise bigNumberStrings option should be allowed to used from DB config\n if (connection.bigNumberStrings === undefined) {\n connection.bigNumberStrings = true;\n }\n connection.typeCast = (\n field: { type: string; string: () => string; length: number },\n next: () => void\n ) => {\n if (field.type === 'DECIMAL' || field.type === 'NEWDECIMAL') {\n const value = field.string();\n return value === null ? null : Number(value);\n }\n\n if (field.type === 'TINY' && field.length === 1) {\n const value = field.string();\n return value ? value === '1' : null;\n }\n\n if (field.type === 'DATE') {\n return field.string();\n }\n\n return next();\n };\n }\n\n async initialize(nativeConnection: unknown) {\n try {\n await this.db.connection\n .raw(`set session sql_require_primary_key = 0;`)\n .connection(nativeConnection);\n } catch {\n // Ignore error due to lack of session permissions\n }\n\n // We only need to get info on the first connection in the pool\n /**\n * Note: There is a race condition here where if two connections are opened at the same time, both will retrieve\n * db info, but it doesn't cause issues, it's just one wasted query one time, so we can safely leave it to avoid\n * adding extra complexity\n * */\n if (!this.info) {\n this.info = await this.databaseInspector.getInformation(nativeConnection);\n }\n }\n\n async startSchemaUpdate() {\n try {\n await this.db.connection.raw(`set foreign_key_checks = 0;`);\n await this.db.connection.raw(`set session sql_require_primary_key = 0;`);\n } catch {\n // Ignore error due to lack of session permissions\n }\n }\n\n async endSchemaUpdate() {\n await this.db.connection.raw(`set foreign_key_checks = 1;`);\n }\n\n supportsUnsigned() {\n return true;\n }\n\n usesForeignKeys() {\n return true;\n }\n\n transformErrors(error: Error) {\n super.transformErrors(error);\n }\n}\n"],"names":["MysqlDialect","Dialect","configure","conn","connection","db","config","supportBigNumbers","bigNumberStrings","undefined","typeCast","field","next","type","value","string","Number","length","initialize","nativeConnection","raw","info","databaseInspector","getInformation","startSchemaUpdate","endSchemaUpdate","supportsUnsigned","usesForeignKeys","transformErrors","error","schemaInspector","MysqlSchemaInspector","MysqlDatabaseInspector"],"mappings":";;;;;;AASe,MAAMA,YAAAA,SAAqBC,OAAAA,CAAAA;AAcxCC,IAAAA,SAAAA,CAAUC,IAAiC,EAAE;QAC3C,MAAMC,UAAAA,GAAaD,IAAAA,IAAS,IAAI,CAACE,EAAE,CAACC,MAAM,CAACF,UAAU,CAACA,UAAU;AAEhEA,QAAAA,UAAAA,CAAWG,iBAAiB,GAAG,IAAA;;;QAG/B,IAAIH,UAAAA,CAAWI,gBAAgB,KAAKC,SAAAA,EAAW;AAC7CL,YAAAA,UAAAA,CA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MAAM,IAAI,CAACf,EAAE,CAACD,UAAU,CAACgB,GAAG,CAAC,CAAC,wCAAwC,CAAC,CAAA;AACzE,QAAA,CAAA,CAAE,OAAM;;AAER,QAAA;AACF,IAAA;AAEA,IAAA,MAAMK,eAAAA,GAAkB;QACtB,MAAM,IAAI,CAACpB,EAAE,CAACD,UAAU,CAACgB,GAAG,CAAC,CAAC,2BAA2B,CAAC,CAAA;AAC5D,IAAA;IAEAM,gBAAAA,GAAmB;QACjB,OAAO,IAAA;AACT,IAAA;IAEAC,eAAAA,GAAkB;QAChB,OAAO,IAAA;AACT,IAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/dialects/mysql/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport Dialect from '../dialect';\nimport MysqlSchemaInspector from './schema-inspector';\nimport MysqlDatabaseInspector from './database-inspector';\nimport type { Database } from '../..';\n\nimport type { Information } from './database-inspector';\n\nexport default class MysqlDialect extends Dialect {\n schemaInspector: MysqlSchemaInspector;\n\n databaseInspector: MysqlDatabaseInspector;\n\n info: Information | null = null;\n\n constructor(db: Database) {\n super(db, 'mysql');\n\n this.schemaInspector = new MysqlSchemaInspector(db);\n this.databaseInspector = new MysqlDatabaseInspector(db);\n }\n\n configure(conn?: Knex.MySqlConnectionConfig) {\n const connection = conn || (this.db.config.connection.connection as Knex.MySqlConnectionConfig);\n\n connection.supportBigNumbers = true;\n // Only allow bigNumberStrings option set to be true if no connection option passed\n // Otherwise bigNumberStrings option should be allowed to used from DB config\n if (connection.bigNumberStrings === undefined) {\n connection.bigNumberStrings = true;\n }\n connection.typeCast = (\n field: { type: string; string: () => string; length: number },\n next: () => void\n ) => {\n if (field.type === 'DECIMAL' || field.type === 'NEWDECIMAL') {\n const value = field.string();\n return value === null ? null : Number(value);\n }\n\n if (field.type === 'TINY' && field.length === 1) {\n const value = field.string();\n return value ? value === '1' : null;\n }\n\n if (field.type === 'DATE') {\n return field.string();\n }\n\n return next();\n };\n }\n\n async initialize(nativeConnection: unknown) {\n try {\n await this.db.connection\n .raw(`set session sql_require_primary_key = 0;`)\n .connection(nativeConnection);\n } catch {\n // Ignore error due to lack of session permissions\n }\n\n // We only need to get info on the first connection in the pool\n /**\n * Note: There is a race condition here where if two connections are opened at the same time, both will retrieve\n * db info, but it doesn't cause issues, it's just one wasted query one time, so we can safely leave it to avoid\n * adding extra complexity\n * */\n if (!this.info) {\n this.info = await this.databaseInspector.getInformation(nativeConnection);\n }\n }\n\n async startSchemaUpdate() {\n try {\n await this.db.connection.raw(`set foreign_key_checks = 0;`);\n await this.db.connection.raw(`set session sql_require_primary_key = 0;`);\n } catch {\n // Ignore error due to lack of session permissions\n }\n }\n\n async endSchemaUpdate() {\n await this.db.connection.raw(`set foreign_key_checks = 1;`);\n }\n\n supportsUnsigned() {\n return true;\n }\n\n usesForeignKeys() {\n return true;\n }\n\n /**\n * Drops the foreign-key constraint named `name` on `table` (MySQL FK names\n * are unique per database, so a stale one blocks re-creating it on any\n * table), then the index of the same name. Runs on `trx`.\n */\n async dropSchemaObject(\n trx: Knex,\n { table, name }: { table: string; name: string }\n ): Promise<boolean> {\n let dropped = false;\n\n const [foreignKeys] = await trx.raw(\n `SELECT 1\n FROM information_schema.table_constraints\n WHERE table_schema = database() AND table_name = ? AND constraint_name = ?\n AND constraint_type = 'FOREIGN KEY'\n LIMIT 1`,\n [table, name]\n );\n if (foreignKeys.length > 0) {\n await trx.raw('ALTER TABLE ?? DROP FOREIGN KEY ??', [table, name]);\n dropped = true;\n }\n\n const [indexes] = await trx.raw(\n `SELECT 1\n FROM information_schema.statistics\n WHERE table_schema = database() AND table_name = ? AND index_name = ?\n LIMIT 1`,\n [table, name]\n );\n if (indexes.length > 0) {\n await trx.raw('ALTER TABLE ?? DROP INDEX ??', [table, name]);\n dropped = true;\n }\n\n return dropped;\n }\n\n transformErrors(error: Error) {\n super.transformErrors(error);\n }\n}\n"],"names":["MysqlDialect","Dialect","configure","conn","connection","db","config","supportBigNumbers","bigNumberStrings","undefined","typeCast","field","next","type","value","string","Number","length","initialize","nativeConnection","raw","info","databaseInspector","getInformation","startSchemaUpdate","endSchemaUpdate","supportsUnsigned","usesForeignKeys","dropSchemaObject","trx","table","name","dropped","foreignKeys","indexes","transformErrors","error","schemaInspector","MysqlSchemaInspector","MysqlDatabaseInspector"],"mappings":";;;;;;AASe,MAAMA,YAAAA,SAAqBC,OAAAA,CAAAA;AAcxCC,IAAAA,SAAAA,CAAUC,IAAiC,EAAE;QAC3C,MAAMC,UAAAA,GAAaD,IAAAA,IAAS,IAAI,CAACE,EAAE,CAACC,MAAM,CAACF,UAAU,CAACA,UAAU;AAEhEA,QAAAA,UAAAA,CAAWG,iBAAiB,GAAG,IAAA;;;QAG/B,IAAIH,UAAAA,CAAWI,gBAAgB,KAAKC,SAAAA,EAAW;AAC7CL,YAAAA,UAAAA,CAAWI,gBAAgB,GAAG,IAAA;AAChC,QAAA;QACAJ,UAAAA,CAAWM,QAAQ,GAAG,CACpBC,KAAAA,EACAC,IAAAA,GAAAA;AAEA,YAAA,IAAID,MAAME,IAAI,KAAK,aAAaF,KAAAA,CAAME,IAAI,KAAK,YAAA,EAAc;gBAC3D,MAAMC,KAAAA,GAAQH,MAAMI,MAAM,EAAA;gBAC1B,OAAOD,KAAAA,KAAU,IAAA,GAAO,IAAA,GAAOE,MAAAA,CAAOF,KAAAA,CAAAA;AACxC,YAAA;AAEA,YAAA,IAAIH,MAAME,IAAI,KAAK,UAAUF,KAAAA,CAAMM,MAAM,KAAK,CAAA,EAAG;gBAC/C,MAAMH,KAAAA,GAAQH,MAAMI,MAAM,EAAA;gBAC1B,OAAOD,KAAAA,GAAQA,UAAU,GAAA,GAAM,IAAA;AACjC,YAAA;YAEA,IAAIH,KAAAA,CAAME,IAAI,KAAK,MAAA,EAAQ;AACzB,gBAAA,OAAOF,MAAMI,MAAM,EAAA;AACrB,YAAA;YAEA,OAAOH,IAAAA,EAAAA;AACT,QAAA,CAAA;AACF,IAAA;IAEA,MAAMM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A,EAAG;YAC1B,MAAMY,GAAAA,CAAIT,GAAG,CAAC,oCAAA,EAAsC;AAACU,gBAAAA,KAAAA;AAAOC,gBAAAA;AAAK,aAAA,CAAA;YACjEC,OAAAA,GAAU,IAAA;AACZ,QAAA;AAEA,QAAA,MAAM,CAACE,OAAAA,CAAQ,GAAG,MAAML,GAAAA,CAAIT,GAAG,CAC7B,CAAC;;;AAGO,cAAA,CAAC,EACT;AAACU,YAAAA,KAAAA;AAAOC,YAAAA;AAAK,SAAA,CAAA;QAEf,IAAIG,OAAAA,CAAQjB,MAAM,GAAG,CAAA,EAAG;YACtB,MAAMY,GAAAA,CAAIT,GAAG,CAAC,8BAAA,EAAgC;AAACU,gBAAAA,KAAAA;AAAOC,gBAAAA;AAAK,aAAA,CAAA;YAC3DC,OAAAA,GAAU,IAAA;AACZ,QAAA;QAEA,OAAOA,OAAAA;AACT,IAAA;AAEAG,IAAAA,eAAAA,CAAgBC,KAAY,EAAE;AAC5B,QAAA,KAAK,CAACD,eAAAA,CAAgBC,KAAAA,CAAAA;AACxB,IAAA;AAxHA,IAAA,WAAA,CAAY/B,EAAY,CAAE;QACxB,KAAK,CAACA,EAAAA,EAAI,OAAA,CAAA,EAAA,IAAA,CAHZgB,IAAAA,GAA2B,IAAA;AAKzB,QAAA,IAAI,CAACgB,eAAe,GAAG,IAAIC,eAAAA,CAAqBjC,EAAAA,CAAAA;AAChD,QAAA,IAAI,CAACiB,iBAAiB,GAAG,IAAIiB,iBAAAA,CAAuBlC,EAAAA,CAAAA;AACtD,IAAA;AAoHF;;;;"}
|
|
@@ -58,6 +58,43 @@ class MysqlDialect extends Dialect {
|
|
|
58
58
|
usesForeignKeys() {
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Drops the foreign-key constraint named `name` on `table` (MySQL FK names
|
|
63
|
+
* are unique per database, so a stale one blocks re-creating it on any
|
|
64
|
+
* table), then the index of the same name. Runs on `trx`.
|
|
65
|
+
*/ async dropSchemaObject(trx, { table, name }) {
|
|
66
|
+
let dropped = false;
|
|
67
|
+
const [foreignKeys] = await trx.raw(`SELECT 1
|
|
68
|
+
FROM information_schema.table_constraints
|
|
69
|
+
WHERE table_schema = database() AND table_name = ? AND constraint_name = ?
|
|
70
|
+
AND constraint_type = 'FOREIGN KEY'
|
|
71
|
+
LIMIT 1`, [
|
|
72
|
+
table,
|
|
73
|
+
name
|
|
74
|
+
]);
|
|
75
|
+
if (foreignKeys.length > 0) {
|
|
76
|
+
await trx.raw('ALTER TABLE ?? DROP FOREIGN KEY ??', [
|
|
77
|
+
table,
|
|
78
|
+
name
|
|
79
|
+
]);
|
|
80
|
+
dropped = true;
|
|
81
|
+
}
|
|
82
|
+
const [indexes] = await trx.raw(`SELECT 1
|
|
83
|
+
FROM information_schema.statistics
|
|
84
|
+
WHERE table_schema = database() AND table_name = ? AND index_name = ?
|
|
85
|
+
LIMIT 1`, [
|
|
86
|
+
table,
|
|
87
|
+
name
|
|
88
|
+
]);
|
|
89
|
+
if (indexes.length > 0) {
|
|
90
|
+
await trx.raw('ALTER TABLE ?? DROP INDEX ??', [
|
|
91
|
+
table,
|
|
92
|
+
name
|
|
93
|
+
]);
|
|
94
|
+
dropped = true;
|
|
95
|
+
}
|
|
96
|
+
return dropped;
|
|
97
|
+
}
|
|
61
98
|
transformErrors(error) {
|
|
62
99
|
super.transformErrors(error);
|
|
63
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/dialects/mysql/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport Dialect from '../dialect';\nimport MysqlSchemaInspector from './schema-inspector';\nimport MysqlDatabaseInspector from './database-inspector';\nimport type { Database } from '../..';\n\nimport type { Information } from './database-inspector';\n\nexport default class MysqlDialect extends Dialect {\n schemaInspector: MysqlSchemaInspector;\n\n databaseInspector: MysqlDatabaseInspector;\n\n info: Information | null = null;\n\n constructor(db: Database) {\n super(db, 'mysql');\n\n this.schemaInspector = new MysqlSchemaInspector(db);\n this.databaseInspector = new MysqlDatabaseInspector(db);\n }\n\n configure(conn?: Knex.MySqlConnectionConfig) {\n const connection = conn || (this.db.config.connection.connection as Knex.MySqlConnectionConfig);\n\n connection.supportBigNumbers = true;\n // Only allow bigNumberStrings option set to be true if no connection option passed\n // Otherwise bigNumberStrings option should be allowed to used from DB config\n if (connection.bigNumberStrings === undefined) {\n connection.bigNumberStrings = true;\n }\n connection.typeCast = (\n field: { type: string; string: () => string; length: number },\n next: () => void\n ) => {\n if (field.type === 'DECIMAL' || field.type === 'NEWDECIMAL') {\n const value = field.string();\n return value === null ? null : Number(value);\n }\n\n if (field.type === 'TINY' && field.length === 1) {\n const value = field.string();\n return value ? value === '1' : null;\n }\n\n if (field.type === 'DATE') {\n return field.string();\n }\n\n return next();\n };\n }\n\n async initialize(nativeConnection: unknown) {\n try {\n await this.db.connection\n .raw(`set session sql_require_primary_key = 0;`)\n .connection(nativeConnection);\n } catch {\n // Ignore error due to lack of session permissions\n }\n\n // We only need to get info on the first connection in the pool\n /**\n * Note: There is a race condition here where if two connections are opened at the same time, both will retrieve\n * db info, but it doesn't cause issues, it's just one wasted query one time, so we can safely leave it to avoid\n * adding extra complexity\n * */\n if (!this.info) {\n this.info = await this.databaseInspector.getInformation(nativeConnection);\n }\n }\n\n async startSchemaUpdate() {\n try {\n await this.db.connection.raw(`set foreign_key_checks = 0;`);\n await this.db.connection.raw(`set session sql_require_primary_key = 0;`);\n } catch {\n // Ignore error due to lack of session permissions\n }\n }\n\n async endSchemaUpdate() {\n await this.db.connection.raw(`set foreign_key_checks = 1;`);\n }\n\n supportsUnsigned() {\n return true;\n }\n\n usesForeignKeys() {\n return true;\n }\n\n transformErrors(error: Error) {\n super.transformErrors(error);\n }\n}\n"],"names":["MysqlDialect","Dialect","configure","conn","connection","db","config","supportBigNumbers","bigNumberStrings","undefined","typeCast","field","next","type","value","string","Number","length","initialize","nativeConnection","raw","info","databaseInspector","getInformation","startSchemaUpdate","endSchemaUpdate","supportsUnsigned","usesForeignKeys","transformErrors","error","schemaInspector","MysqlSchemaInspector","MysqlDatabaseInspector"],"mappings":";;;;AASe,MAAMA,YAAAA,SAAqBC,OAAAA,CAAAA;AAcxCC,IAAAA,SAAAA,CAAUC,IAAiC,EAAE;QAC3C,MAAMC,UAAAA,GAAaD,IAAAA,IAAS,IAAI,CAACE,EAAE,CAACC,MAAM,CAACF,UAAU,CAACA,UAAU;AAEhEA,QAAAA,UAAAA,CAAWG,iBAAiB,GAAG,IAAA;;;QAG/B,IAAIH,UAAAA,CAAWI,gBAAgB,KAAKC,SAAAA,EAAW;AAC7CL,YAAAA,UAAAA,CAAWI,gBAAgB,GAAG,IAAA;AAChC,QAAA;QACAJ,UAAAA,CAAWM,QAAQ,GAAG,CACpBC,KAAAA,EACAC,IAAAA,GAAAA;AAEA,YAAA,IAAID,MAAME,IAAI,KAAK,aAAaF,KAAAA,CAAME,IAAI,KAAK,YAAA,EAAc;gBAC3D,MAAMC,KAAAA,GAAQH,MAAMI,MAAM,EAAA;gBAC1B,OAAOD,KAAAA,KAAU,IAAA,GAAO,IAAA,GAAOE,MAAAA,CAAOF,KAAAA,CAAAA;AACxC,YAAA;AAEA,YAAA,IAAIH,MAAME,IAAI,KAAK,UAAUF,KAAAA,CAAMM,MAAM,KAAK,CAAA,EAAG;gBAC/C,MAAMH,KAAAA,GAAQH,MAAMI,MAAM,EAAA;gBAC1B,OAAOD,KAAAA,GAAQA,UAAU,GAAA,GAAM,IAAA;AACjC,YAAA;YAEA,IAAIH,KAAAA,CAAME,IAAI,KAAK,MAAA,EAAQ;AACzB,gBAAA,OAAOF,MAAMI,MAAM,EAAA;AACrB,YAAA;YAEA,OAAOH,IAAAA,EAAAA;AACT,QAAA,CAAA;AACF,IAAA;IAEA,MAAMM,UAAAA,CAAWC,gBAAyB,EAAE;QAC1C,IAAI;AACF,YAAA,MAAM,IAAI,CAACd,EAAE,CAACD,UAAU,CACrBgB,GAAG,CAAC,CAAC,wCAAwC,CAAC,CAAA,CAC9ChB,UAAU,CAACe,gBAAAA,CAAAA;AAChB,QAAA,CAAA,CAAE,OAAM;;AAER,QAAA;;AAGA;;;;AAIG,UACH,IAAI,CAAC,IAAI,CAACE,IAAI,EAAE;YACd,IAAI,CAACA,IAAI,GAAG,MAAM,IAAI,CAACC,iBAAiB,CAACC,cAAc,CAACJ,gBAAAA,CAAAA;AAC1D,QAAA;AACF,IAAA;AAEA,IAAA,MAAMK,iBAAAA,GAAoB;QACxB,IAAI;YACF,MAAM,IAAI,CAACnB,EAAE,CAACD,UAAU,CAACgB,GAAG,CAAC,CAAC,2BAA2B,CAAC,CAAA;YAC1D,MAAM,IAAI,CAACf,EAAE,CAACD,UAAU,CAACgB,GAAG,CAAC,CAAC,wCAAwC,CAAC,CAAA;AACzE,QAAA,CAAA,CAAE,OAAM;;AAER,QAAA;AACF,IAAA;AAEA,IAAA,MAAMK,eAAAA,GAAkB;QACtB,MAAM,IAAI,CAACpB,EAAE,CAACD,UAAU,CAACgB,GAAG,CAAC,CAAC,2BAA2B,CAAC,CAAA;AAC5D,IAAA;IAEAM,gBAAAA,GAAmB;QACjB,OAAO,IAAA;AACT,IAAA;IAEAC,eAAAA,GAAkB;QAChB,OAAO,IAAA;AACT,IAAA;
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/dialects/mysql/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport Dialect from '../dialect';\nimport MysqlSchemaInspector from './schema-inspector';\nimport MysqlDatabaseInspector from './database-inspector';\nimport type { Database } from '../..';\n\nimport type { Information } from './database-inspector';\n\nexport default class MysqlDialect extends Dialect {\n schemaInspector: MysqlSchemaInspector;\n\n databaseInspector: MysqlDatabaseInspector;\n\n info: Information | null = null;\n\n constructor(db: Database) {\n super(db, 'mysql');\n\n this.schemaInspector = new MysqlSchemaInspector(db);\n this.databaseInspector = new MysqlDatabaseInspector(db);\n }\n\n configure(conn?: Knex.MySqlConnectionConfig) {\n const connection = conn || (this.db.config.connection.connection as Knex.MySqlConnectionConfig);\n\n connection.supportBigNumbers = true;\n // Only allow bigNumberStrings option set to be true if no connection option passed\n // Otherwise bigNumberStrings option should be allowed to used from DB config\n if (connection.bigNumberStrings === undefined) {\n connection.bigNumberStrings = true;\n }\n connection.typeCast = (\n field: { type: string; string: () => string; length: number },\n next: () => void\n ) => {\n if (field.type === 'DECIMAL' || field.type === 'NEWDECIMAL') {\n const value = field.string();\n return value === null ? null : Number(value);\n }\n\n if (field.type === 'TINY' && field.length === 1) {\n const value = field.string();\n return value ? value === '1' : null;\n }\n\n if (field.type === 'DATE') {\n return field.string();\n }\n\n return next();\n };\n }\n\n async initialize(nativeConnection: unknown) {\n try {\n await this.db.connection\n .raw(`set session sql_require_primary_key = 0;`)\n .connection(nativeConnection);\n } catch {\n // Ignore error due to lack of session permissions\n }\n\n // We only need to get info on the first connection in the pool\n /**\n * Note: There is a race condition here where if two connections are opened at the same time, both will retrieve\n * db info, but it doesn't cause issues, it's just one wasted query one time, so we can safely leave it to avoid\n * adding extra complexity\n * */\n if (!this.info) {\n this.info = await this.databaseInspector.getInformation(nativeConnection);\n }\n }\n\n async startSchemaUpdate() {\n try {\n await this.db.connection.raw(`set foreign_key_checks = 0;`);\n await this.db.connection.raw(`set session sql_require_primary_key = 0;`);\n } catch {\n // Ignore error due to lack of session permissions\n }\n }\n\n async endSchemaUpdate() {\n await this.db.connection.raw(`set foreign_key_checks = 1;`);\n }\n\n supportsUnsigned() {\n return true;\n }\n\n usesForeignKeys() {\n return true;\n }\n\n /**\n * Drops the foreign-key constraint named `name` on `table` (MySQL FK names\n * are unique per database, so a stale one blocks re-creating it on any\n * table), then the index of the same name. Runs on `trx`.\n */\n async dropSchemaObject(\n trx: Knex,\n { table, name }: { table: string; name: string }\n ): Promise<boolean> {\n let dropped = false;\n\n const [foreignKeys] = await trx.raw(\n `SELECT 1\n FROM information_schema.table_constraints\n WHERE table_schema = database() AND table_name = ? AND constraint_name = ?\n AND constraint_type = 'FOREIGN KEY'\n LIMIT 1`,\n [table, name]\n );\n if (foreignKeys.length > 0) {\n await trx.raw('ALTER TABLE ?? DROP FOREIGN KEY ??', [table, name]);\n dropped = true;\n }\n\n const [indexes] = await trx.raw(\n `SELECT 1\n FROM information_schema.statistics\n WHERE table_schema = database() AND table_name = ? AND index_name = ?\n LIMIT 1`,\n [table, name]\n );\n if (indexes.length > 0) {\n await trx.raw('ALTER TABLE ?? DROP INDEX ??', [table, name]);\n dropped = true;\n }\n\n return dropped;\n }\n\n transformErrors(error: Error) {\n super.transformErrors(error);\n }\n}\n"],"names":["MysqlDialect","Dialect","configure","conn","connection","db","config","supportBigNumbers","bigNumberStrings","undefined","typeCast","field","next","type","value","string","Number","length","initialize","nativeConnection","raw","info","databaseInspector","getInformation","startSchemaUpdate","endSchemaUpdate","supportsUnsigned","usesForeignKeys","dropSchemaObject","trx","table","name","dropped","foreignKeys","indexes","transformErrors","error","schemaInspector","MysqlSchemaInspector","MysqlDatabaseInspector"],"mappings":";;;;AASe,MAAMA,YAAAA,SAAqBC,OAAAA,CAAAA;AAcxCC,IAAAA,SAAAA,CAAUC,IAAiC,EAAE;QAC3C,MAAMC,UAAAA,GAAaD,IAAAA,IAAS,IAAI,CAACE,EAAE,CAACC,MAAM,CAACF,UAAU,CAACA,UAAU;AAEhEA,QAAAA,UAAAA,CAAWG,iBAAiB,GAAG,IAAA;;;QAG/B,IAAIH,UAAAA,CAAWI,gBAAgB,KAAKC,SAAAA,EAAW;AAC7CL,YAAAA,UAAAA,CAAWI,gBAAgB,GAAG,IAAA;AAChC,QAAA;QACAJ,UAAAA,CAAWM,QAAQ,GAAG,CACpBC,KAAAA,EACAC,IAAAA,GAAAA;AAEA,YAAA,IAAID,MAAME,IAAI,KAAK,aAAaF,KAAAA,CAAME,IAAI,KAAK,YAAA,EAAc;gBAC3D,MAAMC,KAAAA,GAAQH,MAAMI,MAAM,EAAA;gBAC1B,OAAOD,KAAAA,KAAU,IAAA,GAAO,IAAA,G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Ae,GAAG,IAAIC,oBAAAA,CAAqBjC,EAAAA,CAAAA;AAChD,QAAA,IAAI,CAACiB,iBAAiB,GAAG,IAAIiB,sBAAAA,CAAuBlC,EAAAA,CAAAA;AACtD,IAAA;AAoHF;;;;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
1
2
|
import type { Database } from '../..';
|
|
2
3
|
import Dialect from '../dialect';
|
|
3
4
|
import PostgresqlSchemaInspector from './schema-inspector';
|
|
@@ -7,6 +8,12 @@ export default class PostgresDialect extends Dialect {
|
|
|
7
8
|
useReturning(): boolean;
|
|
8
9
|
initialize(nativeConnection: unknown): Promise<void>;
|
|
9
10
|
usesForeignKeys(): boolean;
|
|
11
|
+
canRenameSchemaObjects(): boolean;
|
|
12
|
+
renameSchemaObject(trx: Knex, { table, from, to }: {
|
|
13
|
+
table: string;
|
|
14
|
+
from: string;
|
|
15
|
+
to: string;
|
|
16
|
+
}): Promise<boolean>;
|
|
10
17
|
getSqlType(type: string): string;
|
|
11
18
|
transformErrors(error: NodeJS.ErrnoException): void;
|
|
12
19
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialects/postgresql/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialects/postgresql/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAGjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,yBAAyB,MAAM,oBAAoB,CAAC;AAE3D,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,OAAO;IAClD,eAAe,EAAE,yBAAyB,CAAC;gBAE/B,EAAE,EAAE,QAAQ;IAMxB,YAAY;IAIN,UAAU,CAAC,gBAAgB,EAAE,OAAO;IA+B1C,eAAe;IAIf,sBAAsB;IAIhB,kBAAkB,CACtB,GAAG,EAAE,IAAI,EACT,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAC/D,OAAO,CAAC,OAAO,CAAC;IA8CnB,UAAU,CAAC,IAAI,EAAE,MAAM;IAWvB,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,cAAc;IAa5C;;;;;OAKG;IACH,0BAA0B,CACxB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB;QACD,GAAG,EAAE,MAAM,CAAC;QACZ,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,IAAI;CAuBT"}
|
|
@@ -26,6 +26,56 @@ class PostgresDialect extends dialect {
|
|
|
26
26
|
usesForeignKeys() {
|
|
27
27
|
return true;
|
|
28
28
|
}
|
|
29
|
+
canRenameSchemaObjects() {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
async renameSchemaObject(trx, { table, from, to }) {
|
|
33
|
+
const hasConstraint = async (name)=>{
|
|
34
|
+
const result = await trx.raw(`SELECT 1
|
|
35
|
+
FROM pg_constraint c
|
|
36
|
+
JOIN pg_class t ON t.oid = c.conrelid
|
|
37
|
+
JOIN pg_namespace n ON n.oid = t.relnamespace
|
|
38
|
+
WHERE n.nspname = current_schema() AND t.relname = ? AND c.conname = ?
|
|
39
|
+
LIMIT 1`, [
|
|
40
|
+
table,
|
|
41
|
+
name
|
|
42
|
+
]);
|
|
43
|
+
return result.rows.length > 0;
|
|
44
|
+
};
|
|
45
|
+
const hasIndex = async (name)=>{
|
|
46
|
+
const result = await trx.raw(`SELECT 1
|
|
47
|
+
FROM pg_indexes
|
|
48
|
+
WHERE schemaname = current_schema() AND tablename = ? AND indexname = ?
|
|
49
|
+
LIMIT 1`, [
|
|
50
|
+
table,
|
|
51
|
+
name
|
|
52
|
+
]);
|
|
53
|
+
return result.rows.length > 0;
|
|
54
|
+
};
|
|
55
|
+
let renamed = false;
|
|
56
|
+
// Unique constraints back their index with the same name, so renaming the
|
|
57
|
+
// constraint renames that index too. Foreign-key constraints do not: Strapi
|
|
58
|
+
// also creates a separate, same-named index on the FK column, which is
|
|
59
|
+
// renamed in the second step below.
|
|
60
|
+
if (await hasConstraint(from)) {
|
|
61
|
+
if (!await hasConstraint(to) && !await hasIndex(to)) {
|
|
62
|
+
await trx.raw('ALTER TABLE ?? RENAME CONSTRAINT ?? TO ??', [
|
|
63
|
+
table,
|
|
64
|
+
from,
|
|
65
|
+
to
|
|
66
|
+
]);
|
|
67
|
+
renamed = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (await hasIndex(from) && !await hasIndex(to)) {
|
|
71
|
+
await trx.raw('ALTER INDEX ?? RENAME TO ??', [
|
|
72
|
+
from,
|
|
73
|
+
to
|
|
74
|
+
]);
|
|
75
|
+
renamed = true;
|
|
76
|
+
}
|
|
77
|
+
return renamed;
|
|
78
|
+
}
|
|
29
79
|
getSqlType(type) {
|
|
30
80
|
switch(type){
|
|
31
81
|
case 'timestamp':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/dialects/postgresql/index.ts"],"sourcesContent":["import * as errors from '../../errors';\nimport type { Database } from '../..';\nimport Dialect from '../dialect';\nimport PostgresqlSchemaInspector from './schema-inspector';\n\nexport default class PostgresDialect extends Dialect {\n schemaInspector: PostgresqlSchemaInspector;\n\n constructor(db: Database) {\n super(db, 'postgres');\n\n this.schemaInspector = new PostgresqlSchemaInspector(db);\n }\n\n useReturning() {\n return true;\n }\n\n async initialize(nativeConnection: unknown) {\n // Don't cast DATE string to Date()\n this.db.connection.client.driver.types.setTypeParser(\n this.db.connection.client.driver.types.builtins.DATE,\n 'text',\n (v: unknown) => v\n );\n // Don't parse JSONB automatically\n this.db.connection.client.driver.types.setTypeParser(\n this.db.connection.client.driver.types.builtins.JSONB,\n 'text',\n (v: unknown) => v\n );\n this.db.connection.client.driver.types.setTypeParser(\n this.db.connection.client.driver.types.builtins.NUMERIC,\n 'text',\n parseFloat\n );\n\n // If we're using a schema, set the default path for all table names in queries to use that schema\n // Ideally we would rely on Knex config.searchPath to do this for us\n // However, createConnection must remain synchronous and if the user is using a connection function,\n // we do not know what their schema is until after the connection is resolved\n const schemaName = this.db.getSchemaName();\n if (schemaName) {\n await this.db.connection\n .raw(`SET search_path TO \"${schemaName}\"`)\n .connection(nativeConnection);\n }\n }\n\n usesForeignKeys() {\n return true;\n }\n\n getSqlType(type: string) {\n switch (type) {\n case 'timestamp': {\n return 'datetime';\n }\n default: {\n return type;\n }\n }\n }\n\n transformErrors(error: NodeJS.ErrnoException) {\n switch (error.code) {\n case '23502': {\n throw new errors.NotNullError({\n column: 'column' in error ? `${error.column}` : undefined,\n });\n }\n default: {\n super.transformErrors(error);\n }\n }\n }\n\n /**\n * Get column type conversion SQL with USING clause for PostgreSQL\n * @param currentType - The current PostgreSQL data type\n * @param targetType - The target Strapi type\n * @returns SQL string with USING clause or null if no special conversion needed\n */\n getColumnTypeConversionSQL(\n currentType: string,\n targetType: string\n ): {\n sql: string;\n typeClause: string;\n warning?: string;\n } | null {\n // Time to datetime conversion\n if (targetType === 'datetime' && currentType === 'time without time zone') {\n return {\n sql: `ALTER TABLE ?? ALTER COLUMN ?? TYPE timestamp(6) USING ('1970-01-01 ' || ??::text)::timestamp`,\n typeClause: 'timestamp(6)',\n warning:\n 'Time values will be converted to datetime with default date \"1970-01-01\". Original time values will be preserved.',\n };\n }\n\n // Datetime to time conversion\n if (targetType === 'time' && currentType === 'timestamp without time zone') {\n return {\n sql: `ALTER TABLE ?? ALTER COLUMN ?? TYPE time(3) USING ??::time`,\n typeClause: 'time(3)',\n warning: 'Datetime values will be converted to time only. Date information will be lost.',\n };\n }\n\n // No special conversion needed\n return null;\n }\n}\n"],"names":["PostgresDialect","Dialect","useReturning","initialize","nativeConnection","db","connection","client","driver","types","setTypeParser","builtins","DATE","v","JSONB","NUMERIC","parseFloat","schemaName","getSchemaName","raw","usesForeignKeys","getSqlType","type","transformErrors","error","code","errors","column","undefined","getColumnTypeConversionSQL","currentType","targetType","sql","typeClause","warning","schemaInspector","PostgresqlSchemaInspector"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/dialects/postgresql/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport * as errors from '../../errors';\nimport type { Database } from '../..';\nimport Dialect from '../dialect';\nimport PostgresqlSchemaInspector from './schema-inspector';\n\nexport default class PostgresDialect extends Dialect {\n schemaInspector: PostgresqlSchemaInspector;\n\n constructor(db: Database) {\n super(db, 'postgres');\n\n this.schemaInspector = new PostgresqlSchemaInspector(db);\n }\n\n useReturning() {\n return true;\n }\n\n async initialize(nativeConnection: unknown) {\n // Don't cast DATE string to Date()\n this.db.connection.client.driver.types.setTypeParser(\n this.db.connection.client.driver.types.builtins.DATE,\n 'text',\n (v: unknown) => v\n );\n // Don't parse JSONB automatically\n this.db.connection.client.driver.types.setTypeParser(\n this.db.connection.client.driver.types.builtins.JSONB,\n 'text',\n (v: unknown) => v\n );\n this.db.connection.client.driver.types.setTypeParser(\n this.db.connection.client.driver.types.builtins.NUMERIC,\n 'text',\n parseFloat\n );\n\n // If we're using a schema, set the default path for all table names in queries to use that schema\n // Ideally we would rely on Knex config.searchPath to do this for us\n // However, createConnection must remain synchronous and if the user is using a connection function,\n // we do not know what their schema is until after the connection is resolved\n const schemaName = this.db.getSchemaName();\n if (schemaName) {\n await this.db.connection\n .raw(`SET search_path TO \"${schemaName}\"`)\n .connection(nativeConnection);\n }\n }\n\n usesForeignKeys() {\n return true;\n }\n\n canRenameSchemaObjects() {\n return true;\n }\n\n async renameSchemaObject(\n trx: Knex,\n { table, from, to }: { table: string; from: string; to: string }\n ): Promise<boolean> {\n const hasConstraint = async (name: string): Promise<boolean> => {\n const result = await trx.raw(\n `SELECT 1\n FROM pg_constraint c\n JOIN pg_class t ON t.oid = c.conrelid\n JOIN pg_namespace n ON n.oid = t.relnamespace\n WHERE n.nspname = current_schema() AND t.relname = ? AND c.conname = ?\n LIMIT 1`,\n [table, name]\n );\n return result.rows.length > 0;\n };\n\n const hasIndex = async (name: string): Promise<boolean> => {\n const result = await trx.raw(\n `SELECT 1\n FROM pg_indexes\n WHERE schemaname = current_schema() AND tablename = ? AND indexname = ?\n LIMIT 1`,\n [table, name]\n );\n return result.rows.length > 0;\n };\n\n let renamed = false;\n\n // Unique constraints back their index with the same name, so renaming the\n // constraint renames that index too. Foreign-key constraints do not: Strapi\n // also creates a separate, same-named index on the FK column, which is\n // renamed in the second step below.\n if (await hasConstraint(from)) {\n if (!(await hasConstraint(to)) && !(await hasIndex(to))) {\n await trx.raw('ALTER TABLE ?? RENAME CONSTRAINT ?? TO ??', [table, from, to]);\n renamed = true;\n }\n }\n\n if ((await hasIndex(from)) && !(await hasIndex(to))) {\n await trx.raw('ALTER INDEX ?? RENAME TO ??', [from, to]);\n renamed = true;\n }\n\n return renamed;\n }\n\n getSqlType(type: string) {\n switch (type) {\n case 'timestamp': {\n return 'datetime';\n }\n default: {\n return type;\n }\n }\n }\n\n transformErrors(error: NodeJS.ErrnoException) {\n switch (error.code) {\n case '23502': {\n throw new errors.NotNullError({\n column: 'column' in error ? `${error.column}` : undefined,\n });\n }\n default: {\n super.transformErrors(error);\n }\n }\n }\n\n /**\n * Get column type conversion SQL with USING clause for PostgreSQL\n * @param currentType - The current PostgreSQL data type\n * @param targetType - The target Strapi type\n * @returns SQL string with USING clause or null if no special conversion needed\n */\n getColumnTypeConversionSQL(\n currentType: string,\n targetType: string\n ): {\n sql: string;\n typeClause: string;\n warning?: string;\n } | null {\n // Time to datetime conversion\n if (targetType === 'datetime' && currentType === 'time without time zone') {\n return {\n sql: `ALTER TABLE ?? ALTER COLUMN ?? TYPE timestamp(6) USING ('1970-01-01 ' || ??::text)::timestamp`,\n typeClause: 'timestamp(6)',\n warning:\n 'Time values will be converted to datetime with default date \"1970-01-01\". Original time values will be preserved.',\n };\n }\n\n // Datetime to time conversion\n if (targetType === 'time' && currentType === 'timestamp without time zone') {\n return {\n sql: `ALTER TABLE ?? ALTER COLUMN ?? TYPE time(3) USING ??::time`,\n typeClause: 'time(3)',\n warning: 'Datetime values will be converted to time only. Date information will be lost.',\n };\n }\n\n // No special conversion needed\n return null;\n }\n}\n"],"names":["PostgresDialect","Dialect","useReturning","initialize","nativeConnection","db","connection","client","driver","types","setTypeParser","builtins","DATE","v","JSONB","NUMERIC","parseFloat","schemaName","getSchemaName","raw","usesForeignKeys","canRenameSchemaObjects","renameSchemaObject","trx","table","from","to","hasConstraint","name","result","rows","length","hasIndex","renamed","getSqlType","type","transformErrors","error","code","errors","column","undefined","getColumnTypeConversionSQL","currentType","targetType","sql","typeClause","warning","schemaInspector","PostgresqlSchemaInspector"],"mappings":";;;;;;AAOe,MAAMA,eAAAA,SAAwBC,OAAAA,CAAAA;IAS3CC,YAAAA,GAAe;QACb,OAAO,IAAA;AACT,IAAA;IAEA,MAAMC,UAAAA,CAAWC,gBAAyB,EAAE;;AAE1C,QAAA,IAAI,CAACC,EAAE,CAACC,UAAU,CAACC,MAAM,CAACC,MAAM,CAACC,KAAK,CAACC,aAAa,CAClD,IAAI,CAACL,EAAE,CAACC,UAAU,CAACC,MAAM,CAACC,MAAM,CAACC,KAAK,CAACE,QAAQ,CAACC,IAAI,EACpD,MAAA,EACA,CAACC,CAAAA,GAAeA,CAAAA,CAAAA;;AAGlB,QAAA,IAAI,CAACR,EAAE,CAACC,UAAU,CAACC,MAAM,CAACC,MAAM,CAACC,KAAK,CAACC,aAAa,CAClD,IAAI,CAACL,EAAE,CAACC,UAAU,CAACC,MAAM,CAACC,MAAM,CAACC,KAAK,CAACE,QAAQ,CAACG,KAAK,EACrD,MAAA,EACA,CAACD,CAAAA,GAAeA,CA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A,CAAAA;AACxB,gBAAA;AACF;AACF,IAAA;AAEA;;;;;AAKC,MACDK,0BAAAA,CACEC,WAAmB,EACnBC,UAAkB,EAKX;;QAEP,IAAIA,UAAAA,KAAe,UAAA,IAAcD,WAAAA,KAAgB,wBAAA,EAA0B;YACzE,OAAO;gBACLE,GAAAA,EAAK,CAAC,6FAA6F,CAAC;gBACpGC,UAAAA,EAAY,cAAA;gBACZC,OAAAA,EACE;AACJ,aAAA;AACF,QAAA;;QAGA,IAAIH,UAAAA,KAAe,MAAA,IAAUD,WAAAA,KAAgB,6BAAA,EAA+B;YAC1E,OAAO;gBACLE,GAAAA,EAAK,CAAC,0DAA0D,CAAC;gBACjEC,UAAAA,EAAY,SAAA;gBACZC,OAAAA,EAAS;AACX,aAAA;AACF,QAAA;;QAGA,OAAO,IAAA;AACT,IAAA;AA7JA,IAAA,WAAA,CAAY1C,EAAY,CAAE;AACxB,QAAA,KAAK,CAACA,EAAAA,EAAI,UAAA,CAAA;AAEV,QAAA,IAAI,CAAC2C,eAAe,GAAG,IAAIC,eAAAA,CAA0B5C,EAAAA,CAAAA;AACvD,IAAA;AA0JF;;;;"}
|
|
@@ -24,6 +24,56 @@ class PostgresDialect extends Dialect {
|
|
|
24
24
|
usesForeignKeys() {
|
|
25
25
|
return true;
|
|
26
26
|
}
|
|
27
|
+
canRenameSchemaObjects() {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
async renameSchemaObject(trx, { table, from, to }) {
|
|
31
|
+
const hasConstraint = async (name)=>{
|
|
32
|
+
const result = await trx.raw(`SELECT 1
|
|
33
|
+
FROM pg_constraint c
|
|
34
|
+
JOIN pg_class t ON t.oid = c.conrelid
|
|
35
|
+
JOIN pg_namespace n ON n.oid = t.relnamespace
|
|
36
|
+
WHERE n.nspname = current_schema() AND t.relname = ? AND c.conname = ?
|
|
37
|
+
LIMIT 1`, [
|
|
38
|
+
table,
|
|
39
|
+
name
|
|
40
|
+
]);
|
|
41
|
+
return result.rows.length > 0;
|
|
42
|
+
};
|
|
43
|
+
const hasIndex = async (name)=>{
|
|
44
|
+
const result = await trx.raw(`SELECT 1
|
|
45
|
+
FROM pg_indexes
|
|
46
|
+
WHERE schemaname = current_schema() AND tablename = ? AND indexname = ?
|
|
47
|
+
LIMIT 1`, [
|
|
48
|
+
table,
|
|
49
|
+
name
|
|
50
|
+
]);
|
|
51
|
+
return result.rows.length > 0;
|
|
52
|
+
};
|
|
53
|
+
let renamed = false;
|
|
54
|
+
// Unique constraints back their index with the same name, so renaming the
|
|
55
|
+
// constraint renames that index too. Foreign-key constraints do not: Strapi
|
|
56
|
+
// also creates a separate, same-named index on the FK column, which is
|
|
57
|
+
// renamed in the second step below.
|
|
58
|
+
if (await hasConstraint(from)) {
|
|
59
|
+
if (!await hasConstraint(to) && !await hasIndex(to)) {
|
|
60
|
+
await trx.raw('ALTER TABLE ?? RENAME CONSTRAINT ?? TO ??', [
|
|
61
|
+
table,
|
|
62
|
+
from,
|
|
63
|
+
to
|
|
64
|
+
]);
|
|
65
|
+
renamed = true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (await hasIndex(from) && !await hasIndex(to)) {
|
|
69
|
+
await trx.raw('ALTER INDEX ?? RENAME TO ??', [
|
|
70
|
+
from,
|
|
71
|
+
to
|
|
72
|
+
]);
|
|
73
|
+
renamed = true;
|
|
74
|
+
}
|
|
75
|
+
return renamed;
|
|
76
|
+
}
|
|
27
77
|
getSqlType(type) {
|
|
28
78
|
switch(type){
|
|
29
79
|
case 'timestamp':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/dialects/postgresql/index.ts"],"sourcesContent":["import * as errors from '../../errors';\nimport type { Database } from '../..';\nimport Dialect from '../dialect';\nimport PostgresqlSchemaInspector from './schema-inspector';\n\nexport default class PostgresDialect extends Dialect {\n schemaInspector: PostgresqlSchemaInspector;\n\n constructor(db: Database) {\n super(db, 'postgres');\n\n this.schemaInspector = new PostgresqlSchemaInspector(db);\n }\n\n useReturning() {\n return true;\n }\n\n async initialize(nativeConnection: unknown) {\n // Don't cast DATE string to Date()\n this.db.connection.client.driver.types.setTypeParser(\n this.db.connection.client.driver.types.builtins.DATE,\n 'text',\n (v: unknown) => v\n );\n // Don't parse JSONB automatically\n this.db.connection.client.driver.types.setTypeParser(\n this.db.connection.client.driver.types.builtins.JSONB,\n 'text',\n (v: unknown) => v\n );\n this.db.connection.client.driver.types.setTypeParser(\n this.db.connection.client.driver.types.builtins.NUMERIC,\n 'text',\n parseFloat\n );\n\n // If we're using a schema, set the default path for all table names in queries to use that schema\n // Ideally we would rely on Knex config.searchPath to do this for us\n // However, createConnection must remain synchronous and if the user is using a connection function,\n // we do not know what their schema is until after the connection is resolved\n const schemaName = this.db.getSchemaName();\n if (schemaName) {\n await this.db.connection\n .raw(`SET search_path TO \"${schemaName}\"`)\n .connection(nativeConnection);\n }\n }\n\n usesForeignKeys() {\n return true;\n }\n\n getSqlType(type: string) {\n switch (type) {\n case 'timestamp': {\n return 'datetime';\n }\n default: {\n return type;\n }\n }\n }\n\n transformErrors(error: NodeJS.ErrnoException) {\n switch (error.code) {\n case '23502': {\n throw new errors.NotNullError({\n column: 'column' in error ? `${error.column}` : undefined,\n });\n }\n default: {\n super.transformErrors(error);\n }\n }\n }\n\n /**\n * Get column type conversion SQL with USING clause for PostgreSQL\n * @param currentType - The current PostgreSQL data type\n * @param targetType - The target Strapi type\n * @returns SQL string with USING clause or null if no special conversion needed\n */\n getColumnTypeConversionSQL(\n currentType: string,\n targetType: string\n ): {\n sql: string;\n typeClause: string;\n warning?: string;\n } | null {\n // Time to datetime conversion\n if (targetType === 'datetime' && currentType === 'time without time zone') {\n return {\n sql: `ALTER TABLE ?? ALTER COLUMN ?? TYPE timestamp(6) USING ('1970-01-01 ' || ??::text)::timestamp`,\n typeClause: 'timestamp(6)',\n warning:\n 'Time values will be converted to datetime with default date \"1970-01-01\". Original time values will be preserved.',\n };\n }\n\n // Datetime to time conversion\n if (targetType === 'time' && currentType === 'timestamp without time zone') {\n return {\n sql: `ALTER TABLE ?? ALTER COLUMN ?? TYPE time(3) USING ??::time`,\n typeClause: 'time(3)',\n warning: 'Datetime values will be converted to time only. Date information will be lost.',\n };\n }\n\n // No special conversion needed\n return null;\n }\n}\n"],"names":["PostgresDialect","Dialect","useReturning","initialize","nativeConnection","db","connection","client","driver","types","setTypeParser","builtins","DATE","v","JSONB","NUMERIC","parseFloat","schemaName","getSchemaName","raw","usesForeignKeys","getSqlType","type","transformErrors","error","code","errors","column","undefined","getColumnTypeConversionSQL","currentType","targetType","sql","typeClause","warning","schemaInspector","PostgresqlSchemaInspector"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/dialects/postgresql/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport * as errors from '../../errors';\nimport type { Database } from '../..';\nimport Dialect from '../dialect';\nimport PostgresqlSchemaInspector from './schema-inspector';\n\nexport default class PostgresDialect extends Dialect {\n schemaInspector: PostgresqlSchemaInspector;\n\n constructor(db: Database) {\n super(db, 'postgres');\n\n this.schemaInspector = new PostgresqlSchemaInspector(db);\n }\n\n useReturning() {\n return true;\n }\n\n async initialize(nativeConnection: unknown) {\n // Don't cast DATE string to Date()\n this.db.connection.client.driver.types.setTypeParser(\n this.db.connection.client.driver.types.builtins.DATE,\n 'text',\n (v: unknown) => v\n );\n // Don't parse JSONB automatically\n this.db.connection.client.driver.types.setTypeParser(\n this.db.connection.client.driver.types.builtins.JSONB,\n 'text',\n (v: unknown) => v\n );\n this.db.connection.client.driver.types.setTypeParser(\n this.db.connection.client.driver.types.builtins.NUMERIC,\n 'text',\n parseFloat\n );\n\n // If we're using a schema, set the default path for all table names in queries to use that schema\n // Ideally we would rely on Knex config.searchPath to do this for us\n // However, createConnection must remain synchronous and if the user is using a connection function,\n // we do not know what their schema is until after the connection is resolved\n const schemaName = this.db.getSchemaName();\n if (schemaName) {\n await this.db.connection\n .raw(`SET search_path TO \"${schemaName}\"`)\n .connection(nativeConnection);\n }\n }\n\n usesForeignKeys() {\n return true;\n }\n\n canRenameSchemaObjects() {\n return true;\n }\n\n async renameSchemaObject(\n trx: Knex,\n { table, from, to }: { table: string; from: string; to: string }\n ): Promise<boolean> {\n const hasConstraint = async (name: string): Promise<boolean> => {\n const result = await trx.raw(\n `SELECT 1\n FROM pg_constraint c\n JOIN pg_class t ON t.oid = c.conrelid\n JOIN pg_namespace n ON n.oid = t.relnamespace\n WHERE n.nspname = current_schema() AND t.relname = ? AND c.conname = ?\n LIMIT 1`,\n [table, name]\n );\n return result.rows.length > 0;\n };\n\n const hasIndex = async (name: string): Promise<boolean> => {\n const result = await trx.raw(\n `SELECT 1\n FROM pg_indexes\n WHERE schemaname = current_schema() AND tablename = ? AND indexname = ?\n LIMIT 1`,\n [table, name]\n );\n return result.rows.length > 0;\n };\n\n let renamed = false;\n\n // Unique constraints back their index with the same name, so renaming the\n // constraint renames that index too. Foreign-key constraints do not: Strapi\n // also creates a separate, same-named index on the FK column, which is\n // renamed in the second step below.\n if (await hasConstraint(from)) {\n if (!(await hasConstraint(to)) && !(await hasIndex(to))) {\n await trx.raw('ALTER TABLE ?? RENAME CONSTRAINT ?? TO ??', [table, from, to]);\n renamed = true;\n }\n }\n\n if ((await hasIndex(from)) && !(await hasIndex(to))) {\n await trx.raw('ALTER INDEX ?? RENAME TO ??', [from, to]);\n renamed = true;\n }\n\n return renamed;\n }\n\n getSqlType(type: string) {\n switch (type) {\n case 'timestamp': {\n return 'datetime';\n }\n default: {\n return type;\n }\n }\n }\n\n transformErrors(error: NodeJS.ErrnoException) {\n switch (error.code) {\n case '23502': {\n throw new errors.NotNullError({\n column: 'column' in error ? `${error.column}` : undefined,\n });\n }\n default: {\n super.transformErrors(error);\n }\n }\n }\n\n /**\n * Get column type conversion SQL with USING clause for PostgreSQL\n * @param currentType - The current PostgreSQL data type\n * @param targetType - The target Strapi type\n * @returns SQL string with USING clause or null if no special conversion needed\n */\n getColumnTypeConversionSQL(\n currentType: string,\n targetType: string\n ): {\n sql: string;\n typeClause: string;\n warning?: string;\n } | null {\n // Time to datetime conversion\n if (targetType === 'datetime' && currentType === 'time without time zone') {\n return {\n sql: `ALTER TABLE ?? ALTER COLUMN ?? TYPE timestamp(6) USING ('1970-01-01 ' || ??::text)::timestamp`,\n typeClause: 'timestamp(6)',\n warning:\n 'Time values will be converted to datetime with default date \"1970-01-01\". Original time values will be preserved.',\n };\n }\n\n // Datetime to time conversion\n if (targetType === 'time' && currentType === 'timestamp without time zone') {\n return {\n sql: `ALTER TABLE ?? ALTER COLUMN ?? TYPE time(3) USING ??::time`,\n typeClause: 'time(3)',\n warning: 'Datetime values will be converted to time only. Date information will be lost.',\n };\n }\n\n // No special conversion needed\n return null;\n }\n}\n"],"names":["PostgresDialect","Dialect","useReturning","initialize","nativeConnection","db","connection","client","driver","types","setTypeParser","builtins","DATE","v","JSONB","NUMERIC","parseFloat","schemaName","getSchemaName","raw","usesForeignKeys","canRenameSchemaObjects","renameSchemaObject","trx","table","from","to","hasConstraint","name","result","rows","length","hasIndex","renamed","getSqlType","type","transformErrors","error","code","errors","column","undefined","getColumnTypeConversionSQL","currentType","targetType","sql","typeClause","warning","schemaInspector","PostgresqlSchemaInspector"],"mappings":";;;;AAOe,MAAMA,eAAAA,SAAwBC,OAAAA,CAAAA;IAS3CC,YAAAA,GAAe;QACb,OAAO,IAAA;AACT,IAAA;IAEA,MAAMC,UAAAA,CAAWC,gBAAyB,EAAE;;AAE1C,QAAA,IAAI,CAACC,EAAE,CAACC,UAAU,CAACC,MAAM,CAACC,MAAM,CAACC,KAAK,CAACC,aAAa,CAClD,IAAI,CAACL,EAAE,CAACC,UAAU,CAACC,MAAM,CAACC,MAAM,CAACC,KAAK,CAACE,QAAQ,CAACC,IAAI,EACpD,MAAA,EACA,CAACC,CAAAA,GAAeA,CAAAA,CAAAA;;AAGlB,QAAA,IAAI,CAACR,EAAE,CAACC,UAAU,CAACC,MAAM,CAACC,MAA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H,KAAAA,GAAQ,CAAA,EAAGA,KAAAA,CAAMG,MAAM,EAAE,GAAGC;AAClD,qBAAA,CAAA;AACF,gBAAA;AACA,YAAA;AAAS,gBAAA;AACP,oBAAA,KAAK,CAACL,eAAAA,CAAgBC,KAAAA,CAAAA;AACxB,gBAAA;AACF;AACF,IAAA;AAEA;;;;;AAKC,MACDK,0BAAAA,CACEC,WAAmB,EACnBC,UAAkB,EAKX;;QAEP,IAAIA,UAAAA,KAAe,UAAA,IAAcD,WAAAA,KAAgB,wBAAA,EAA0B;YACzE,OAAO;gBACLE,GAAAA,EAAK,CAAC,6FAA6F,CAAC;gBACpGC,UAAAA,EAAY,cAAA;gBACZC,OAAAA,EACE;AACJ,aAAA;AACF,QAAA;;QAGA,IAAIH,UAAAA,KAAe,MAAA,IAAUD,WAAAA,KAAgB,6BAAA,EAA+B;YAC1E,OAAO;gBACLE,GAAAA,EAAK,CAAC,0DAA0D,CAAC;gBACjEC,UAAAA,EAAY,SAAA;gBACZC,OAAAA,EAAS;AACX,aAAA;AACF,QAAA;;QAGA,OAAO,IAAA;AACT,IAAA;AA7JA,IAAA,WAAA,CAAY1C,EAAY,CAAE;AACxB,QAAA,KAAK,CAACA,EAAAA,EAAI,UAAA,CAAA;AAEV,QAAA,IAAI,CAAC2C,eAAe,GAAG,IAAIC,yBAAAA,CAA0B5C,EAAAA,CAAAA;AACvD,IAAA;AA0JF;;;;"}
|
|
@@ -10,6 +10,15 @@ export default class SqliteDialect extends Dialect {
|
|
|
10
10
|
useReturning(): boolean;
|
|
11
11
|
initialize(nativeConnection: unknown): Promise<void>;
|
|
12
12
|
canAlterConstraints(): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* SQLite foreign keys are unnamed (declared inline on the table), so only
|
|
15
|
+
* indexes need dropping. Queries run on `trx`: SQLite pools hold a single
|
|
16
|
+
* connection, which the migration transaction already owns.
|
|
17
|
+
*/
|
|
18
|
+
dropSchemaObject(trx: Knex, { table, name }: {
|
|
19
|
+
table: string;
|
|
20
|
+
name: string;
|
|
21
|
+
}): Promise<boolean>;
|
|
13
22
|
getSqlType(type: string): string;
|
|
14
23
|
supportsOperator(operator: string): boolean;
|
|
15
24
|
startSchemaUpdate(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialects/sqlite/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAGjC,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,qBAAqB,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAOtC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,OAAO;IAChD,eAAe,EAAE,qBAAqB,CAAC;gBAE3B,EAAE,EAAE,QAAQ;IAMxB,kBAAkB,IAAI,MAAM;IAI5B,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,uBAAuB;IAY7C,YAAY;IAIN,UAAU,CAAC,gBAAgB,EAAE,OAAO;IAI1C,mBAAmB;IAInB,UAAU,CAAC,IAAI,EAAE,MAAM;IAkBvB,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAI3B,iBAAiB;IAIjB,eAAe;IAIrB,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,cAAc;IAW5C,gBAAgB;CAGjB"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialects/sqlite/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAGjC,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,qBAAqB,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAOtC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,OAAO;IAChD,eAAe,EAAE,qBAAqB,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