@zintrust/core 0.1.21 → 0.1.22
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/package.json +1 -1
- package/src/cli/commands/MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateCommand.js +1 -1
- package/src/cli/d1/D1SqlMigrations.d.ts.map +1 -1
- package/src/cli/d1/D1SqlMigrations.js +4 -3
- package/src/cli/scaffolding/ModelGenerator.d.ts +1 -1
- package/src/cli/scaffolding/ModelGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/ModelGenerator.js +10 -2
- package/src/config/broadcast.js +1 -1
- package/src/config/storage.js +4 -4
- package/src/config/type.d.ts +11 -0
- package/src/config/type.d.ts.map +1 -1
- package/src/config/type.js +10 -1
- package/src/index.d.ts.map +1 -1
- package/src/migrations/MigrationLoader.d.ts +1 -1
- package/src/migrations/MigrationLoader.d.ts.map +1 -1
- package/src/migrations/Migrator.d.ts +3 -3
- package/src/migrations/Migrator.d.ts.map +1 -1
- package/src/migrations/Migrator.js +1 -1
- package/src/migrations/MigratorFactory.d.ts +1 -1
- package/src/migrations/MigratorFactory.d.ts.map +1 -1
- package/src/migrations/MigratorFactory.js +3 -3
- package/src/migrations/enum/index.d.ts +93 -0
- package/src/migrations/enum/index.d.ts.map +1 -0
- package/src/migrations/enum/index.js +92 -0
- package/src/migrations/schema/Blueprint.d.ts +1 -1
- package/src/migrations/schema/Blueprint.d.ts.map +1 -1
- package/src/migrations/schema/Blueprint.js +27 -25
- package/src/migrations/schema/Schema.d.ts +1 -1
- package/src/migrations/schema/Schema.d.ts.map +1 -1
- package/src/migrations/schema/Schema.js +4 -3
- package/src/migrations/schema/SchemaCompiler.d.ts +1 -1
- package/src/migrations/schema/SchemaCompiler.d.ts.map +1 -1
- package/src/migrations/schema/SchemaCompiler.js +99 -91
- package/src/migrations/schema/index.d.ts +4 -4
- package/src/migrations/schema/index.d.ts.map +1 -1
- package/src/migrations/schema/index.js +3 -3
- package/src/migrations/schema/types.d.ts +2 -1
- package/src/migrations/schema/types.d.ts.map +1 -1
- package/src/orm/ConnectionManager.d.ts +6 -4
- package/src/orm/ConnectionManager.d.ts.map +1 -1
- package/src/orm/ConnectionManager.js +213 -75
- package/src/orm/Database.d.ts +2 -1
- package/src/orm/Database.d.ts.map +1 -1
- package/src/orm/DatabaseAdapter.d.ts +3 -2
- package/src/orm/DatabaseAdapter.d.ts.map +1 -1
- package/src/orm/DatabaseAdapter.js +17 -0
- package/src/orm/Model.d.ts.map +1 -1
- package/src/orm/Model.js +24 -2
- package/src/orm/adapters/D1Adapter.d.ts.map +1 -1
- package/src/orm/adapters/D1Adapter.js +2 -1
- package/src/orm/adapters/D1RemoteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/D1RemoteAdapter.js +2 -1
- package/src/orm/adapters/MySQLAdapter.d.ts.map +1 -1
- package/src/orm/adapters/MySQLAdapter.js +2 -1
- package/src/orm/adapters/SQLServerAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLServerAdapter.js +2 -1
- package/src/orm/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLiteAdapter.js +2 -1
- package/src/orm/migrations/MigrationStore.d.ts.map +1 -1
- package/src/performance/Optimizer.d.ts.map +1 -1
- package/src/performance/Optimizer.js +55 -14
- package/src/profiling/RequestProfiler.d.ts.map +1 -1
- package/src/profiling/RequestProfiler.js +3 -1
- package/src/runtime/StartupConfigFileRegistry.d.ts +14 -13
- package/src/runtime/StartupConfigFileRegistry.d.ts.map +1 -1
- package/src/runtime/StartupConfigFileRegistry.js +10 -11
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
2
|
+
import { ColumnType as ColumnTypeName, SchOther } from '../enum/index.js';
|
|
2
3
|
const IDENT_RE = /^[A-Za-z_]\w*$/;
|
|
3
4
|
function assertIdentifier(label, value) {
|
|
4
5
|
if (!IDENT_RE.test(value)) {
|
|
@@ -46,7 +47,7 @@ function createColumnBuilder(def) {
|
|
|
46
47
|
}
|
|
47
48
|
function createForeignKeyBuilder(columns, name) {
|
|
48
49
|
for (const c of columns)
|
|
49
|
-
assertIdentifier(
|
|
50
|
+
assertIdentifier(SchOther.COLUMN, c);
|
|
50
51
|
const fk = {
|
|
51
52
|
name: name ?? `fk_${columns.join('_')}`,
|
|
52
53
|
columns,
|
|
@@ -97,7 +98,7 @@ function createState(tableName) {
|
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
100
|
function addColumn(state, name, type, length) {
|
|
100
|
-
assertIdentifier(
|
|
101
|
+
assertIdentifier(SchOther.COLUMN, name);
|
|
101
102
|
const def = {
|
|
102
103
|
name,
|
|
103
104
|
type,
|
|
@@ -125,35 +126,36 @@ function buildDefinition(state) {
|
|
|
125
126
|
}
|
|
126
127
|
function createBlueprintApi(state) {
|
|
127
128
|
const api = {
|
|
128
|
-
string: (name, length = 255) => addColumn(state, name,
|
|
129
|
-
integer: (name) => addColumn(state, name,
|
|
130
|
-
bigInteger: (name) => addColumn(state, name,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
api.timestamp(
|
|
129
|
+
string: (name, length = 255) => addColumn(state, name, ColumnTypeName.STRING, length),
|
|
130
|
+
integer: (name) => addColumn(state, name, ColumnTypeName.INTEGER),
|
|
131
|
+
bigInteger: (name) => addColumn(state, name, ColumnTypeName.BIGINT).unsigned(),
|
|
132
|
+
uuid: (name) => addColumn(state, name, ColumnTypeName.UUID),
|
|
133
|
+
real: (name) => addColumn(state, name, ColumnTypeName.REAL),
|
|
134
|
+
boolean: (name) => addColumn(state, name, ColumnTypeName.BOOLEAN),
|
|
135
|
+
text: (name) => addColumn(state, name, ColumnTypeName.TEXT),
|
|
136
|
+
json: (name) => addColumn(state, name, ColumnTypeName.JSON),
|
|
137
|
+
timestamp: (name) => addColumn(state, name, ColumnTypeName.TIMESTAMP),
|
|
138
|
+
blob: (name) => addColumn(state, name, ColumnTypeName.BLOB),
|
|
139
|
+
id: (name = SchOther.ID) => addColumn(state, name, ColumnTypeName.INTEGER).primary().autoIncrement(),
|
|
140
|
+
timestamps: (createdAt = SchOther.CREATED_AT, updatedAt = SchOther.UPDATED_AT) => {
|
|
141
|
+
api.timestamp(createdAt).notNullable().default(ColumnTypeName.CURRENT_TIMESTAMP);
|
|
142
|
+
api.timestamp(updatedAt).notNullable().default(ColumnTypeName.CURRENT_TIMESTAMP);
|
|
141
143
|
},
|
|
142
144
|
index: (cols, name) => {
|
|
143
145
|
const arr = Array.isArray(cols) ? cols : [cols];
|
|
144
146
|
for (const c of arr)
|
|
145
|
-
assertIdentifier(
|
|
147
|
+
assertIdentifier(SchOther.COLUMN, c);
|
|
146
148
|
const indexName = name ?? `idx_${state.tableName}_${arr.join('_')}`;
|
|
147
|
-
assertIdentifier(
|
|
148
|
-
state.indexes.push({ name: indexName, columns: arr, type:
|
|
149
|
+
assertIdentifier(SchOther.INDEX, indexName);
|
|
150
|
+
state.indexes.push({ name: indexName, columns: arr, type: ColumnTypeName.INDEX });
|
|
149
151
|
},
|
|
150
152
|
unique: (cols, name) => {
|
|
151
153
|
const arr = Array.isArray(cols) ? cols : [cols];
|
|
152
154
|
for (const c of arr)
|
|
153
|
-
assertIdentifier(
|
|
155
|
+
assertIdentifier(SchOther.COLUMN, c);
|
|
154
156
|
const indexName = name ?? `uniq_${state.tableName}_${arr.join('_')}`;
|
|
155
|
-
assertIdentifier(
|
|
156
|
-
state.indexes.push({ name: indexName, columns: arr, type:
|
|
157
|
+
assertIdentifier(SchOther.INDEX, indexName);
|
|
158
|
+
state.indexes.push({ name: indexName, columns: arr, type: ColumnTypeName.UNIQUE });
|
|
157
159
|
},
|
|
158
160
|
foreign: (cols, name) => {
|
|
159
161
|
const arr = Array.isArray(cols) ? cols : [cols];
|
|
@@ -162,15 +164,15 @@ function createBlueprintApi(state) {
|
|
|
162
164
|
return builder;
|
|
163
165
|
},
|
|
164
166
|
dropColumn: (name) => {
|
|
165
|
-
assertIdentifier(
|
|
167
|
+
assertIdentifier(SchOther.COLUMN, name);
|
|
166
168
|
state.dropColumns.push(name);
|
|
167
169
|
},
|
|
168
170
|
dropIndex: (name) => {
|
|
169
|
-
assertIdentifier(
|
|
171
|
+
assertIdentifier(SchOther.INDEX, name);
|
|
170
172
|
state.dropIndexes.push(name);
|
|
171
173
|
},
|
|
172
174
|
dropForeign: (name) => {
|
|
173
|
-
assertIdentifier(
|
|
175
|
+
assertIdentifier(SchOther.FOREIGN_KEY, name);
|
|
174
176
|
state.dropForeignKeys.push(name);
|
|
175
177
|
},
|
|
176
178
|
getDefinition: () => buildDefinition(state),
|
|
@@ -182,7 +184,7 @@ function createBlueprintApi(state) {
|
|
|
182
184
|
}
|
|
183
185
|
export const MigrationBlueprint = Object.freeze({
|
|
184
186
|
create(tableName) {
|
|
185
|
-
assertIdentifier(
|
|
187
|
+
assertIdentifier(SchOther.TABLE, tableName);
|
|
186
188
|
const state = createState(tableName);
|
|
187
189
|
return createBlueprintApi(state);
|
|
188
190
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IDatabase } from '../../orm/Database';
|
|
2
|
-
import type { SchemaBuilder } from '
|
|
2
|
+
import type { SchemaBuilder } from '../schema/types';
|
|
3
3
|
declare function createSchemaBuilder(db: IDatabase): SchemaBuilder;
|
|
4
4
|
export declare const Schema: Readonly<{
|
|
5
5
|
create: typeof createSchemaBuilder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../../../src/migrations/schema/Schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../../../src/migrations/schema/Schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAM/C,OAAO,KAAK,EAAgC,aAAa,EAAE,MAAM,0BAA0B,CAAC;AA6M5F,iBAAS,mBAAmB,CAAC,EAAE,EAAE,SAAS,GAAG,aAAa,CAWzD;AAED,eAAO,MAAM,MAAM;;EAEjB,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
2
2
|
import { BaseAdapter } from '../../orm/DatabaseAdapter.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { isSqliteFamily } from '../enum/index.js';
|
|
4
|
+
import { MigrationBlueprint } from '../schema/Blueprint.js';
|
|
5
|
+
import { MigrationSchemaCompiler } from '../schema/SchemaCompiler.js';
|
|
5
6
|
const IDENT_RE = /^[A-Za-z_]\w*$/;
|
|
6
7
|
function assertIdentifier(label, value) {
|
|
7
8
|
if (!IDENT_RE.test(value)) {
|
|
@@ -66,7 +67,7 @@ async function schemaDrop(db, tableName, ifExists) {
|
|
|
66
67
|
}
|
|
67
68
|
async function schemaHasTable(db, tableName) {
|
|
68
69
|
const t = db.getType();
|
|
69
|
-
if (t
|
|
70
|
+
if (isSqliteFamily(t)) {
|
|
70
71
|
return queryExists(db, "SELECT 1 FROM sqlite_master WHERE type='table' AND name=? LIMIT 1", [
|
|
71
72
|
tableName,
|
|
72
73
|
]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ColumnDefinition, ForeignKeyDefinition, IndexDefinition, TableDefinition } from '
|
|
1
|
+
import type { ColumnDefinition, ForeignKeyDefinition, IndexDefinition, TableDefinition } from '../schema/types';
|
|
2
2
|
type AlterTablePlan = {
|
|
3
3
|
addColumns: ColumnDefinition[];
|
|
4
4
|
dropColumns: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaCompiler.d.ts","sourceRoot":"","sources":["../../../../src/migrations/schema/SchemaCompiler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SchemaCompiler.d.ts","sourceRoot":"","sources":["../../../../src/migrations/schema/SchemaCompiler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAEhB,oBAAoB,EACpB,eAAe,EACf,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAIlC,KAAK,cAAc,GAAG;IACpB,UAAU,EAAE,gBAAgB,EAAE,CAAC;IAC/B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,EAAE,eAAe,EAAE,CAAC;IACjC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE,oBAAoB,EAAE,CAAC;IACvC,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC;AA8UF,eAAO,MAAM,uBAAuB;+BAExB,MAAM,OACT,eAAe,SACb;QAAE,WAAW,CAAC,EAAE,OAAO,CAAA;KAAE,GAC/B,MAAM,EAAE;6BAKc,MAAM,SAAS,MAAM,SAAS;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM;8BAK5D,MAAM,SAAS,MAAM,QAAQ,cAAc,GAAG,MAAM,EAAE;EAIhF,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
2
|
+
import { AdaptersEnum, ColumnType, isSqliteFamily, SchOther } from '../enum/index.js';
|
|
2
3
|
const IDENT_RE = /^[A-Za-z_]\w*$/;
|
|
3
4
|
function isSupportedDriver(driver) {
|
|
4
|
-
return (driver ===
|
|
5
|
-
driver ===
|
|
6
|
-
driver ===
|
|
7
|
-
driver ===
|
|
8
|
-
driver ===
|
|
9
|
-
driver ===
|
|
5
|
+
return (driver === AdaptersEnum.sqlite ||
|
|
6
|
+
driver === AdaptersEnum.d1 ||
|
|
7
|
+
driver === AdaptersEnum.d1Remote ||
|
|
8
|
+
driver === AdaptersEnum.postgresql ||
|
|
9
|
+
driver === AdaptersEnum.mysql ||
|
|
10
|
+
driver === AdaptersEnum.sqlserver);
|
|
10
11
|
}
|
|
11
12
|
function assertIdentifier(label, value) {
|
|
12
13
|
if (!IDENT_RE.test(value)) {
|
|
@@ -20,21 +21,18 @@ function requireSupportedDriver(driver) {
|
|
|
20
21
|
return driver;
|
|
21
22
|
}
|
|
22
23
|
function quoteIdent(driver, ident) {
|
|
23
|
-
assertIdentifier(
|
|
24
|
-
if (driver ===
|
|
24
|
+
assertIdentifier(ColumnType.SQL, ident);
|
|
25
|
+
if (driver === AdaptersEnum.mysql)
|
|
25
26
|
return `\`${ident}\``;
|
|
26
27
|
return `"${ident}"`;
|
|
27
28
|
}
|
|
28
|
-
function isSqliteFamily(driver) {
|
|
29
|
-
return driver === 'sqlite' || driver === 'd1' || driver === 'd1-remote';
|
|
30
|
-
}
|
|
31
29
|
function normalizeForeignKeyAction(action) {
|
|
32
30
|
switch (action) {
|
|
33
|
-
case
|
|
34
|
-
case
|
|
35
|
-
case
|
|
36
|
-
case
|
|
37
|
-
case
|
|
31
|
+
case ColumnType.CASCADE:
|
|
32
|
+
case ColumnType.SETNULL:
|
|
33
|
+
case ColumnType.RESTRICT:
|
|
34
|
+
case ColumnType.NOACTION:
|
|
35
|
+
case ColumnType.SETDEFAULT:
|
|
38
36
|
return action;
|
|
39
37
|
default:
|
|
40
38
|
throw ErrorFactory.createValidationError(`Unsupported foreign key action: ${String(action)}`);
|
|
@@ -42,45 +40,53 @@ function normalizeForeignKeyAction(action) {
|
|
|
42
40
|
}
|
|
43
41
|
const TYPE_SQL = Object.freeze({
|
|
44
42
|
STRING: (driver, def) => {
|
|
45
|
-
const len = typeof def.length ===
|
|
46
|
-
return isSqliteFamily(driver) ?
|
|
43
|
+
const len = typeof def.length === SchOther.NUMBER && Number.isFinite(def.length) ? def.length : 255;
|
|
44
|
+
return isSqliteFamily(driver) ? ColumnType.TEXT : `${ColumnType.VARCHAR}(${len})`;
|
|
45
|
+
},
|
|
46
|
+
INTEGER: (driver) => (driver === AdaptersEnum.mysql ? ColumnType.INT : ColumnType.INTEGER),
|
|
47
|
+
BIGINT: () => ColumnType.BIGINT,
|
|
48
|
+
UUID: (driver) => {
|
|
49
|
+
if (driver === AdaptersEnum.postgresql)
|
|
50
|
+
return ColumnType.UUID;
|
|
51
|
+
return isSqliteFamily(driver) ? ColumnType.TEXT : `${ColumnType.VARCHAR}(36)`;
|
|
47
52
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
TEXT: () => 'TEXT',
|
|
53
|
+
REAL: (driver) => (driver === AdaptersEnum.sqlserver ? ColumnType.FLOAT : ColumnType.REAL),
|
|
54
|
+
BOOLEAN: (driver) => (driver === AdaptersEnum.mysql ? ColumnType.TINYINT_1 : ColumnType.BOOLEAN),
|
|
55
|
+
TEXT: () => ColumnType.TEXT,
|
|
52
56
|
JSON: (driver) => {
|
|
53
|
-
if (driver ===
|
|
54
|
-
return
|
|
55
|
-
if (driver ===
|
|
56
|
-
return
|
|
57
|
-
return
|
|
57
|
+
if (driver === AdaptersEnum.postgresql)
|
|
58
|
+
return ColumnType.JSONB;
|
|
59
|
+
if (driver === AdaptersEnum.mysql)
|
|
60
|
+
return ColumnType.JSON;
|
|
61
|
+
return ColumnType.TEXT;
|
|
58
62
|
},
|
|
59
63
|
TIMESTAMP: (driver) => {
|
|
60
|
-
if (driver ===
|
|
61
|
-
return
|
|
62
|
-
if (driver ===
|
|
63
|
-
return
|
|
64
|
-
return
|
|
64
|
+
if (driver === AdaptersEnum.mysql)
|
|
65
|
+
return ColumnType.DATETIME;
|
|
66
|
+
if (driver === AdaptersEnum.postgresql)
|
|
67
|
+
return ColumnType.TIMESTAMP;
|
|
68
|
+
return ColumnType.TEXT;
|
|
65
69
|
},
|
|
66
|
-
BLOB: () =>
|
|
70
|
+
BLOB: (driver) => (driver === AdaptersEnum.postgresql ? ColumnType.BYTEA : ColumnType.BLOB),
|
|
67
71
|
});
|
|
68
72
|
function getColumnTypeSql(driver, def) {
|
|
69
73
|
return TYPE_SQL[def.type](driver, def);
|
|
70
74
|
}
|
|
71
|
-
function getAutoIncrementColumnSql(driver, colName) {
|
|
75
|
+
function getAutoIncrementColumnSql(driver, colName, type) {
|
|
72
76
|
const sqliteFamily = isSqliteFamily(driver);
|
|
73
77
|
if (sqliteFamily) {
|
|
74
|
-
return `${colName} INTEGER
|
|
78
|
+
return `${colName} ${ColumnType.INTEGER} ${ColumnType.PRIMARY_KEY} ${ColumnType.AUTOINCREMENT}`;
|
|
75
79
|
}
|
|
76
|
-
if (driver ===
|
|
77
|
-
return `${colName} SERIAL
|
|
80
|
+
if (driver === AdaptersEnum.postgresql) {
|
|
81
|
+
return `${colName} ${type === ColumnType.BIGINT ? ColumnType.BIGSERIAL : ColumnType.SERIAL} ${ColumnType.PRIMARY_KEY}`;
|
|
78
82
|
}
|
|
79
|
-
if (driver ===
|
|
80
|
-
|
|
83
|
+
if (driver === AdaptersEnum.mysql) {
|
|
84
|
+
const typeSql = type === ColumnType.BIGINT ? ColumnType.BIGINT : ColumnType.INT;
|
|
85
|
+
return `${colName} ${typeSql} ${ColumnType.AUTO_INCREMENT} ${ColumnType.PRIMARY_KEY}`;
|
|
81
86
|
}
|
|
82
|
-
if (driver ===
|
|
83
|
-
|
|
87
|
+
if (driver === AdaptersEnum.sqlserver) {
|
|
88
|
+
const typeSql = type === ColumnType.BIGINT ? ColumnType.BIGINT : ColumnType.INT;
|
|
89
|
+
return `${colName} ${typeSql} ${ColumnType.IDENTITY_1_1} ${ColumnType.PRIMARY_KEY}`;
|
|
84
90
|
}
|
|
85
91
|
throw ErrorFactory.createValidationError(`Auto-increment not supported for driver: ${driver}`);
|
|
86
92
|
}
|
|
@@ -89,41 +95,43 @@ function formatDefaultValueSql(table, def) {
|
|
|
89
95
|
return null;
|
|
90
96
|
const dv = def.defaultValue;
|
|
91
97
|
if (dv === null)
|
|
92
|
-
return
|
|
98
|
+
return ColumnType.DEFAULT_NULL;
|
|
93
99
|
if (typeof dv === 'number' && Number.isFinite(dv))
|
|
94
100
|
return `DEFAULT ${dv}`;
|
|
95
101
|
if (typeof dv === 'boolean')
|
|
96
102
|
return `DEFAULT ${dv ? 1 : 0}`;
|
|
97
103
|
if (typeof dv === 'string') {
|
|
98
|
-
if (dv ===
|
|
99
|
-
return
|
|
104
|
+
if (dv === ColumnType.CURRENT_TIMESTAMP)
|
|
105
|
+
return `DEFAULT ${ColumnType.CURRENT_TIMESTAMP}`;
|
|
100
106
|
const escaped = dv.replaceAll("'", "''");
|
|
101
107
|
return `DEFAULT '${escaped}'`;
|
|
102
108
|
}
|
|
103
109
|
throw ErrorFactory.createValidationError(`Unsupported default type for ${table}.${def.name}`);
|
|
104
110
|
}
|
|
105
111
|
function buildColumnSql(driver, table, def) {
|
|
106
|
-
assertIdentifier(
|
|
107
|
-
assertIdentifier(
|
|
112
|
+
assertIdentifier(SchOther.TABLE, table);
|
|
113
|
+
assertIdentifier(SchOther.COLUMN, def.name);
|
|
108
114
|
const col = quoteIdent(driver, def.name);
|
|
109
115
|
if (def.autoIncrement === true) {
|
|
110
|
-
if (def.type !==
|
|
111
|
-
throw ErrorFactory.createValidationError(`Auto-increment column must be INTEGER: ${table}.${def.name}`);
|
|
116
|
+
if (def.type !== ColumnType.INTEGER && def.type !== ColumnType.BIGINT) {
|
|
117
|
+
throw ErrorFactory.createValidationError(`Auto-increment column must be INTEGER or BIGINT: ${table}.${def.name}`);
|
|
112
118
|
}
|
|
113
|
-
return getAutoIncrementColumnSql(driver, col);
|
|
119
|
+
return getAutoIncrementColumnSql(driver, col, def.type);
|
|
114
120
|
}
|
|
115
121
|
const parts = [`${col} ${getColumnTypeSql(driver, def)}`];
|
|
116
|
-
if (driver ===
|
|
122
|
+
if (driver === AdaptersEnum.mysql &&
|
|
117
123
|
def.unsigned === true &&
|
|
118
|
-
(def.type ===
|
|
119
|
-
|
|
124
|
+
(def.type === ColumnType.INTEGER ||
|
|
125
|
+
def.type === ColumnType.BIGINT ||
|
|
126
|
+
def.type === ColumnType.REAL)) {
|
|
127
|
+
parts.push(ColumnType.UNSIGNED);
|
|
120
128
|
}
|
|
121
129
|
if (def.nullable !== true)
|
|
122
|
-
parts.push(
|
|
130
|
+
parts.push(ColumnType.NOT_NULL);
|
|
123
131
|
if (def.unique === true)
|
|
124
|
-
parts.push(
|
|
132
|
+
parts.push(ColumnType.UNIQUE);
|
|
125
133
|
if (def.primary === true)
|
|
126
|
-
parts.push(
|
|
134
|
+
parts.push(ColumnType.PRIMARY_KEY);
|
|
127
135
|
const defaultSql = formatDefaultValueSql(table, def);
|
|
128
136
|
if (defaultSql !== null)
|
|
129
137
|
parts.push(defaultSql);
|
|
@@ -131,55 +139,55 @@ function buildColumnSql(driver, table, def) {
|
|
|
131
139
|
}
|
|
132
140
|
function buildPrimaryKeyConstraintSql(driver, columns) {
|
|
133
141
|
const cols = columns.map((c) => {
|
|
134
|
-
assertIdentifier(
|
|
142
|
+
assertIdentifier(SchOther.COLUMN, c);
|
|
135
143
|
return quoteIdent(driver, c);
|
|
136
144
|
});
|
|
137
|
-
return
|
|
145
|
+
return `${ColumnType.PRIMARY_KEY} (${cols.join(', ')})`;
|
|
138
146
|
}
|
|
139
147
|
function buildForeignKeyConstraintSql(driver, table, fk) {
|
|
140
|
-
assertIdentifier(
|
|
141
|
-
assertIdentifier(
|
|
142
|
-
assertIdentifier(
|
|
148
|
+
assertIdentifier(SchOther.TABLE, table);
|
|
149
|
+
assertIdentifier(SchOther.FOREIGN_KEY, fk.name);
|
|
150
|
+
assertIdentifier(SchOther.REFERENCED_TABLE, fk.referencedTable);
|
|
143
151
|
for (const c of fk.columns)
|
|
144
|
-
assertIdentifier(
|
|
152
|
+
assertIdentifier(SchOther.COLUMN, c);
|
|
145
153
|
for (const c of fk.referencedColumns)
|
|
146
|
-
assertIdentifier(
|
|
147
|
-
const constraint =
|
|
154
|
+
assertIdentifier(SchOther.REFERENCED_COLUMN, c);
|
|
155
|
+
const constraint = `${ColumnType.CONSTRAINT} ${quoteIdent(driver, fk.name)}`;
|
|
148
156
|
const localCols = fk.columns.map((c) => quoteIdent(driver, c)).join(', ');
|
|
149
157
|
const refCols = fk.referencedColumns.map((c) => quoteIdent(driver, c)).join(', ');
|
|
150
158
|
const parts = [
|
|
151
|
-
`${constraint}
|
|
159
|
+
`${constraint} ${ColumnType.FOREIGN_KEY_S} (${localCols}) ${ColumnType.REFERENCES} ${quoteIdent(driver, fk.referencedTable)} (${refCols})`,
|
|
152
160
|
];
|
|
153
161
|
if (fk.onDelete)
|
|
154
|
-
parts.push(
|
|
162
|
+
parts.push(`${ColumnType.ON_DELETE} ${normalizeForeignKeyAction(fk.onDelete)}`);
|
|
155
163
|
if (fk.onUpdate)
|
|
156
|
-
parts.push(
|
|
164
|
+
parts.push(`${ColumnType.ON_UPDATE} ${normalizeForeignKeyAction(fk.onUpdate)}`);
|
|
157
165
|
return parts.join(' ');
|
|
158
166
|
}
|
|
159
167
|
function buildCreateIndexSql(driver, table, idx) {
|
|
160
|
-
assertIdentifier(
|
|
161
|
-
assertIdentifier(
|
|
168
|
+
assertIdentifier(SchOther.TABLE, table);
|
|
169
|
+
assertIdentifier(SchOther.INDEX, idx.name);
|
|
162
170
|
for (const c of idx.columns)
|
|
163
|
-
assertIdentifier(
|
|
164
|
-
const unique = idx.type ===
|
|
171
|
+
assertIdentifier(SchOther.COLUMN, c);
|
|
172
|
+
const unique = idx.type === ColumnType.UNIQUE ? `${ColumnType.UNIQUE} ` : '';
|
|
165
173
|
const cols = idx.columns.map((c) => quoteIdent(driver, c)).join(', ');
|
|
166
|
-
return
|
|
174
|
+
return `${ColumnType.CREATE_INDEX_S} ${unique}${ColumnType.INDEX} ${quoteIdent(driver, idx.name)} ${ColumnType.ON} ${quoteIdent(driver, table)} (${cols})`;
|
|
167
175
|
}
|
|
168
176
|
function buildDropIndexSql(driver, table, indexName) {
|
|
169
|
-
assertIdentifier(
|
|
170
|
-
assertIdentifier(
|
|
171
|
-
if (driver ===
|
|
172
|
-
return
|
|
177
|
+
assertIdentifier(SchOther.TABLE, table);
|
|
178
|
+
assertIdentifier(SchOther.INDEX, indexName);
|
|
179
|
+
if (driver === AdaptersEnum.mysql) {
|
|
180
|
+
return `${ColumnType.DROP_INDEX_S} ${quoteIdent(driver, indexName)} ${ColumnType.ON} ${quoteIdent(driver, table)}`;
|
|
173
181
|
}
|
|
174
|
-
return
|
|
182
|
+
return `${ColumnType.DROP_INDEX_S} ${ColumnType.IF_EXISTS} ${quoteIdent(driver, indexName)}`;
|
|
175
183
|
}
|
|
176
184
|
function buildDropTableSql(driver, table, ifExists) {
|
|
177
|
-
assertIdentifier(
|
|
178
|
-
const ine = ifExists ?
|
|
179
|
-
return
|
|
185
|
+
assertIdentifier(SchOther.TABLE, table);
|
|
186
|
+
const ine = ifExists ? `${ColumnType.IF_EXISTS} ` : '';
|
|
187
|
+
return `${ColumnType.DROP_TABLE_S} ${ine}${quoteIdent(driver, table)}`;
|
|
180
188
|
}
|
|
181
189
|
function buildCreateTableStatements(driver, def, ifNotExists) {
|
|
182
|
-
assertIdentifier(
|
|
190
|
+
assertIdentifier(SchOther.TABLE, def.name);
|
|
183
191
|
if (def.columns.length === 0) {
|
|
184
192
|
throw ErrorFactory.createValidationError(`Schema for table '${def.name}' has no columns`);
|
|
185
193
|
}
|
|
@@ -192,8 +200,8 @@ function buildCreateTableStatements(driver, def, ifNotExists) {
|
|
|
192
200
|
constraints.push(buildForeignKeyConstraintSql(driver, def.name, fk));
|
|
193
201
|
}
|
|
194
202
|
const allLines = [...colLines, ...constraints].map((l) => ` ${l}`);
|
|
195
|
-
const ine = ifNotExists ?
|
|
196
|
-
const createSql =
|
|
203
|
+
const ine = ifNotExists ? `${ColumnType.IF_NOT_EXISTS} ` : '';
|
|
204
|
+
const createSql = `${ColumnType.CREATE_TABLE_S} ${ine}${quoteIdent(driver, def.name)} (\n${allLines.join(',\n')}\n)`;
|
|
197
205
|
const statements = [createSql];
|
|
198
206
|
for (const idx of def.indexes) {
|
|
199
207
|
statements.push(buildCreateIndexSql(driver, def.name, idx));
|
|
@@ -203,7 +211,7 @@ function buildCreateTableStatements(driver, def, ifNotExists) {
|
|
|
203
211
|
function compileAddColumns(driver, table, cols) {
|
|
204
212
|
return cols.map((col) => {
|
|
205
213
|
const colSql = buildColumnSql(driver, table, col);
|
|
206
|
-
return
|
|
214
|
+
return `${ColumnType.ALTER_TABLE_S} ${quoteIdent(driver, table)} ${ColumnType.ADD_COLUMN_S} ${colSql}`;
|
|
207
215
|
});
|
|
208
216
|
}
|
|
209
217
|
function compileIndexOps(driver, table, plan) {
|
|
@@ -222,24 +230,24 @@ function compileAdvancedAlterOps(driver, table, plan) {
|
|
|
222
230
|
}
|
|
223
231
|
const statements = [];
|
|
224
232
|
for (const col of plan.dropColumns) {
|
|
225
|
-
assertIdentifier(
|
|
226
|
-
statements.push(
|
|
233
|
+
assertIdentifier(SchOther.COLUMN, col);
|
|
234
|
+
statements.push(`${ColumnType.ALTER_TABLE_S} ${quoteIdent(driver, table)} ${ColumnType.DROP_COLUMN_S} ${quoteIdent(driver, col)}`);
|
|
227
235
|
}
|
|
228
236
|
for (const fk of plan.addForeignKeys) {
|
|
229
|
-
statements.push(
|
|
237
|
+
statements.push(`${ColumnType.ALTER_TABLE_S} ${quoteIdent(driver, table)} ${ColumnType.ADD} ${buildForeignKeyConstraintSql(driver, table, fk)}`);
|
|
230
238
|
}
|
|
231
239
|
for (const fkName of plan.dropForeignKeys) {
|
|
232
|
-
assertIdentifier(
|
|
233
|
-
if (driver ===
|
|
234
|
-
statements.push(
|
|
240
|
+
assertIdentifier(SchOther.FOREIGN_KEY, fkName);
|
|
241
|
+
if (driver === AdaptersEnum.mysql) {
|
|
242
|
+
statements.push(`${ColumnType.ALTER_TABLE_S} ${quoteIdent(driver, table)} ${ColumnType.DROP} ${ColumnType.FOREIGN_KEY_S} ${quoteIdent(driver, fkName)}`);
|
|
235
243
|
continue;
|
|
236
244
|
}
|
|
237
|
-
statements.push(
|
|
245
|
+
statements.push(`${ColumnType.ALTER_TABLE_S} ${quoteIdent(driver, table)} ${ColumnType.DROP} ${ColumnType.CONSTRAINT} ${quoteIdent(driver, fkName)}`);
|
|
238
246
|
}
|
|
239
247
|
return statements;
|
|
240
248
|
}
|
|
241
249
|
function buildAlterTableStatements(driver, table, plan) {
|
|
242
|
-
assertIdentifier(
|
|
250
|
+
assertIdentifier(SchOther.TABLE, table);
|
|
243
251
|
return [
|
|
244
252
|
...compileAddColumns(driver, table, plan.addColumns),
|
|
245
253
|
...compileIndexOps(driver, table, plan),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { MigrationBlueprint } from '
|
|
2
|
-
export { Schema } from '
|
|
3
|
-
export { MigrationSchemaCompiler } from '
|
|
4
|
-
export type { Blueprint, BlueprintCallback, ColumnBuilder, ColumnDefinition, ColumnType, ForeignKeyAction, ForeignKeyBuilder, ForeignKeyDefinition, IndexDefinition, IndexType, SchemaBuilder, TableDefinition, } from '
|
|
1
|
+
export { MigrationBlueprint } from '../schema/Blueprint';
|
|
2
|
+
export { Schema } from '../schema/Schema';
|
|
3
|
+
export { MigrationSchemaCompiler } from '../schema/SchemaCompiler';
|
|
4
|
+
export type { Blueprint, BlueprintCallback, ColumnBuilder, ColumnDefinition, ColumnType, ForeignKeyAction, ForeignKeyBuilder, ForeignKeyDefinition, IndexDefinition, IndexType, SchemaBuilder, TableDefinition, } from '../schema/types';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/migrations/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/migrations/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,SAAS,EACT,aAAa,EACb,eAAe,GAChB,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { MigrationBlueprint } from '
|
|
2
|
-
export { Schema } from '
|
|
3
|
-
export { MigrationSchemaCompiler } from '
|
|
1
|
+
export { MigrationBlueprint } from '../schema/Blueprint.js';
|
|
2
|
+
export { Schema } from '../schema/Schema.js';
|
|
3
|
+
export { MigrationSchemaCompiler } from '../schema/SchemaCompiler.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IDatabase } from '../../orm/Database';
|
|
2
|
-
export type ColumnType = 'STRING' | 'INTEGER' | 'REAL' | 'BOOLEAN' | 'TEXT' | 'JSON' | 'TIMESTAMP' | 'BLOB';
|
|
2
|
+
export type ColumnType = 'STRING' | 'INTEGER' | 'BIGINT' | 'UUID' | 'REAL' | 'BOOLEAN' | 'TEXT' | 'JSON' | 'TIMESTAMP' | 'BLOB';
|
|
3
3
|
export type IndexType = 'INDEX' | 'UNIQUE';
|
|
4
4
|
export type ForeignKeyAction = 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION' | 'SET DEFAULT';
|
|
5
5
|
export type ColumnDefinition = {
|
|
@@ -51,6 +51,7 @@ export type ForeignKeyBuilder = {
|
|
|
51
51
|
getDefinition(): ForeignKeyDefinition;
|
|
52
52
|
};
|
|
53
53
|
export type Blueprint = {
|
|
54
|
+
uuid(arg0: string): unknown;
|
|
54
55
|
string(name: string, length?: number): ColumnBuilder;
|
|
55
56
|
integer(name: string): ColumnBuilder;
|
|
56
57
|
bigInteger(name: string): ColumnBuilder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEhC,aAAa,IAAI,eAAe,CAAC;IACjC,cAAc,IAAI,MAAM,EAAE,CAAC;IAC3B,cAAc,IAAI,MAAM,EAAE,CAAC;IAC3B,kBAAkB,IAAI,MAAM,EAAE,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjF,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChF,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9C,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnE,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAClC,KAAK,IAAI,SAAS,CAAC;CACpB,CAAC"}
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* Handles database connections across different runtime environments
|
|
4
4
|
* Supports: PostgreSQL, MySQL, SQL Server with connection pooling for Lambda
|
|
5
5
|
*/
|
|
6
|
+
import type { SupportedDriver } from '../migrations/enum';
|
|
7
|
+
import type { IDatabaseAdapter } from './DatabaseAdapter';
|
|
6
8
|
export interface ConnectionConfig {
|
|
7
|
-
adapter:
|
|
9
|
+
adapter: SupportedDriver;
|
|
8
10
|
host?: string;
|
|
9
11
|
port?: number;
|
|
10
12
|
database: string;
|
|
@@ -31,7 +33,7 @@ export interface ConnectionPool {
|
|
|
31
33
|
queued: number;
|
|
32
34
|
}
|
|
33
35
|
interface ConnectionManagerInstance {
|
|
34
|
-
getConnection(id?: string): Promise<
|
|
36
|
+
getConnection(id?: string): Promise<IDatabaseAdapter>;
|
|
35
37
|
releaseConnection(connectionId?: string): Promise<void>;
|
|
36
38
|
closeAll(): Promise<void>;
|
|
37
39
|
getPoolStats(): ConnectionPool;
|
|
@@ -58,7 +60,7 @@ export declare const ConnectionManager: Readonly<{
|
|
|
58
60
|
/**
|
|
59
61
|
* Get or create database connection
|
|
60
62
|
*/
|
|
61
|
-
getConnection(id?: string): Promise<
|
|
63
|
+
getConnection(id?: string): Promise<IDatabaseAdapter>;
|
|
62
64
|
/**
|
|
63
65
|
* Release connection back to pool (but keep persistent)
|
|
64
66
|
*/
|
|
@@ -97,7 +99,7 @@ export interface AuroraQueryResult {
|
|
|
97
99
|
/**
|
|
98
100
|
* Get database credentials from AWS Secrets Manager
|
|
99
101
|
*/
|
|
100
|
-
export declare function getDatabaseSecret(
|
|
102
|
+
export declare function getDatabaseSecret(secretName: string): Promise<DatabaseSecret>;
|
|
101
103
|
/**
|
|
102
104
|
* Get database credentials from environment variables
|
|
103
105
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionManager.d.ts","sourceRoot":"","sources":["../../../src/orm/ConnectionManager.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAKH,MAAM,
|
|
1
|
+
{"version":3,"file":"ConnectionManager.d.ts","sourceRoot":"","sources":["../../../src/orm/ConnectionManager.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAOxD,OAAO,KAAK,EAAkB,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7E,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,eAAe,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAA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