@klapeks/micro-db-utils 0.0.23 → 0.0.24
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.
|
@@ -5,8 +5,8 @@ type SuperMigrationsSQLParam = string | ISQLCommandAdapter | SQLCommandData | (s
|
|
|
5
5
|
export declare class SuperMigrations {
|
|
6
6
|
private static _migrations;
|
|
7
7
|
static get migrationTableName(): string;
|
|
8
|
-
static addRawMigration(dbtype: DatabaseOptions['type'] | 'all', entity: EntitySchema, date: Date | string, sql: SuperMigrationsSQLParam): void;
|
|
9
|
-
static addMigration(entity: EntitySchema, date: Date | string, sql: ISQLCommandAdapter | ISQLCommandAdapter[]): void;
|
|
8
|
+
static addRawMigration(dbtype: DatabaseOptions['type'] | 'all', entity: EntitySchema | string, date: Date | string, sql: SuperMigrationsSQLParam): void;
|
|
9
|
+
static addMigration(entity: EntitySchema | string, date: Date | string, sql: ISQLCommandAdapter | ISQLCommandAdapter[]): void;
|
|
10
10
|
private static runMigrationForTable;
|
|
11
11
|
static runMigrations(dataSource: DataSource): Promise<void>;
|
|
12
12
|
}
|
|
@@ -68,7 +68,7 @@ var SuperMigrations = /** @class */ (function () {
|
|
|
68
68
|
date = new Date(date);
|
|
69
69
|
SuperMigrations._migrations.push({
|
|
70
70
|
dbtype: dbtype == 'all' ? undefined : dbtype,
|
|
71
|
-
table: entity.options.tableName || entity.options.name,
|
|
71
|
+
table: typeof entity === 'string' ? entity : (entity.options.tableName || entity.options.name),
|
|
72
72
|
date: date,
|
|
73
73
|
sql: sql
|
|
74
74
|
});
|
|
@@ -7,4 +7,7 @@ export declare class SQLAlterCommand {
|
|
|
7
7
|
renameColumn(old_name: string, new_name: string): ISQLCommandAdapter;
|
|
8
8
|
addColumn(column: string, type: MicroColumnTypeObject): ISQLCommandAdapter;
|
|
9
9
|
changeColumnType(column: string, type: MicroColumnTypeObject): ISQLCommandAdapter;
|
|
10
|
+
dropPrimaryKey(): ISQLCommandAdapter & {
|
|
11
|
+
toPostgreSQL(): string | Promise<string>;
|
|
12
|
+
};
|
|
10
13
|
}
|
|
@@ -140,6 +140,15 @@ var SQLAlterCommand = /** @class */ (function () {
|
|
|
140
140
|
}); },
|
|
141
141
|
};
|
|
142
142
|
};
|
|
143
|
+
SQLAlterCommand.prototype.dropPrimaryKey = function () {
|
|
144
|
+
var _this = this;
|
|
145
|
+
return {
|
|
146
|
+
toSQLite: function () { return "SELECT 1;"; },
|
|
147
|
+
toMySQL: function () { return "ALTER TABLE `".concat(_this.table, "` DROP PRIMARY KEY;"); },
|
|
148
|
+
toMSSQL: function () { return "\n BEGIN TRANSACTION;\n DECLARE @pkName NVARCHAR(128);\n DECLARE @sql NVARCHAR(MAX);\n\n SELECT @pkName = kc.name\n FROM sys.key_constraints kc\n WHERE kc.parent_object_id = OBJECT_ID('dbo.".concat(_this.table, "')\n AND kc.type = 'PK';\n\n IF @pkName IS NOT NULL\n BEGIN\n SET @sql = N'ALTER TABLE dbo.").concat(_this.table, " DROP CONSTRAINT '\n + QUOTENAME(@pkName);\n\n EXEC sp_executesql @sql;\n END;\n COMMIT TRANSACTION;\n "); },
|
|
149
|
+
toPostgreSQL: function () { return "\n BEGIN;\n DO $$\n DECLARE\n pk_name TEXT;\n BEGIN\n SELECT conname\n INTO pk_name\n FROM pg_constraint\n WHERE conrelid = '".concat(_this.table, "'::regclass\n AND contype = 'p';\n\n IF pk_name IS NOT NULL THEN\n EXECUTE format(\n 'ALTER TABLE ").concat(_this.table, " DROP CONSTRAINT %I',\n pk_name\n );\n END IF;\n END $$;\n COMMIT;\n "); }
|
|
150
|
+
};
|
|
151
|
+
};
|
|
143
152
|
return SQLAlterCommand;
|
|
144
153
|
}());
|
|
145
154
|
exports.SQLAlterCommand = SQLAlterCommand;
|