fixed mssql primary key respects column order

This commit is contained in:
SPRINX0\prochazka
2024-11-08 12:13:00 +01:00
parent c750bd04ad
commit 319580554f
7 changed files with 62 additions and 14 deletions

View File

@@ -145,6 +145,10 @@ export function isCollectionInfo(obj: { objectTypeField?: string }): obj is Coll
}
export function filterStructureBySchema(db: DatabaseInfo, schema: string) {
if (!db) {
return db;
}
return {
...db,
tables: (db.tables || []).filter(x => x.schemaName == schema),
@@ -158,6 +162,10 @@ export function filterStructureBySchema(db: DatabaseInfo, schema: string) {
}
export function getSchemasUsedByStructure(db: DatabaseInfo) {
if (!db) {
return db;
}
return _uniq([
...(db.tables || []).map(x => x.schemaName),
...(db.views || []).map(x => x.schemaName),
@@ -168,3 +176,30 @@ export function getSchemasUsedByStructure(db: DatabaseInfo) {
...(db.triggers || []).map(x => x.schemaName),
]);
}
export function replaceSchemaInStructure(db: DatabaseInfo, schema: string) {
if (!db) {
return db;
}
return {
...db,
tables: (db.tables || []).map(tbl => ({
...tbl,
schemaName: schema,
columns: (tbl.columns || []).map(column => ({ ...column, schemaName: schema })),
primaryKey: tbl.primaryKey ? { ...tbl.primaryKey, schemaName: schema } : undefined,
sortingKey: tbl.sortingKey ? { ...tbl.sortingKey, schemaName: schema } : undefined,
foreignKeys: (tbl.foreignKeys || []).map(fk => ({ ...fk, refSchemaName: schema, schemaName: schema })),
indexes: (tbl.indexes || []).map(idx => ({ ...idx, schemaName: schema })),
uniques: (tbl.uniques || []).map(idx => ({ ...idx, schemaName: schema })),
checks: (tbl.checks || []).map(idx => ({ ...idx, schemaName: schema })),
})),
views: (db.views || []).map(x => ({ ...x, schemaName: schema })),
collections: (db.collections || []).map(x => ({ ...x, schemaName: schema })),
matviews: (db.matviews || []).map(x => ({ ...x, schemaName: schema })),
procedures: (db.procedures || []).map(x => ({ ...x, schemaName: schema })),
functions: (db.functions || []).map(x => ({ ...x, schemaName: schema })),
triggers: (db.triggers || []).map(x => ({ ...x, schemaName: schema })),
};
}