Browse Source

fix: mm table deletion

pull/7434/head
mertmit 10 months ago
parent
commit
745c673de4
  1. 21
      packages/nocodb/src/db/sql-client/lib/pg/PgClient.ts
  2. 5
      packages/nocodb/src/services/columns.service.ts
  3. 3
      packages/nocodb/src/services/tables.service.ts

21
packages/nocodb/src/db/sql-client/lib/pg/PgClient.ts

@ -965,28 +965,13 @@ class PGClient extends KnexClient {
f.attnotnull as rqd, f.attnotnull as rqd,
p.contype as cst, p.contype as cst,
p.conname as cstn, p.conname as cstn,
ix.indisprimary as primarykey,
not ix.indisunique as non_unique_original,
not ix.indisunique as non_unique,
CASE CASE
WHEN i.oid<>0 THEN true WHEN i.oid<>0 THEN true
ELSE false ELSE false
END AS is_index, END AS is_index,
CASE
WHEN p.contype = 'p' THEN true
ELSE false
END AS primarykey,
CASE
WHEN p.contype = 'u' THEN 0
WHEN p.contype = 'p' THEN 0
ELSE 1
END AS non_unique_original,
CASE
WHEN p.contype = 'p' THEN true
ELSE false
END AS primarykey,
CASE
WHEN p.contype = 'u' THEN 0
WHEN p.contype = 'p' THEN 0
ELSE 1
END AS non_unique,
CASE CASE
WHEN f.atthasdef = 't' THEN pg_get_expr(d.adbin, d.adrelid) WHEN f.atthasdef = 't' THEN pg_get_expr(d.adbin, d.adrelid)
END AS default FROM pg_attribute f END AS default FROM pg_attribute f

5
packages/nocodb/src/services/columns.service.ts

@ -2059,6 +2059,7 @@ export class ColumnsService {
req?: any; req?: any;
columnId: string; columnId: string;
user: UserType; user: UserType;
forceDeleteSystem?: boolean;
reuse?: ReusableParams; reuse?: ReusableParams;
}, },
ncMeta = this.metaService, ncMeta = this.metaService,
@ -2067,7 +2068,7 @@ export class ColumnsService {
const column = await Column.get({ colId: param.columnId }, ncMeta); const column = await Column.get({ colId: param.columnId }, ncMeta);
if (column.system) { if (column.system && !param.forceDeleteSystem) {
NcError.badRequest( NcError.badRequest(
`The column '${ `The column '${
column.title || column.column_name column.title || column.column_name
@ -2424,7 +2425,7 @@ export class ColumnsService {
...index, ...index,
tn: cTable.table_name, tn: cTable.table_name,
columns: [childColumn.column_name], columns: [childColumn.column_name],
indexName: index.index_name, indexName: index.key_name,
}); });
} }
} }

3
packages/nocodb/src/services/tables.service.ts

@ -202,7 +202,7 @@ export class TablesService {
// delete all relations // delete all relations
for (const c of relationColumns) { for (const c of relationColumns) {
// skip if column is hasmany relation to mm table // skip if column is hasmany relation to mm table
if (c.system) { if (c.system && !table.mm) {
continue; continue;
} }
@ -216,6 +216,7 @@ export class TablesService {
req: param.req, req: param.req,
columnId: c.id, columnId: c.id,
user: param.user, user: param.user,
forceDeleteSystem: true,
}, },
ncMeta, ncMeta,
); );

Loading…
Cancel
Save