sqlmorpheus 1.0.0 → 1.0.1
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/LICENSE +21 -0
- package/dist/index.cjs +1622 -0
- package/dist/index.d.cts +401 -0
- package/dist/index.d.mts +313 -292
- package/dist/index.mjs +1529 -1638
- package/package.json +25 -15
- package/dist/index.d.ts +0 -380
- package/dist/index.js +0 -1744
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sqlmorpheus",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"author": "JodliDev",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,34 +13,44 @@
|
|
|
13
13
|
"url": "https://github.com/JodliDev/SqlMorpheus/issues"
|
|
14
14
|
},
|
|
15
15
|
"homepage": "https://github.com/JodliDev/SqlMorpheus#readme",
|
|
16
|
+
"type": "module",
|
|
16
17
|
"main": "dist/index.js",
|
|
17
18
|
"types": "dist/index.d.ts",
|
|
18
19
|
"files": [
|
|
19
20
|
"/dist"
|
|
20
21
|
],
|
|
21
22
|
"scripts": {
|
|
22
|
-
"build": "
|
|
23
|
-
"dev": "
|
|
23
|
+
"build": "tsdown",
|
|
24
|
+
"dev": "tsdown --watch",
|
|
24
25
|
"test": "vitest run",
|
|
25
26
|
"test:watch": "vitest",
|
|
26
27
|
"build_and_publish": "npm run build && npm publish"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@testcontainers/mysql": "^
|
|
30
|
-
"@testcontainers/postgresql": "^
|
|
31
|
-
"@types/better-sqlite3": "^
|
|
32
|
-
"@types/node": "^
|
|
33
|
-
"@types/pg": "^8.
|
|
34
|
-
"@vitest/coverage-v8": "^
|
|
35
|
-
"better-sqlite3": "^
|
|
36
|
-
"mysql2": "^3.
|
|
37
|
-
"pg": "^8.
|
|
38
|
-
"
|
|
39
|
-
"typescript": "^
|
|
40
|
-
"
|
|
30
|
+
"@testcontainers/mysql": "^12.2.1",
|
|
31
|
+
"@testcontainers/postgresql": "^12.2.1",
|
|
32
|
+
"@types/better-sqlite3": "^9.6.0",
|
|
33
|
+
"@types/node": "^26.6.5",
|
|
34
|
+
"@types/pg": "^8.23.1",
|
|
35
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
36
|
+
"better-sqlite3": "^13.0.3",
|
|
37
|
+
"mysql2": "^3.24.6",
|
|
38
|
+
"pg": "^8.23.1",
|
|
39
|
+
"tsdown": "^0.23.1",
|
|
40
|
+
"typescript": "^6.0.3",
|
|
41
|
+
"vite": "^7.3.7",
|
|
42
|
+
"vitest": "^5.0.5"
|
|
41
43
|
},
|
|
42
44
|
"dependencies": {
|
|
43
45
|
"escape-sql-string": "^1.2.2",
|
|
44
46
|
"polyfill-symbol-metadata": "^0.0.2"
|
|
47
|
+
},
|
|
48
|
+
"allowScripts": {
|
|
49
|
+
"better-sqlite3@13.0.3": true,
|
|
50
|
+
"cpu-features@0.0.10": true,
|
|
51
|
+
"esbuild@0.28.2": true,
|
|
52
|
+
"fsevents@2.3.3": true,
|
|
53
|
+
"protobufjs@7.6.6": true,
|
|
54
|
+
"ssh2@1.17.0": true
|
|
45
55
|
}
|
|
46
56
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,380 +0,0 @@
|
|
|
1
|
-
interface DatabaseAccess {
|
|
2
|
-
createBackup?(backupName: string): Promise<any>;
|
|
3
|
-
runReadStatement(query: string): Promise<unknown>;
|
|
4
|
-
runWriteStatement(query: string): Promise<any>;
|
|
5
|
-
runTransaction(query: string): Promise<any>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
type Class<T> = new (...args: never[]) => T;
|
|
9
|
-
/**
|
|
10
|
-
* This does nothing. It mainly exists in case we want to filter class types in the future
|
|
11
|
-
*/
|
|
12
|
-
type TableClassInterface = {
|
|
13
|
-
[key: string]: any;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
declare const ALLOWED = "allowed";
|
|
17
|
-
declare const USED = "allowedAndUsed";
|
|
18
|
-
type AllowedMigrationState = typeof ALLOWED | typeof USED;
|
|
19
|
-
interface AllowedMigrations {
|
|
20
|
-
recreateTable?: Record<string, AllowedMigrationState>;
|
|
21
|
-
dropTable?: Record<string, AllowedMigrationState>;
|
|
22
|
-
dropColumn?: Record<string, AllowedMigrationState>;
|
|
23
|
-
alterPrimaryKey?: Record<string, AllowedMigrationState>;
|
|
24
|
-
removeForeignKey?: Record<string, AllowedMigrationState>;
|
|
25
|
-
alterForeignKey?: Record<string, AllowedMigrationState>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface RenameData {
|
|
29
|
-
oldName: string;
|
|
30
|
-
newName: string;
|
|
31
|
-
}
|
|
32
|
-
interface MigrationInstructions {
|
|
33
|
-
tableRenaming?: RenameData;
|
|
34
|
-
recreate: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Stores changes to column. One entry per column.
|
|
37
|
-
*/
|
|
38
|
-
renamedColumns: RenameData[];
|
|
39
|
-
allowedMigrations: AllowedMigrations;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface ColumnInfo {
|
|
43
|
-
name: string;
|
|
44
|
-
sqlType: string;
|
|
45
|
-
maxLength?: number;
|
|
46
|
-
defaultValue?: string;
|
|
47
|
-
isPrimaryKey: boolean;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
type ForeignKeyActions = "SET NULL" | "SET DEFAULT" | "RESTRICT" | "NO ACTION" | "CASCADE";
|
|
51
|
-
interface ForeignKeyInfo {
|
|
52
|
-
fromTable: string;
|
|
53
|
-
fromColumn: string;
|
|
54
|
-
toTable: string;
|
|
55
|
-
toColumn: string;
|
|
56
|
-
onUpdate?: ForeignKeyActions;
|
|
57
|
-
onDelete?: ForeignKeyActions;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
interface TableStructure {
|
|
61
|
-
table: string;
|
|
62
|
-
primaryKey?: string;
|
|
63
|
-
columns: Record<string, ColumnInfo>;
|
|
64
|
-
foreignKeys?: ForeignKeyInfo[];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The Migrations class is responsible for managing manual database schema migrations.
|
|
69
|
-
*/
|
|
70
|
-
declare class Migrations {
|
|
71
|
-
private fromVersion;
|
|
72
|
-
private toVersion;
|
|
73
|
-
private lastUsedVersion;
|
|
74
|
-
private migrationData;
|
|
75
|
-
private migrationDataForOldTableNames;
|
|
76
|
-
private alwaysAllowed;
|
|
77
|
-
private notAllowedChanges;
|
|
78
|
-
/**
|
|
79
|
-
* Resets the migration state to its initial values.
|
|
80
|
-
* Only used internally.
|
|
81
|
-
*
|
|
82
|
-
* @param dbInstructions - The instructions containing database metadata and migration details.
|
|
83
|
-
* @param fromVersion - The version of the actual database.
|
|
84
|
-
*/
|
|
85
|
-
reset(dbInstructions: DatabaseInstructions, fromVersion: number): void;
|
|
86
|
-
/**
|
|
87
|
-
* Retrieves the migration instructions for the specified table.
|
|
88
|
-
*
|
|
89
|
-
* @param tableName - The name of the table for which the entry is to be retrieved or created.
|
|
90
|
-
* @return The migration instructions corresponding to the given table input.
|
|
91
|
-
*/
|
|
92
|
-
private getEntryFromTableName;
|
|
93
|
-
/**
|
|
94
|
-
* Checks whether a provided version is relevant based on database version ({@link fromVersion}) and target version ({@link toVersion}).
|
|
95
|
-
* Also makes sure that version checks happen in order.
|
|
96
|
-
*
|
|
97
|
-
* @param version - The version to check for relevance.
|
|
98
|
-
* @return Returns true if the version is relevant, otherwise false.
|
|
99
|
-
* @throws Error if versions are not properly ordered
|
|
100
|
-
*/
|
|
101
|
-
private versionIsRelevant;
|
|
102
|
-
/**
|
|
103
|
-
* Verifies the renaming tasks specified in {@link DatabaseInstructions.preMigration} that were considered are valid.
|
|
104
|
-
* Called after all SQL queries have been generated.
|
|
105
|
-
* Only used internally.
|
|
106
|
-
*
|
|
107
|
-
* @param newTables - The table structures extracted from {@link DatabaseInstructions.tables}.
|
|
108
|
-
* @throws Error if a renaming task is invalid.
|
|
109
|
-
*/
|
|
110
|
-
verifyRenamingTasks(newTables: Record<string, TableStructure>): Error | void;
|
|
111
|
-
/**
|
|
112
|
-
* Making sure all considered calls to {@link allowMigration()} where necessary to prevent input mistakes.
|
|
113
|
-
* Called after all SQL queries have been generated.
|
|
114
|
-
* Only used internally.
|
|
115
|
-
*
|
|
116
|
-
* @throws Error if unnecessary calls were discovered. All discovered calls are collected and thrown as one Error.
|
|
117
|
-
*/
|
|
118
|
-
verifyAllowedMigrations(): Error | void;
|
|
119
|
-
/**
|
|
120
|
-
* Called by {@link MigrationManager} to check if a specific destructive query is allowed.
|
|
121
|
-
* Only used internally.
|
|
122
|
-
*
|
|
123
|
-
* @see allowMigration()
|
|
124
|
-
* @param tableName - The name of the table to check the migration against.
|
|
125
|
-
* @param type - The type of destructive migration being checked.
|
|
126
|
-
* @param column - The column name for which the migration is allowed. Only needed for "dropColumn", "removeForeignKey" and "alterForeignKey".
|
|
127
|
-
*/
|
|
128
|
-
compareWithAllowedMigration(tableName: string, type: keyof AllowedMigrations, column?: string): void;
|
|
129
|
-
/**
|
|
130
|
-
* Retrieves the migration data containing instructions for data migration.
|
|
131
|
-
* Only used internally.
|
|
132
|
-
*
|
|
133
|
-
* @return An object where each key corresponds to the table name,
|
|
134
|
-
* and the value is the associated migration instructions.
|
|
135
|
-
*/
|
|
136
|
-
getMigrationData(): Record<string, MigrationInstructions>;
|
|
137
|
-
/**
|
|
138
|
-
* Iterates over renamed columns for the specified table and executes a callback for each pair of old and new column names.
|
|
139
|
-
* Only used internally.
|
|
140
|
-
*
|
|
141
|
-
* @param tableName - Name of the table whose renamed columns should be processed.
|
|
142
|
-
* @param callback - A function to execute for each renamed column, receiving the old and new column names as arguments.
|
|
143
|
-
*/
|
|
144
|
-
loopRenamedColumns(tableName: string, callback: (oldColumnName: string, newColumnName: string) => void): void;
|
|
145
|
-
/**
|
|
146
|
-
* Considers the renaming of a table and returns its (newest) name after the migration or
|
|
147
|
-
* the original name if no renaming is queued.
|
|
148
|
-
* Only used internally.
|
|
149
|
-
*
|
|
150
|
-
* @see getOldTableName()
|
|
151
|
-
* @param tableName - The current table name in the database.
|
|
152
|
-
* @return The newest table name if available, otherwise the current table name.
|
|
153
|
-
*/
|
|
154
|
-
getNewestTableName(tableName: string): string;
|
|
155
|
-
/**
|
|
156
|
-
* Retrieves the current table name in the database.
|
|
157
|
-
* Only used internally.
|
|
158
|
-
*
|
|
159
|
-
* @see getNewestTableName()
|
|
160
|
-
* @param tableName - The name of the newest table name.
|
|
161
|
-
* @return The current table name in the database.
|
|
162
|
-
*/
|
|
163
|
-
getOldTableName(tableName: string): string;
|
|
164
|
-
/**
|
|
165
|
-
* Considers the renaming of a column in a table and returns its (newest) name after the migration or
|
|
166
|
-
* the original name if no renaming is queued.
|
|
167
|
-
* Only used internally.
|
|
168
|
-
*
|
|
169
|
-
* @param tableName - The name of the table containing the column.
|
|
170
|
-
* @param oldColumnName - The current name of the column in the database.
|
|
171
|
-
* @return The newest column name if available, otherwise the original column name.
|
|
172
|
-
*/
|
|
173
|
-
getNewestColumnName(tableName: string, oldColumnName: string): string;
|
|
174
|
-
/**
|
|
175
|
-
* Determines if the specified table is marked to be recreated.
|
|
176
|
-
* Only used internally.
|
|
177
|
-
*
|
|
178
|
-
* @param tableName The name of the table to check.
|
|
179
|
-
* @return Returns true if the table will be recreated, false otherwise.
|
|
180
|
-
*/
|
|
181
|
-
willBeRecreated(tableName: string): boolean;
|
|
182
|
-
/**
|
|
183
|
-
* Marks a table to be recreated and logs the recreation reason for the user.
|
|
184
|
-
* Only used internally.
|
|
185
|
-
*
|
|
186
|
-
* @param tableName - The name of the table to be marked for recreation.
|
|
187
|
-
* @param reason - The reason why the table is being marked for recreation.
|
|
188
|
-
*/
|
|
189
|
-
internalRecreate(tableName: string, reason: string): void;
|
|
190
|
-
/**
|
|
191
|
-
* SqlMorpheus only allows destructive statements if it was specifically allowed in {@link DatabaseInstructions.preMigration()}.
|
|
192
|
-
* Use this method to allow a destructive statement for a specific version.
|
|
193
|
-
* This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
|
|
194
|
-
*
|
|
195
|
-
* @param version - The target version for which the specific migration is allowed. Must be provided to make sure this method will only have an effect when specified.
|
|
196
|
-
* @param tableName - The current table name in the database at the time of the migration version.
|
|
197
|
-
* @param allowedMigration - The keys representing the migrations to be allowed.
|
|
198
|
-
* @param column - The column name for which the migration is allowed. Only needed for "dropColumn", "removeForeignKey" and "alterForeignKey".
|
|
199
|
-
*
|
|
200
|
-
* @throws Error if the provided column name is not valid for the specified migration.
|
|
201
|
-
*/
|
|
202
|
-
allowMigration(version: number, tableName: string, allowedMigration: keyof AllowedMigrations, column?: string): void;
|
|
203
|
-
/**
|
|
204
|
-
* When you change the name of a table, SqlMorpheus will assume the original table was meant to be dropped
|
|
205
|
-
* and the new table was meant to be added, which would lead to data loss.
|
|
206
|
-
* Use this method to mark a table to be renamed instead.
|
|
207
|
-
* This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
|
|
208
|
-
*
|
|
209
|
-
* @param version - The target version for which the table should be renamed. Must be provided to make sure this method will only have an effect when specified.
|
|
210
|
-
* @param oldTableName - The current name in the database at the time of the migration version.
|
|
211
|
-
* @param newTableName - The new table name at the time of the migration version.
|
|
212
|
-
*/
|
|
213
|
-
renameTable(version: number, oldTableName: string, newTableName: string): void;
|
|
214
|
-
/**
|
|
215
|
-
* When you change the name of a column, SqlMorpheus will assume the original column was meant to be removed
|
|
216
|
-
* and the new column was meant to be added, which would lead to data loss.
|
|
217
|
-
* Use this method to mark a column to be renamed instead.
|
|
218
|
-
* This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
|
|
219
|
-
*
|
|
220
|
-
* @param version - The target version for which the table should be renamed. Must be provided to make sure this method will only have an effect when specified.
|
|
221
|
-
* @param tableName - The current table name in the database at the time of the migration version.
|
|
222
|
-
* @param oldColumn The current name in the database at the time of the migration.
|
|
223
|
-
* @param newColumn The new name to assign to the column.
|
|
224
|
-
*/
|
|
225
|
-
renameColumn(version: number, tableName: string, oldColumn: string, newColumn: string): void;
|
|
226
|
-
/**
|
|
227
|
-
* Should not be needed most of the time.
|
|
228
|
-
* Marks a table to be recreated
|
|
229
|
-
* (a copy of the table will be created, all data will be moved over, the original table will be dropped and the new table will be renamed to the original name).
|
|
230
|
-
* This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
|
|
231
|
-
*
|
|
232
|
-
* @param version - The target version for which the table should be renamed. Must be provided to make sure this method will only have an effect when specified.
|
|
233
|
-
* @param tableName - The current table name in the database at the time of the migration version.
|
|
234
|
-
*/
|
|
235
|
-
recreateTable(version: number, tableName: string): void;
|
|
236
|
-
}
|
|
237
|
-
type PublicMigrations = Pick<Migrations, "recreateTable" | "renameTable" | "renameColumn" | "allowMigration">;
|
|
238
|
-
|
|
239
|
-
interface SqlChanges {
|
|
240
|
-
up: string;
|
|
241
|
-
down: string;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
type NativeDataTypeOptions = "boolean" | "number" | "bigint" | "string";
|
|
245
|
-
type AddedDataTypeOptions = "date" | "time" | "dateTime" | "text";
|
|
246
|
-
type DataTypeOptions = NativeDataTypeOptions | AddedDataTypeOptions;
|
|
247
|
-
|
|
248
|
-
interface InputColumnInfo extends ColumnInfo {
|
|
249
|
-
inputType?: DataTypeOptions;
|
|
250
|
-
inputDefaultValue?: unknown;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
interface InputTableStructure extends TableStructure {
|
|
254
|
-
columns: Record<string, InputColumnInfo>;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
type AllowedTypes = boolean | number | bigint | string | null | Date;
|
|
258
|
-
|
|
259
|
-
interface ColumnOptions {
|
|
260
|
-
primaryKey?: boolean;
|
|
261
|
-
dataType?: DataTypeOptions;
|
|
262
|
-
maxCharacterLength?: number;
|
|
263
|
-
}
|
|
264
|
-
type DataFormat = Record<string, AllowedTypes | [AllowedTypes, ColumnOptions]>;
|
|
265
|
-
type GetColumns<T> = T extends PublicTableObj<infer Item> ? Item : never;
|
|
266
|
-
type PublicTableObj<T extends DataFormat> = Pick<TableObj<T>, "foreignKey" | "sealType">;
|
|
267
|
-
type TableObjInput = PublicTableObj<DataFormat>;
|
|
268
|
-
/**
|
|
269
|
-
* Use this class to define tables for DatabaseInstructions
|
|
270
|
-
* (as an alternative for Class decorators)
|
|
271
|
-
*
|
|
272
|
-
*/
|
|
273
|
-
declare class TableObj<T extends DataFormat> {
|
|
274
|
-
readonly IS_TABLE_OBJ = true;
|
|
275
|
-
readonly tableName: string;
|
|
276
|
-
tableStructure: InputTableStructure;
|
|
277
|
-
private constructor();
|
|
278
|
-
private applyOptions;
|
|
279
|
-
/**
|
|
280
|
-
* Creates a foreign key relationship between the current table and a target table.
|
|
281
|
-
*
|
|
282
|
-
* @param fromColumn - The column in the current table that will serve as the foreign key.
|
|
283
|
-
* @param toTable - The target table object that the foreign key will reference.
|
|
284
|
-
* @param toColumn - The column in the target table that the foreign key will reference.
|
|
285
|
-
* @param options - Optional configurations for the foreign key, specifying actions on update or delete.
|
|
286
|
-
*/
|
|
287
|
-
foreignKey<TOther extends Partial<TableObj<DataFormat>>>(fromColumn: keyof T, toTable: TOther, toColumn: keyof GetColumns<TOther>, options?: {
|
|
288
|
-
onUpdate?: ForeignKeyActions;
|
|
289
|
-
onDelete?: ForeignKeyActions;
|
|
290
|
-
}): PublicTableObj<T>;
|
|
291
|
-
/**
|
|
292
|
-
* An optional helper function to deal with `TS2589: Type instantiation is excessively deep and possibly infinite. when used as method parameter`
|
|
293
|
-
* Does nothing in runtime
|
|
294
|
-
*/
|
|
295
|
-
sealType(): TableObjInput;
|
|
296
|
-
static create<T extends DataFormat>(tableName: string, columns: T): PublicTableObj<T>;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
type LoggerMode = "silent" | "error" | "warn" | "log" | "debug";
|
|
300
|
-
|
|
301
|
-
type TableInput = TableObjInput | Class<TableClassInterface>;
|
|
302
|
-
interface DatabaseInstructions {
|
|
303
|
-
dialect: "Sqlite" | "MsSql" | "MySql" | "Postgres";
|
|
304
|
-
tables: TableInput[];
|
|
305
|
-
version: number;
|
|
306
|
-
/**
|
|
307
|
-
* Usually SqlMorpheus throws an exception if it needs to execute a destructive database change and is not explicitly confirmed in
|
|
308
|
-
* (using `allowMigration()` in `preMigration()`).
|
|
309
|
-
* If true, no exception will be thrown and an error message will be logged to the console instead.
|
|
310
|
-
*/
|
|
311
|
-
doNotThrowIfNotAllowed?: boolean;
|
|
312
|
-
/**
|
|
313
|
-
* Defines how much should be logged to the console.
|
|
314
|
-
*/
|
|
315
|
-
loggerMode?: LoggerMode;
|
|
316
|
-
/**
|
|
317
|
-
* Usually SqlMorpheus throws an exception if it needs to execute a destructive database change and is not explicitly allowed to do so
|
|
318
|
-
* (using `allowMigration()` in `preMigration()`).
|
|
319
|
-
* if defined, the confirmation will be skipped for each migration type defined in `alwaysAllowedMigrations`.
|
|
320
|
-
*/
|
|
321
|
-
alwaysAllowedMigrations?: (keyof AllowedMigrations)[];
|
|
322
|
-
/**
|
|
323
|
-
* Custom migrations that will run before any database changes are applied.
|
|
324
|
-
* @param migrations - The migration object that will be validated after this.
|
|
325
|
-
* @param dbAccess - The database access object to interact with the database.
|
|
326
|
-
* @param fromVersion - Version of the current database.
|
|
327
|
-
* @param toVersion - Version of the database after update.
|
|
328
|
-
* @return custom SQL that should be executed before migrations are executed.
|
|
329
|
-
*/
|
|
330
|
-
preMigration?(migrations: PublicMigrations, dbAccess: DatabaseAccess, fromVersion: number, toVersion: number): SqlChanges | void;
|
|
331
|
-
/**
|
|
332
|
-
* Custom migrations that will run after database changes have been applied (but before the transaction is finished)
|
|
333
|
-
* @param dbAccess - The database access object to interact with the database.
|
|
334
|
-
* @param fromVersion - Version of the current database.
|
|
335
|
-
* @param toVersion - Version of the database after update.
|
|
336
|
-
* @return custom SQL that should be executed after migrations were executed.
|
|
337
|
-
*/
|
|
338
|
-
postMigration?(dbAccess: DatabaseAccess, fromVersion: number, toVersion: number): SqlChanges;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Decorator function to configure a database table with its name and primary key.
|
|
343
|
-
*
|
|
344
|
-
* @param tableName - The name of the database table used in SQL.
|
|
345
|
-
* @param primaryKey - The property name representing the primary property of the table.
|
|
346
|
-
*/
|
|
347
|
-
declare function TableClass<T extends TableClassInterface>(tableName: string, primaryKey?: keyof T): (table: Class<T>, context?: any) => void;
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Decorator function to assign a specific data type to a column.
|
|
351
|
-
* Should be used if you want to use a data type that does not exist in JavaScript or
|
|
352
|
-
* if the default value should be NULL
|
|
353
|
-
*
|
|
354
|
-
* @param type - The data type to be assigned.
|
|
355
|
-
*/
|
|
356
|
-
declare function DataType(type: DataTypeOptions): (table: any, context: any) => void;
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Decorator function to define a foreign key relationship for a database table.
|
|
360
|
-
*
|
|
361
|
-
* @param toTable - The target table class to which the foreign key points.
|
|
362
|
-
* @param toColumn - The column name in the target table to which the foreign key points.
|
|
363
|
-
* @param options - Additional options.
|
|
364
|
-
*/
|
|
365
|
-
declare function ForeignKey<TOther extends TableClassInterface>(toTable: Class<TOther>, toColumn: keyof TOther, options?: {
|
|
366
|
-
onDelete?: ForeignKeyActions;
|
|
367
|
-
onUpdate?: ForeignKeyActions;
|
|
368
|
-
}): (table: any, context: any) => void;
|
|
369
|
-
|
|
370
|
-
declare function runMigration(db: DatabaseAccess, dbInstructions: DatabaseInstructions): Promise<void>;
|
|
371
|
-
/**
|
|
372
|
-
* Rolls back the database to the provided toVersion
|
|
373
|
-
* @param dbAccess - Access to the database.
|
|
374
|
-
* @param toVersion - the version to which the database should be upgraded to.
|
|
375
|
-
* @param dialect - the dialect that should be used for the database. Usually is the value defined in DatabaseInstructions
|
|
376
|
-
* @param loggerMode - defines how much should be logged to the console.
|
|
377
|
-
*/
|
|
378
|
-
declare function rollback(dbAccess: DatabaseAccess, toVersion: number, dialect: DatabaseInstructions["dialect"], loggerMode?: DatabaseInstructions["loggerMode"]): Promise<number>;
|
|
379
|
-
|
|
380
|
-
export { DataType, type DatabaseAccess, type DatabaseInstructions, ForeignKey, type PublicMigrations, type SqlChanges, TableClass, TableObj, rollback, runMigration };
|