|
|
@ -1688,34 +1688,36 @@ export class ColumnsService { |
|
|
|
case UITypes.CreateTime: |
|
|
|
case UITypes.CreateTime: |
|
|
|
case UITypes.LastModifiedTime: |
|
|
|
case UITypes.LastModifiedTime: |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
const columns = await table.getColumns(); |
|
|
|
// check if column already exists, then just create a new column in meta
|
|
|
|
// check if column already exists, then just create a new column in meta
|
|
|
|
// else create a new column in meta and db
|
|
|
|
// else create a new column in meta and db
|
|
|
|
const existingColumn = await table.getColumns().then((col) => { |
|
|
|
const existingColumn = columns.find( |
|
|
|
return col.find( |
|
|
|
|
|
|
|
(c) => c.uidt === colBody.uidt && c.system, |
|
|
|
(c) => c.uidt === colBody.uidt && c.system, |
|
|
|
// ||
|
|
|
|
// ||
|
|
|
|
// c.column_name ===
|
|
|
|
// c.column_name ===
|
|
|
|
// (c.uidt === UITypes.CreateTime ? 'created_at' : 'updated_at'),
|
|
|
|
// (c.uidt === UITypes.CreateTime ? 'created_at' : 'updated_at'),
|
|
|
|
); |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!existingColumn) { |
|
|
|
if (!existingColumn) { |
|
|
|
const sqlClient = await reuseOrSave('sqlClient', reuse, async () => |
|
|
|
let columnName = |
|
|
|
NcConnectionMgrv2.getSqlClient(source), |
|
|
|
colBody.uidt === UITypes.CreateTime ? 'created_at' : 'updated_at'; |
|
|
|
); |
|
|
|
// const sqlClient = await reuseOrSave('sqlClient', reuse, async () =>
|
|
|
|
const dbColumns = ( |
|
|
|
// NcConnectionMgrv2.getSqlClient(source),
|
|
|
|
await sqlClient.columnList({ |
|
|
|
// );
|
|
|
|
tn: table.table_name, |
|
|
|
// const dbColumns = (
|
|
|
|
schema: source.getConfig()?.schema, |
|
|
|
// await sqlClient.columnList({
|
|
|
|
}) |
|
|
|
// tn: table.table_name,
|
|
|
|
)?.data?.list; |
|
|
|
// schema: source.getConfig()?.schema,
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// )?.data?.list;
|
|
|
|
|
|
|
|
|
|
|
|
// todo: check type as well
|
|
|
|
// todo: check type as well
|
|
|
|
const dbColumn = dbColumns.find( |
|
|
|
const dbColumn = columns.find((c) => c.column_name === columnName); |
|
|
|
(c) => |
|
|
|
|
|
|
|
c.column_name === |
|
|
|
if (dbColumn) { |
|
|
|
(c.uidt === UITypes.CreateTime ? 'created_at' : 'updated_at'), |
|
|
|
columnName = getUniqueColumnName(columns, columnName); |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!dbColumn) { |
|
|
|
if (!dbColumn) { |
|
|
|
// create column in db
|
|
|
|
// create column in db
|
|
|
|
|
|
|
|
|
|
|
@ -1752,12 +1754,12 @@ export class ColumnsService { |
|
|
|
system: 1, |
|
|
|
system: 1, |
|
|
|
fk_model_id: table.id, |
|
|
|
fk_model_id: table.id, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
await Column.insert({ |
|
|
|
await Column.insert({ |
|
|
|
...colBody, |
|
|
|
...colBody, |
|
|
|
fk_model_id: table.id, |
|
|
|
fk_model_id: table.id, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
{ |
|
|
|
{ |
|
|
@ -2775,6 +2777,7 @@ export class ColumnsService { |
|
|
|
await Column.update(column.id, colBody); |
|
|
|
await Column.update(column.id, colBody); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async columnsHash(tableId: string) { |
|
|
|
async columnsHash(tableId: string) { |
|
|
|
const table = await Model.getWithInfo({ |
|
|
|
const table = await Model.getWithInfo({ |
|
|
|
id: tableId, |
|
|
|
id: tableId, |
|
|
|