@ductape/sdk 0.0.4-v42 → 0.0.4-v43
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/apps/services/app.service.d.ts +10 -0
- package/dist/apps/services/app.service.js +22 -0
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/database/adapters/base.adapter.d.ts +176 -0
- package/dist/database/adapters/base.adapter.js +31 -0
- package/dist/database/adapters/base.adapter.js.map +1 -0
- package/dist/database/adapters/dynamodb.adapter.d.ts +83 -0
- package/dist/database/adapters/dynamodb.adapter.js +1237 -0
- package/dist/database/adapters/dynamodb.adapter.js.map +1 -0
- package/dist/database/adapters/mongodb.adapter.d.ts +70 -0
- package/dist/database/adapters/mongodb.adapter.js +717 -0
- package/dist/database/adapters/mongodb.adapter.js.map +1 -0
- package/dist/database/adapters/mysql.adapter.d.ts +141 -0
- package/dist/database/adapters/mysql.adapter.js +1221 -0
- package/dist/database/adapters/mysql.adapter.js.map +1 -0
- package/dist/database/adapters/postgresql.adapter.d.ts +142 -0
- package/dist/database/adapters/postgresql.adapter.js +1288 -0
- package/dist/database/adapters/postgresql.adapter.js.map +1 -0
- package/dist/database/database.service.d.ts +190 -0
- package/dist/database/database.service.js +552 -0
- package/dist/database/database.service.js.map +1 -0
- package/dist/database/index.d.ts +18 -0
- package/dist/database/index.js +98 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/types/aggregation.types.d.ts +202 -0
- package/dist/database/types/aggregation.types.js +21 -0
- package/dist/database/types/aggregation.types.js.map +1 -0
- package/dist/database/types/connection.types.d.ts +132 -0
- package/dist/database/types/connection.types.js +6 -0
- package/dist/database/types/connection.types.js.map +1 -0
- package/dist/database/types/database.types.d.ts +173 -0
- package/dist/database/types/database.types.js +73 -0
- package/dist/database/types/database.types.js.map +1 -0
- package/dist/database/types/index.d.ts +12 -0
- package/dist/database/types/index.js +37 -0
- package/dist/database/types/index.js.map +1 -0
- package/dist/database/types/index.types.d.ts +220 -0
- package/dist/database/types/index.types.js +27 -0
- package/dist/database/types/index.types.js.map +1 -0
- package/dist/database/types/migration.types.d.ts +205 -0
- package/dist/database/types/migration.types.js +44 -0
- package/dist/database/types/migration.types.js.map +1 -0
- package/dist/database/types/query.types.d.ts +274 -0
- package/dist/database/types/query.types.js +57 -0
- package/dist/database/types/query.types.js.map +1 -0
- package/dist/database/types/result.types.d.ts +218 -0
- package/dist/database/types/result.types.js +6 -0
- package/dist/database/types/result.types.js.map +1 -0
- package/dist/database/types/schema.types.d.ts +190 -0
- package/dist/database/types/schema.types.js +69 -0
- package/dist/database/types/schema.types.js.map +1 -0
- package/dist/database/utils/helpers.d.ts +66 -0
- package/dist/database/utils/helpers.js +501 -0
- package/dist/database/utils/helpers.js.map +1 -0
- package/dist/database/utils/migration.utils.d.ts +151 -0
- package/dist/database/utils/migration.utils.js +476 -0
- package/dist/database/utils/migration.utils.js.map +1 -0
- package/dist/database/utils/transaction.d.ts +64 -0
- package/dist/database/utils/transaction.js +130 -0
- package/dist/database/utils/transaction.js.map +1 -0
- package/dist/database/validators/connection.validator.d.ts +20 -0
- package/dist/database/validators/connection.validator.js +267 -0
- package/dist/database/validators/connection.validator.js.map +1 -0
- package/dist/database/validators/query.validator.d.ts +31 -0
- package/dist/database/validators/query.validator.js +305 -0
- package/dist/database/validators/query.validator.js.map +1 -0
- package/dist/database/validators/schema.validator.d.ts +31 -0
- package/dist/database/validators/schema.validator.js +334 -0
- package/dist/database/validators/schema.validator.js.map +1 -0
- package/dist/index.d.ts +25 -4
- package/dist/index.js +36 -4
- package/dist/index.js.map +1 -1
- package/dist/processor/services/processor.service.js +10 -8
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/types/processor.types.d.ts +2 -2
- package/package.json +3 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration Utilities
|
|
3
|
+
* Helper functions for creating and managing database migrations
|
|
4
|
+
*/
|
|
5
|
+
import { IMigrationDefinition, IMigrationOperation } from '../types/migration.types';
|
|
6
|
+
import { ITableSchema, IColumnDefinition } from '../types/schema.types';
|
|
7
|
+
/**
|
|
8
|
+
* Generate a migration tag from a name
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateMigrationTag(name: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Generate a migration timestamp
|
|
13
|
+
*/
|
|
14
|
+
export declare function generateMigrationTimestamp(): number;
|
|
15
|
+
/**
|
|
16
|
+
* Create a migration definition
|
|
17
|
+
*/
|
|
18
|
+
export declare function createMigration(name: string, up: IMigrationOperation[], down: IMigrationOperation[], tag?: string): IMigrationDefinition;
|
|
19
|
+
/**
|
|
20
|
+
* Create a table creation migration operation
|
|
21
|
+
*/
|
|
22
|
+
export declare function createTable(schema: ITableSchema): IMigrationOperation;
|
|
23
|
+
/**
|
|
24
|
+
* Create a table drop migration operation
|
|
25
|
+
*/
|
|
26
|
+
export declare function dropTable(tableName: string): IMigrationOperation;
|
|
27
|
+
/**
|
|
28
|
+
* Create an add column migration operation
|
|
29
|
+
*/
|
|
30
|
+
export declare function addColumn(tableName: string, column: IColumnDefinition): IMigrationOperation;
|
|
31
|
+
/**
|
|
32
|
+
* Create a drop column migration operation
|
|
33
|
+
*/
|
|
34
|
+
export declare function dropColumn(tableName: string, columnName: string): IMigrationOperation;
|
|
35
|
+
/**
|
|
36
|
+
* Create a modify column migration operation
|
|
37
|
+
*/
|
|
38
|
+
export declare function modifyColumn(tableName: string, column: IColumnDefinition): IMigrationOperation;
|
|
39
|
+
/**
|
|
40
|
+
* Create a rename column migration operation
|
|
41
|
+
*/
|
|
42
|
+
export declare function renameColumn(tableName: string, oldName: string, newName: string): IMigrationOperation;
|
|
43
|
+
/**
|
|
44
|
+
* Create an add index migration operation
|
|
45
|
+
*/
|
|
46
|
+
export declare function addIndex(tableName: string, indexName: string, columns: string[], unique?: boolean): IMigrationOperation;
|
|
47
|
+
/**
|
|
48
|
+
* Create a drop index migration operation
|
|
49
|
+
*/
|
|
50
|
+
export declare function dropIndex(indexName: string): IMigrationOperation;
|
|
51
|
+
/**
|
|
52
|
+
* Create an add constraint migration operation
|
|
53
|
+
*/
|
|
54
|
+
export declare function addConstraint(tableName: string, constraintName: string, definition: string): IMigrationOperation;
|
|
55
|
+
/**
|
|
56
|
+
* Create a drop constraint migration operation
|
|
57
|
+
*/
|
|
58
|
+
export declare function dropConstraint(tableName: string, constraintName: string): IMigrationOperation;
|
|
59
|
+
/**
|
|
60
|
+
* Create a raw SQL migration operation
|
|
61
|
+
*/
|
|
62
|
+
export declare function rawSql(sql: string): IMigrationOperation;
|
|
63
|
+
/**
|
|
64
|
+
* Create a complete migration with automatic rollback for common operations
|
|
65
|
+
*/
|
|
66
|
+
export declare function createTableMigration(name: string, schema: ITableSchema, tag?: string): IMigrationDefinition;
|
|
67
|
+
/**
|
|
68
|
+
* Create a migration to add a column with automatic rollback
|
|
69
|
+
*/
|
|
70
|
+
export declare function addColumnMigration(name: string, tableName: string, column: IColumnDefinition, tag?: string): IMigrationDefinition;
|
|
71
|
+
/**
|
|
72
|
+
* Create a migration to add an index with automatic rollback
|
|
73
|
+
*/
|
|
74
|
+
export declare function addIndexMigration(name: string, tableName: string, indexName: string, columns: string[], unique?: boolean, tag?: string): IMigrationDefinition;
|
|
75
|
+
/**
|
|
76
|
+
* Schema helper for common column types
|
|
77
|
+
*/
|
|
78
|
+
export declare const SchemaHelpers: {
|
|
79
|
+
/**
|
|
80
|
+
* Create a primary key column (auto-increment integer)
|
|
81
|
+
*/
|
|
82
|
+
id(name?: string): IColumnDefinition;
|
|
83
|
+
/**
|
|
84
|
+
* Create a UUID primary key column
|
|
85
|
+
*/
|
|
86
|
+
uuid(name?: string): IColumnDefinition;
|
|
87
|
+
/**
|
|
88
|
+
* Create a string column
|
|
89
|
+
*/
|
|
90
|
+
string(name: string, length?: number, nullable?: boolean): IColumnDefinition;
|
|
91
|
+
/**
|
|
92
|
+
* Create a text column
|
|
93
|
+
*/
|
|
94
|
+
text(name: string, nullable?: boolean): IColumnDefinition;
|
|
95
|
+
/**
|
|
96
|
+
* Create an integer column
|
|
97
|
+
*/
|
|
98
|
+
integer(name: string, nullable?: boolean): IColumnDefinition;
|
|
99
|
+
/**
|
|
100
|
+
* Create a bigint column
|
|
101
|
+
*/
|
|
102
|
+
bigint(name: string, nullable?: boolean): IColumnDefinition;
|
|
103
|
+
/**
|
|
104
|
+
* Create a decimal column
|
|
105
|
+
*/
|
|
106
|
+
decimal(name: string, precision?: number, scale?: number, nullable?: boolean): IColumnDefinition;
|
|
107
|
+
/**
|
|
108
|
+
* Create a boolean column
|
|
109
|
+
*/
|
|
110
|
+
boolean(name: string, defaultValue?: boolean, nullable?: boolean): IColumnDefinition;
|
|
111
|
+
/**
|
|
112
|
+
* Create a date column
|
|
113
|
+
*/
|
|
114
|
+
date(name: string, nullable?: boolean): IColumnDefinition;
|
|
115
|
+
/**
|
|
116
|
+
* Create a datetime column
|
|
117
|
+
*/
|
|
118
|
+
datetime(name: string, nullable?: boolean): IColumnDefinition;
|
|
119
|
+
/**
|
|
120
|
+
* Create a timestamp column
|
|
121
|
+
*/
|
|
122
|
+
timestamp(name: string, nullable?: boolean): IColumnDefinition;
|
|
123
|
+
/**
|
|
124
|
+
* Create a JSON column
|
|
125
|
+
*/
|
|
126
|
+
json(name: string, nullable?: boolean): IColumnDefinition;
|
|
127
|
+
/**
|
|
128
|
+
* Create a JSONB column (PostgreSQL)
|
|
129
|
+
*/
|
|
130
|
+
jsonb(name: string, nullable?: boolean): IColumnDefinition;
|
|
131
|
+
/**
|
|
132
|
+
* Create timestamps columns (created_at, updated_at)
|
|
133
|
+
*/
|
|
134
|
+
timestamps(): IColumnDefinition[];
|
|
135
|
+
/**
|
|
136
|
+
* Create a soft delete column (deleted_at)
|
|
137
|
+
*/
|
|
138
|
+
softDelete(): IColumnDefinition;
|
|
139
|
+
/**
|
|
140
|
+
* Create a foreign key column
|
|
141
|
+
*/
|
|
142
|
+
foreignKey(name: string, referencedTable: string, referencedColumn?: string, nullable?: boolean): IColumnDefinition;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Generate TypeScript migration file content
|
|
146
|
+
*/
|
|
147
|
+
export declare function generateMigrationFileContent(migration: IMigrationDefinition): string;
|
|
148
|
+
/**
|
|
149
|
+
* Generate a simple migration template
|
|
150
|
+
*/
|
|
151
|
+
export declare function generateMigrationTemplate(name: string): string;
|
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Migration Utilities
|
|
4
|
+
* Helper functions for creating and managing database migrations
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SchemaHelpers = void 0;
|
|
8
|
+
exports.generateMigrationTag = generateMigrationTag;
|
|
9
|
+
exports.generateMigrationTimestamp = generateMigrationTimestamp;
|
|
10
|
+
exports.createMigration = createMigration;
|
|
11
|
+
exports.createTable = createTable;
|
|
12
|
+
exports.dropTable = dropTable;
|
|
13
|
+
exports.addColumn = addColumn;
|
|
14
|
+
exports.dropColumn = dropColumn;
|
|
15
|
+
exports.modifyColumn = modifyColumn;
|
|
16
|
+
exports.renameColumn = renameColumn;
|
|
17
|
+
exports.addIndex = addIndex;
|
|
18
|
+
exports.dropIndex = dropIndex;
|
|
19
|
+
exports.addConstraint = addConstraint;
|
|
20
|
+
exports.dropConstraint = dropConstraint;
|
|
21
|
+
exports.rawSql = rawSql;
|
|
22
|
+
exports.createTableMigration = createTableMigration;
|
|
23
|
+
exports.addColumnMigration = addColumnMigration;
|
|
24
|
+
exports.addIndexMigration = addIndexMigration;
|
|
25
|
+
exports.generateMigrationFileContent = generateMigrationFileContent;
|
|
26
|
+
exports.generateMigrationTemplate = generateMigrationTemplate;
|
|
27
|
+
const migration_types_1 = require("../types/migration.types");
|
|
28
|
+
const schema_types_1 = require("../types/schema.types");
|
|
29
|
+
/**
|
|
30
|
+
* Generate a migration tag from a name
|
|
31
|
+
*/
|
|
32
|
+
function generateMigrationTag(name) {
|
|
33
|
+
const timestamp = Date.now();
|
|
34
|
+
const sanitizedName = name.toLowerCase().replace(/[^a-z0-9]+/g, '_');
|
|
35
|
+
return `${timestamp}_${sanitizedName}`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Generate a migration timestamp
|
|
39
|
+
*/
|
|
40
|
+
function generateMigrationTimestamp() {
|
|
41
|
+
return Date.now();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a migration definition
|
|
45
|
+
*/
|
|
46
|
+
function createMigration(name, up, down, tag) {
|
|
47
|
+
return {
|
|
48
|
+
tag: tag || generateMigrationTag(name),
|
|
49
|
+
name,
|
|
50
|
+
description: `Migration: ${name}`,
|
|
51
|
+
up,
|
|
52
|
+
down,
|
|
53
|
+
createdAt: new Date(),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a table creation migration operation
|
|
58
|
+
*/
|
|
59
|
+
function createTable(schema) {
|
|
60
|
+
return {
|
|
61
|
+
type: migration_types_1.MigrationOperationType.CREATE_TABLE,
|
|
62
|
+
params: { schema },
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a table drop migration operation
|
|
67
|
+
*/
|
|
68
|
+
function dropTable(tableName) {
|
|
69
|
+
return {
|
|
70
|
+
type: migration_types_1.MigrationOperationType.DROP_TABLE,
|
|
71
|
+
table: tableName,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create an add column migration operation
|
|
76
|
+
*/
|
|
77
|
+
function addColumn(tableName, column) {
|
|
78
|
+
return {
|
|
79
|
+
type: migration_types_1.MigrationOperationType.ADD_COLUMN,
|
|
80
|
+
table: tableName,
|
|
81
|
+
params: { column },
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Create a drop column migration operation
|
|
86
|
+
*/
|
|
87
|
+
function dropColumn(tableName, columnName) {
|
|
88
|
+
return {
|
|
89
|
+
type: migration_types_1.MigrationOperationType.DROP_COLUMN,
|
|
90
|
+
table: tableName,
|
|
91
|
+
params: { columnName },
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create a modify column migration operation
|
|
96
|
+
*/
|
|
97
|
+
function modifyColumn(tableName, column) {
|
|
98
|
+
return {
|
|
99
|
+
type: migration_types_1.MigrationOperationType.MODIFY_COLUMN,
|
|
100
|
+
table: tableName,
|
|
101
|
+
params: { column },
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create a rename column migration operation
|
|
106
|
+
*/
|
|
107
|
+
function renameColumn(tableName, oldName, newName) {
|
|
108
|
+
return {
|
|
109
|
+
type: migration_types_1.MigrationOperationType.RENAME_COLUMN,
|
|
110
|
+
table: tableName,
|
|
111
|
+
params: { oldName, newName },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create an add index migration operation
|
|
116
|
+
*/
|
|
117
|
+
function addIndex(tableName, indexName, columns, unique = false) {
|
|
118
|
+
return {
|
|
119
|
+
type: migration_types_1.MigrationOperationType.ADD_INDEX,
|
|
120
|
+
table: tableName,
|
|
121
|
+
params: { indexName, columns, unique },
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create a drop index migration operation
|
|
126
|
+
*/
|
|
127
|
+
function dropIndex(indexName) {
|
|
128
|
+
return {
|
|
129
|
+
type: migration_types_1.MigrationOperationType.DROP_INDEX,
|
|
130
|
+
params: { indexName },
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Create an add constraint migration operation
|
|
135
|
+
*/
|
|
136
|
+
function addConstraint(tableName, constraintName, definition) {
|
|
137
|
+
return {
|
|
138
|
+
type: migration_types_1.MigrationOperationType.ADD_CONSTRAINT,
|
|
139
|
+
table: tableName,
|
|
140
|
+
params: { constraintName, definition },
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Create a drop constraint migration operation
|
|
145
|
+
*/
|
|
146
|
+
function dropConstraint(tableName, constraintName) {
|
|
147
|
+
return {
|
|
148
|
+
type: migration_types_1.MigrationOperationType.DROP_CONSTRAINT,
|
|
149
|
+
table: tableName,
|
|
150
|
+
params: { constraintName },
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Create a raw SQL migration operation
|
|
155
|
+
*/
|
|
156
|
+
function rawSql(sql) {
|
|
157
|
+
return {
|
|
158
|
+
type: migration_types_1.MigrationOperationType.RAW_SQL,
|
|
159
|
+
sql,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Create a complete migration with automatic rollback for common operations
|
|
164
|
+
*/
|
|
165
|
+
function createTableMigration(name, schema, tag) {
|
|
166
|
+
return createMigration(name, [createTable(schema)], [dropTable(schema.name)], tag);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Create a migration to add a column with automatic rollback
|
|
170
|
+
*/
|
|
171
|
+
function addColumnMigration(name, tableName, column, tag) {
|
|
172
|
+
return createMigration(name, [addColumn(tableName, column)], [dropColumn(tableName, column.name)], tag);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Create a migration to add an index with automatic rollback
|
|
176
|
+
*/
|
|
177
|
+
function addIndexMigration(name, tableName, indexName, columns, unique = false, tag) {
|
|
178
|
+
return createMigration(name, [addIndex(tableName, indexName, columns, unique)], [dropIndex(indexName)], tag);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Schema helper for common column types
|
|
182
|
+
*/
|
|
183
|
+
exports.SchemaHelpers = {
|
|
184
|
+
/**
|
|
185
|
+
* Create a primary key column (auto-increment integer)
|
|
186
|
+
*/
|
|
187
|
+
id(name = 'id') {
|
|
188
|
+
return {
|
|
189
|
+
name,
|
|
190
|
+
type: schema_types_1.ColumnType.INTEGER,
|
|
191
|
+
primaryKey: true,
|
|
192
|
+
autoIncrement: true,
|
|
193
|
+
nullable: false,
|
|
194
|
+
};
|
|
195
|
+
},
|
|
196
|
+
/**
|
|
197
|
+
* Create a UUID primary key column
|
|
198
|
+
*/
|
|
199
|
+
uuid(name = 'id') {
|
|
200
|
+
return {
|
|
201
|
+
name,
|
|
202
|
+
type: schema_types_1.ColumnType.UUID,
|
|
203
|
+
primaryKey: true,
|
|
204
|
+
nullable: false,
|
|
205
|
+
};
|
|
206
|
+
},
|
|
207
|
+
/**
|
|
208
|
+
* Create a string column
|
|
209
|
+
*/
|
|
210
|
+
string(name, length = 255, nullable = true) {
|
|
211
|
+
return {
|
|
212
|
+
name,
|
|
213
|
+
type: schema_types_1.ColumnType.STRING,
|
|
214
|
+
length,
|
|
215
|
+
nullable,
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
/**
|
|
219
|
+
* Create a text column
|
|
220
|
+
*/
|
|
221
|
+
text(name, nullable = true) {
|
|
222
|
+
return {
|
|
223
|
+
name,
|
|
224
|
+
type: schema_types_1.ColumnType.TEXT,
|
|
225
|
+
nullable,
|
|
226
|
+
};
|
|
227
|
+
},
|
|
228
|
+
/**
|
|
229
|
+
* Create an integer column
|
|
230
|
+
*/
|
|
231
|
+
integer(name, nullable = true) {
|
|
232
|
+
return {
|
|
233
|
+
name,
|
|
234
|
+
type: schema_types_1.ColumnType.INTEGER,
|
|
235
|
+
nullable,
|
|
236
|
+
};
|
|
237
|
+
},
|
|
238
|
+
/**
|
|
239
|
+
* Create a bigint column
|
|
240
|
+
*/
|
|
241
|
+
bigint(name, nullable = true) {
|
|
242
|
+
return {
|
|
243
|
+
name,
|
|
244
|
+
type: schema_types_1.ColumnType.BIGINT,
|
|
245
|
+
nullable,
|
|
246
|
+
};
|
|
247
|
+
},
|
|
248
|
+
/**
|
|
249
|
+
* Create a decimal column
|
|
250
|
+
*/
|
|
251
|
+
decimal(name, precision = 10, scale = 2, nullable = true) {
|
|
252
|
+
return {
|
|
253
|
+
name,
|
|
254
|
+
type: schema_types_1.ColumnType.DECIMAL,
|
|
255
|
+
precision,
|
|
256
|
+
scale,
|
|
257
|
+
nullable,
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
/**
|
|
261
|
+
* Create a boolean column
|
|
262
|
+
*/
|
|
263
|
+
boolean(name, defaultValue, nullable = true) {
|
|
264
|
+
return {
|
|
265
|
+
name,
|
|
266
|
+
type: schema_types_1.ColumnType.BOOLEAN,
|
|
267
|
+
defaultValue,
|
|
268
|
+
nullable,
|
|
269
|
+
};
|
|
270
|
+
},
|
|
271
|
+
/**
|
|
272
|
+
* Create a date column
|
|
273
|
+
*/
|
|
274
|
+
date(name, nullable = true) {
|
|
275
|
+
return {
|
|
276
|
+
name,
|
|
277
|
+
type: schema_types_1.ColumnType.DATE,
|
|
278
|
+
nullable,
|
|
279
|
+
};
|
|
280
|
+
},
|
|
281
|
+
/**
|
|
282
|
+
* Create a datetime column
|
|
283
|
+
*/
|
|
284
|
+
datetime(name, nullable = true) {
|
|
285
|
+
return {
|
|
286
|
+
name,
|
|
287
|
+
type: schema_types_1.ColumnType.DATETIME,
|
|
288
|
+
nullable,
|
|
289
|
+
};
|
|
290
|
+
},
|
|
291
|
+
/**
|
|
292
|
+
* Create a timestamp column
|
|
293
|
+
*/
|
|
294
|
+
timestamp(name, nullable = true) {
|
|
295
|
+
return {
|
|
296
|
+
name,
|
|
297
|
+
type: schema_types_1.ColumnType.TIMESTAMP,
|
|
298
|
+
nullable,
|
|
299
|
+
};
|
|
300
|
+
},
|
|
301
|
+
/**
|
|
302
|
+
* Create a JSON column
|
|
303
|
+
*/
|
|
304
|
+
json(name, nullable = true) {
|
|
305
|
+
return {
|
|
306
|
+
name,
|
|
307
|
+
type: schema_types_1.ColumnType.JSON,
|
|
308
|
+
nullable,
|
|
309
|
+
};
|
|
310
|
+
},
|
|
311
|
+
/**
|
|
312
|
+
* Create a JSONB column (PostgreSQL)
|
|
313
|
+
*/
|
|
314
|
+
jsonb(name, nullable = true) {
|
|
315
|
+
return {
|
|
316
|
+
name,
|
|
317
|
+
type: schema_types_1.ColumnType.JSONB,
|
|
318
|
+
nullable,
|
|
319
|
+
};
|
|
320
|
+
},
|
|
321
|
+
/**
|
|
322
|
+
* Create timestamps columns (created_at, updated_at)
|
|
323
|
+
*/
|
|
324
|
+
timestamps() {
|
|
325
|
+
return [
|
|
326
|
+
{
|
|
327
|
+
name: 'created_at',
|
|
328
|
+
type: schema_types_1.ColumnType.TIMESTAMP,
|
|
329
|
+
nullable: false,
|
|
330
|
+
defaultValue: 'CURRENT_TIMESTAMP',
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
name: 'updated_at',
|
|
334
|
+
type: schema_types_1.ColumnType.TIMESTAMP,
|
|
335
|
+
nullable: false,
|
|
336
|
+
defaultValue: 'CURRENT_TIMESTAMP',
|
|
337
|
+
},
|
|
338
|
+
];
|
|
339
|
+
},
|
|
340
|
+
/**
|
|
341
|
+
* Create a soft delete column (deleted_at)
|
|
342
|
+
*/
|
|
343
|
+
softDelete() {
|
|
344
|
+
return {
|
|
345
|
+
name: 'deleted_at',
|
|
346
|
+
type: schema_types_1.ColumnType.TIMESTAMP,
|
|
347
|
+
nullable: true,
|
|
348
|
+
};
|
|
349
|
+
},
|
|
350
|
+
/**
|
|
351
|
+
* Create a foreign key column
|
|
352
|
+
*/
|
|
353
|
+
foreignKey(name, referencedTable, referencedColumn = 'id', nullable = true) {
|
|
354
|
+
return {
|
|
355
|
+
name,
|
|
356
|
+
type: schema_types_1.ColumnType.INTEGER,
|
|
357
|
+
nullable,
|
|
358
|
+
comment: `Foreign key to ${referencedTable}.${referencedColumn}`,
|
|
359
|
+
};
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* Generate TypeScript migration file content
|
|
364
|
+
*/
|
|
365
|
+
function generateMigrationFileContent(migration) {
|
|
366
|
+
const upOperations = JSON.stringify(migration.up, null, 2);
|
|
367
|
+
const downOperations = JSON.stringify(migration.down, null, 2);
|
|
368
|
+
const createdAtStr = migration.createdAt instanceof Date
|
|
369
|
+
? migration.createdAt.toISOString()
|
|
370
|
+
: migration.createdAt;
|
|
371
|
+
return `/**
|
|
372
|
+
* Migration: ${migration.name}
|
|
373
|
+
* Tag: ${migration.tag}
|
|
374
|
+
* Created: ${createdAtStr}
|
|
375
|
+
*/
|
|
376
|
+
|
|
377
|
+
import { IMigrationDefinition } from '@ductape/sdk';
|
|
378
|
+
|
|
379
|
+
export const migration: IMigrationDefinition = {
|
|
380
|
+
tag: '${migration.tag}',
|
|
381
|
+
name: '${migration.name}',
|
|
382
|
+
description: '${migration.description || migration.name}',
|
|
383
|
+
up: ${upOperations},
|
|
384
|
+
down: ${downOperations},
|
|
385
|
+
createdAt: new Date('${createdAtStr}'),
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
export default migration;
|
|
389
|
+
`;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Generate a simple migration template
|
|
393
|
+
*/
|
|
394
|
+
function generateMigrationTemplate(name) {
|
|
395
|
+
const tag = generateMigrationTag(name);
|
|
396
|
+
const timestamp = new Date().toISOString();
|
|
397
|
+
return `/**
|
|
398
|
+
* Migration: ${name}
|
|
399
|
+
* Tag: ${tag}
|
|
400
|
+
* Created: ${timestamp}
|
|
401
|
+
*/
|
|
402
|
+
|
|
403
|
+
import {
|
|
404
|
+
IMigrationDefinition,
|
|
405
|
+
createMigration,
|
|
406
|
+
createTable,
|
|
407
|
+
dropTable,
|
|
408
|
+
addColumn,
|
|
409
|
+
dropColumn,
|
|
410
|
+
addIndex,
|
|
411
|
+
dropIndex,
|
|
412
|
+
SchemaHelpers,
|
|
413
|
+
ColumnType,
|
|
414
|
+
} from '@ductape/sdk';
|
|
415
|
+
|
|
416
|
+
// Define your migration as a simple JSON object
|
|
417
|
+
export const migration: IMigrationDefinition = {
|
|
418
|
+
tag: '${tag}',
|
|
419
|
+
name: '${name}',
|
|
420
|
+
description: 'Description of what this migration does',
|
|
421
|
+
|
|
422
|
+
// Up migration - operations to apply
|
|
423
|
+
up: [
|
|
424
|
+
// Example: Create a table
|
|
425
|
+
// {
|
|
426
|
+
// type: 'create_table',
|
|
427
|
+
// params: {
|
|
428
|
+
// schema: {
|
|
429
|
+
// name: 'users',
|
|
430
|
+
// columns: [
|
|
431
|
+
// { name: 'id', type: ColumnType.INTEGER, primaryKey: true, autoIncrement: true },
|
|
432
|
+
// { name: 'email', type: ColumnType.STRING, length: 255, nullable: false, unique: true },
|
|
433
|
+
// { name: 'name', type: ColumnType.STRING, length: 255 },
|
|
434
|
+
// { name: 'created_at', type: ColumnType.TIMESTAMP, nullable: false, defaultValue: 'CURRENT_TIMESTAMP' },
|
|
435
|
+
// ],
|
|
436
|
+
// },
|
|
437
|
+
// },
|
|
438
|
+
// },
|
|
439
|
+
|
|
440
|
+
// Example: Add a column
|
|
441
|
+
// {
|
|
442
|
+
// type: 'add_column',
|
|
443
|
+
// table: 'users',
|
|
444
|
+
// params: {
|
|
445
|
+
// column: { name: 'phone', type: ColumnType.STRING, length: 20 },
|
|
446
|
+
// },
|
|
447
|
+
// },
|
|
448
|
+
|
|
449
|
+
// Example: Add an index
|
|
450
|
+
// {
|
|
451
|
+
// type: 'add_index',
|
|
452
|
+
// table: 'users',
|
|
453
|
+
// params: {
|
|
454
|
+
// indexName: 'idx_users_email',
|
|
455
|
+
// columns: ['email'],
|
|
456
|
+
// unique: true,
|
|
457
|
+
// },
|
|
458
|
+
// },
|
|
459
|
+
],
|
|
460
|
+
|
|
461
|
+
// Down migration - operations to rollback
|
|
462
|
+
down: [
|
|
463
|
+
// Example: Drop the table
|
|
464
|
+
// {
|
|
465
|
+
// type: 'drop_table',
|
|
466
|
+
// table: 'users',
|
|
467
|
+
// },
|
|
468
|
+
],
|
|
469
|
+
|
|
470
|
+
createdAt: new Date('${timestamp}'),
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
export default migration;
|
|
474
|
+
`;
|
|
475
|
+
}
|
|
476
|
+
//# sourceMappingURL=migration.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.utils.js","sourceRoot":"","sources":["../../../src/database/utils/migration.utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAaH,oDAIC;AAKD,gEAEC;AAKD,0CAcC;AAKD,kCAKC;AAKD,8BAKC;AAKD,8BAMC;AAKD,gCAMC;AAKD,oCAMC;AAKD,oCAMC;AAKD,4BAMC;AAKD,8BAKC;AAKD,sCAUC;AAKD,wCAMC;AAKD,wBAKC;AAKD,oDAEC;AAKD,gDAOC;AAKD,8CASC;AA2MD,oEA2BC;AAKD,8DAkFC;AAhgBD,8DAIkC;AAClC,wDAAoF;AAGpF;;GAEG;AACH,SAAgB,oBAAoB,CAAC,IAAY;IAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;IACrE,OAAO,GAAG,SAAS,IAAI,aAAa,EAAE,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,SAAgB,0BAA0B;IACxC,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAC7B,IAAY,EACZ,EAAyB,EACzB,IAA2B,EAC3B,GAAY;IAEZ,OAAO;QACL,GAAG,EAAE,GAAG,IAAI,oBAAoB,CAAC,IAAI,CAAC;QACtC,IAAI;QACJ,WAAW,EAAE,cAAc,IAAI,EAAE;QACjC,EAAE;QACF,IAAI;QACJ,SAAS,EAAE,IAAI,IAAI,EAAE;KACtB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,WAAW,CAAC,MAAoB;IAC9C,OAAO;QACL,IAAI,EAAE,wCAAsB,CAAC,YAAY;QACzC,MAAM,EAAE,EAAE,M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pB,SAAS,CAAC,GAAG;cACT,YAAY;;;;;;UAMhB,SAAS,CAAC,GAAG;WACZ,SAAS,CAAC,IAAI;kBACP,SAAS,CAAC,WAAW,IAAI,SAAS,CAAC,IAAI;QACjD,YAAY;UACV,cAAc;yBACC,YAAY;;;;CAIpC,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAgB,yBAAyB,CAAC,IAAY;IACpD,MAAM,GAAG,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAE3C,OAAO;gBACO,IAAI;UACV,GAAG;cACC,SAAS;;;;;;;;;;;;;;;;;;UAkBb,GAAG;WACF,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAmDU,SAAS;;;;CAIjC,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction implementation
|
|
3
|
+
* Provides a stable interface for database transactions
|
|
4
|
+
*/
|
|
5
|
+
import { ITransaction, ISavepoint, IConnection, TransactionStatus, TransactionIsolationLevel } from '../types/database.types';
|
|
6
|
+
import { BaseDatabaseAdapter } from '../adapters/base.adapter';
|
|
7
|
+
/**
|
|
8
|
+
* Savepoint implementation
|
|
9
|
+
*/
|
|
10
|
+
export declare class Savepoint implements ISavepoint {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly transaction: ITransaction;
|
|
13
|
+
readonly createdAt: Date;
|
|
14
|
+
private adapter;
|
|
15
|
+
constructor(name: string, transaction: ITransaction, adapter: BaseDatabaseAdapter);
|
|
16
|
+
rollback(): Promise<void>;
|
|
17
|
+
release(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Transaction implementation
|
|
21
|
+
*/
|
|
22
|
+
export declare class Transaction implements ITransaction {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly connection: IConnection;
|
|
25
|
+
status: TransactionStatus;
|
|
26
|
+
readonly isolationLevel?: TransactionIsolationLevel;
|
|
27
|
+
readonly parent?: ITransaction;
|
|
28
|
+
readonly createdAt: Date;
|
|
29
|
+
readonly native: any;
|
|
30
|
+
private adapter;
|
|
31
|
+
private savepoints;
|
|
32
|
+
private savepointCounter;
|
|
33
|
+
constructor(id: string, connection: IConnection, native: any, adapter: BaseDatabaseAdapter, options?: {
|
|
34
|
+
isolationLevel?: TransactionIsolationLevel;
|
|
35
|
+
parent?: ITransaction;
|
|
36
|
+
});
|
|
37
|
+
commit(): Promise<void>;
|
|
38
|
+
rollback(): Promise<void>;
|
|
39
|
+
savepoint(name?: string): Promise<ISavepoint>;
|
|
40
|
+
isActive(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Get a savepoint by name
|
|
43
|
+
*/
|
|
44
|
+
getSavepoint(name: string): ISavepoint | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Get all savepoints
|
|
47
|
+
*/
|
|
48
|
+
getSavepoints(): ISavepoint[];
|
|
49
|
+
/**
|
|
50
|
+
* Remove a savepoint from tracking (after rollback or release)
|
|
51
|
+
*/
|
|
52
|
+
removeSavepoint(name: string): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Transaction factory
|
|
56
|
+
* Creates transaction instances
|
|
57
|
+
*/
|
|
58
|
+
export declare class TransactionFactory {
|
|
59
|
+
private static idCounter;
|
|
60
|
+
static create(connection: IConnection, native: any, adapter: BaseDatabaseAdapter, options?: {
|
|
61
|
+
isolationLevel?: TransactionIsolationLevel;
|
|
62
|
+
parent?: ITransaction;
|
|
63
|
+
}): ITransaction;
|
|
64
|
+
}
|