sqlmorpheus 0.1.2 → 0.1.4
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/index.d.mts +17 -1
- package/dist/index.d.ts +126 -9
- package/dist/index.js +947 -47
- package/dist/index.mjs +3 -1
- package/package.json +3 -3
- package/dist/lib/Logger.d.ts +0 -10
- package/dist/lib/Logger.js +0 -24
- package/dist/lib/MigrationHistoryManager.d.ts +0 -12
- package/dist/lib/MigrationHistoryManager.js +0 -47
- package/dist/lib/MigrationManager.d.ts +0 -27
- package/dist/lib/MigrationManager.js +0 -331
- package/dist/lib/TableStructureGenerator.d.ts +0 -10
- package/dist/lib/TableStructureGenerator.js +0 -69
- package/dist/lib/dialects/DefaultSql.d.ts +0 -34
- package/dist/lib/dialects/DefaultSql.js +0 -79
- package/dist/lib/dialects/MsSqlDialect.d.ts +0 -18
- package/dist/lib/dialects/MsSqlDialect.js +0 -53
- package/dist/lib/dialects/MySqlDialect.d.ts +0 -18
- package/dist/lib/dialects/MySqlDialect.js +0 -53
- package/dist/lib/dialects/PostgresDialect.d.ts +0 -16
- package/dist/lib/dialects/PostgresDialect.js +0 -42
- package/dist/lib/dialects/SqliteDialect.d.ts +0 -16
- package/dist/lib/dialects/SqliteDialect.js +0 -53
- package/dist/lib/exceptions/NotAllowedException.d.ts +0 -4
- package/dist/lib/exceptions/NotAllowedException.js +0 -31
- package/dist/lib/tableInfo/TableInfo.d.ts +0 -9
- package/dist/lib/tableInfo/TableInfo.js +0 -20
- package/dist/lib/tableInfo/TableObjects.d.ts +0 -6
- package/dist/lib/tableInfo/TableObjects.js +0 -2
- package/dist/lib/tableInfo/decorators/DbTable.d.ts +0 -2
- package/dist/lib/tableInfo/decorators/DbTable.js +0 -16
- package/dist/lib/tableInfo/decorators/ForeignKey.d.ts +0 -4
- package/dist/lib/tableInfo/decorators/ForeignKey.js +0 -20
- package/dist/lib/typings/AllowedMigrations.d.ts +0 -9
- package/dist/lib/typings/AllowedMigrations.js +0 -2
- package/dist/lib/typings/BackendTable.d.ts +0 -7
- package/dist/lib/typings/BackendTable.js +0 -2
- package/dist/lib/typings/ColumnInfo.d.ts +0 -6
- package/dist/lib/typings/ColumnInfo.js +0 -2
- package/dist/lib/typings/DatabaseAccess.d.ts +0 -5
- package/dist/lib/typings/DatabaseAccess.js +0 -2
- package/dist/lib/typings/DatabaseInstructions.d.ts +0 -26
- package/dist/lib/typings/DatabaseInstructions.js +0 -2
- package/dist/lib/typings/ForeignKeyInfo.d.ts +0 -9
- package/dist/lib/typings/ForeignKeyInfo.js +0 -2
- package/dist/lib/typings/MigrationHistory.d.ts +0 -7
- package/dist/lib/typings/MigrationHistory.js +0 -15
- package/dist/lib/typings/MigrationInstructions.d.ts +0 -10
- package/dist/lib/typings/MigrationInstructions.js +0 -2
- package/dist/lib/typings/Migrations.d.ts +0 -20
- package/dist/lib/typings/Migrations.js +0 -83
- package/dist/lib/typings/SqlChanges.d.ts +0 -4
- package/dist/lib/typings/SqlChanges.js +0 -2
- package/dist/lib/typings/TableStructure.d.ts +0 -8
- package/dist/lib/typings/TableStructure.js +0 -2
package/dist/index.d.mts
CHANGED
|
@@ -98,8 +98,24 @@ interface DatabaseInstructions {
|
|
|
98
98
|
postMigration?(fromVersion: number, toVersion: number): SqlChanges;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Decorator function to configure a database table with its name and primary key
|
|
103
|
+
* and to add missing "fromTable" properties to foreign keys.
|
|
104
|
+
*
|
|
105
|
+
* @param tableName - The name of the database table used in SQL.
|
|
106
|
+
* @param primaryKey - The property name representing the primary property of the table.
|
|
107
|
+
*/
|
|
101
108
|
declare function DbTable<T extends BackendTable>(tableName: string, primaryKey?: keyof T): (table: Class<T>, context?: any) => void;
|
|
102
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Decorator function to define a foreign key constraint for a database table. It defines a relationship
|
|
112
|
+
* between a column on the current table and a column on another table.
|
|
113
|
+
*
|
|
114
|
+
* @param toTable - The target table class to which the foreign key points.
|
|
115
|
+
* @param toColumn - The column name in the target table to which the foreign key points.
|
|
116
|
+
* @param [onDelete] - Optional. The action to perform when a row in the target table is deleted.
|
|
117
|
+
* @param [onUpdate] - Optional. The action to perform when a related row in the target table is updated.
|
|
118
|
+
*/
|
|
103
119
|
declare function ForeignKey<TOther extends BackendTable>(toTable: Class<TOther>, toColumn: keyof TOther, onDelete?: ForeignKeyActions, onUpdate?: ForeignKeyActions): (table: any, context: any) => void;
|
|
104
120
|
|
|
105
121
|
declare function prepareMigration(db: DatabaseAccess, instructions: DatabaseInstructions, overwriteExisting?: boolean): Promise<void>;
|
|
@@ -107,4 +123,4 @@ declare function runPreparedMigrations(db: DatabaseAccess, instructions: Databas
|
|
|
107
123
|
declare function prepareAndRunMigration(db: DatabaseAccess, instructions: DatabaseInstructions, overwriteExisting?: boolean): Promise<void>;
|
|
108
124
|
declare function rollback(db: DatabaseAccess, instructions: DatabaseInstructions, toVersion: number): Promise<void>;
|
|
109
125
|
|
|
110
|
-
export { DbTable, ForeignKey, prepareAndRunMigration, prepareMigration, rollback, runPreparedMigrations };
|
|
126
|
+
export { type DatabaseInstructions, DbTable, ForeignKey, prepareAndRunMigration, prepareMigration, rollback, runPreparedMigrations };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,126 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
interface DatabaseAccess {
|
|
2
|
+
createBackup?(name: string): Promise<void>;
|
|
3
|
+
runGetStatement(query: string): Promise<unknown>;
|
|
4
|
+
runMultipleWriteStatements(query: string): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type Class<T> = new (...args: never[]) => T;
|
|
8
|
+
/**
|
|
9
|
+
* This does nothing. It mainly exists in case we want to filter class types in the future
|
|
10
|
+
*/
|
|
11
|
+
type BackendTable = {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
interface AllowedMigrations {
|
|
16
|
+
recreateTable?: boolean;
|
|
17
|
+
dropTable?: boolean;
|
|
18
|
+
dropColumn?: boolean;
|
|
19
|
+
alterPrimaryKey?: boolean;
|
|
20
|
+
removeForeignKey?: boolean;
|
|
21
|
+
alterForeignKey?: boolean;
|
|
22
|
+
continueWithoutRollback?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface MigrationInstructions {
|
|
26
|
+
oldTableName?: string;
|
|
27
|
+
recreate: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Stores changes to column (0: name in the database, last: current name in code)
|
|
30
|
+
*/
|
|
31
|
+
renamedColumns: string[][];
|
|
32
|
+
allowedMigrations: Record<number, AllowedMigrations>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare class Migrations {
|
|
36
|
+
private readonly migrationData;
|
|
37
|
+
private alwaysAllowed;
|
|
38
|
+
private getEntry;
|
|
39
|
+
private getTableName;
|
|
40
|
+
alwaysAllow(...allowedMigrations: (keyof AllowedMigrations)[]): void;
|
|
41
|
+
allowMigration(version: number, table: string | Class<BackendTable>, ...allowedMigrations: (keyof AllowedMigrations)[]): void;
|
|
42
|
+
throwIfNotAllowed(version: number, tableName: string, type: keyof AllowedMigrations): void;
|
|
43
|
+
renameTable(oldTableName: string, newTable: string | Class<BackendTable>): void;
|
|
44
|
+
renameColumn(table: string | Class<BackendTable>, oldColumn: string, newColumn: string): void;
|
|
45
|
+
recreateTable(table: Class<BackendTable> | string): void;
|
|
46
|
+
getMigrationData(): Record<string, MigrationInstructions>;
|
|
47
|
+
loopRenamedColumns(tableName: string, callback: (oldColumnName: string, newColumnName: string) => void): void;
|
|
48
|
+
getUpdatedColumnName(tableName: string, oldColumnName: string): string;
|
|
49
|
+
willBeRecreated(tableName: string): boolean;
|
|
50
|
+
}
|
|
51
|
+
type PublicMigrations = Pick<Migrations, "recreateTable" | "renameTable" | "renameColumn" | "allowMigration" | "alwaysAllow">;
|
|
52
|
+
|
|
53
|
+
interface SqlChanges {
|
|
54
|
+
up: string;
|
|
55
|
+
down: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type ForeignKeyActions = "SET NULL" | "SET DEFAULT" | "RESTRICT" | "NO ACTION" | "CASCADE";
|
|
59
|
+
interface ForeignKeyInfo {
|
|
60
|
+
fromTable: string;
|
|
61
|
+
fromColumn: string;
|
|
62
|
+
toTable: string;
|
|
63
|
+
toColumn: string;
|
|
64
|
+
onUpdate?: ForeignKeyActions;
|
|
65
|
+
onDelete?: ForeignKeyActions;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface TableInfo {
|
|
69
|
+
primaryKey?: string;
|
|
70
|
+
foreignKeys?: ForeignKeyInfo[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type TableObjects = Record<string, {
|
|
74
|
+
columns: BackendTable;
|
|
75
|
+
tableInfo?: TableInfo;
|
|
76
|
+
}>;
|
|
77
|
+
|
|
78
|
+
interface DatabaseInstructions {
|
|
79
|
+
dialect: "Sqlite" | "MsSql" | "MySql" | "Postgres";
|
|
80
|
+
tables: Class<BackendTable>[] | TableObjects;
|
|
81
|
+
version: number;
|
|
82
|
+
configPath: string;
|
|
83
|
+
loggerMode?: "silent" | "noLog" | "normal" | "debug";
|
|
84
|
+
/**
|
|
85
|
+
* Custom migrations that will run before any database changes are applied.
|
|
86
|
+
* @param migrations The migration object that will be validated after this.
|
|
87
|
+
* @param fromVersion Version of the current database.
|
|
88
|
+
* @param toVersion Version of the database after update.
|
|
89
|
+
* @return custom SQL that should be executed before migrations are executed.
|
|
90
|
+
*/
|
|
91
|
+
preMigration?(migrations: PublicMigrations, fromVersion: number, toVersion: number): SqlChanges | void;
|
|
92
|
+
/**
|
|
93
|
+
* Custom migrations that will run after database changes have been applied (but before the transaction is finished)
|
|
94
|
+
* @param fromVersion Version of the current database.
|
|
95
|
+
* @param toVersion Version of the database after update.
|
|
96
|
+
* @return custom SQL that should be executed before migrations are executed.
|
|
97
|
+
*/
|
|
98
|
+
postMigration?(fromVersion: number, toVersion: number): SqlChanges;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Decorator function to configure a database table with its name and primary key
|
|
103
|
+
* and to add missing "fromTable" properties to foreign keys.
|
|
104
|
+
*
|
|
105
|
+
* @param tableName - The name of the database table used in SQL.
|
|
106
|
+
* @param primaryKey - The property name representing the primary property of the table.
|
|
107
|
+
*/
|
|
108
|
+
declare function DbTable<T extends BackendTable>(tableName: string, primaryKey?: keyof T): (table: Class<T>, context?: any) => void;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Decorator function to define a foreign key constraint for a database table. It defines a relationship
|
|
112
|
+
* between a column on the current table and a column on another table.
|
|
113
|
+
*
|
|
114
|
+
* @param toTable - The target table class to which the foreign key points.
|
|
115
|
+
* @param toColumn - The column name in the target table to which the foreign key points.
|
|
116
|
+
* @param [onDelete] - Optional. The action to perform when a row in the target table is deleted.
|
|
117
|
+
* @param [onUpdate] - Optional. The action to perform when a related row in the target table is updated.
|
|
118
|
+
*/
|
|
119
|
+
declare function ForeignKey<TOther extends BackendTable>(toTable: Class<TOther>, toColumn: keyof TOther, onDelete?: ForeignKeyActions, onUpdate?: ForeignKeyActions): (table: any, context: any) => void;
|
|
120
|
+
|
|
121
|
+
declare function prepareMigration(db: DatabaseAccess, instructions: DatabaseInstructions, overwriteExisting?: boolean): Promise<void>;
|
|
122
|
+
declare function runPreparedMigrations(db: DatabaseAccess, instructions: DatabaseInstructions): Promise<void>;
|
|
123
|
+
declare function prepareAndRunMigration(db: DatabaseAccess, instructions: DatabaseInstructions, overwriteExisting?: boolean): Promise<void>;
|
|
124
|
+
declare function rollback(db: DatabaseAccess, instructions: DatabaseInstructions, toVersion: number): Promise<void>;
|
|
125
|
+
|
|
126
|
+
export { type DatabaseInstructions, DbTable, ForeignKey, prepareAndRunMigration, prepareMigration, rollback, runPreparedMigrations };
|