Browse Source

fix: use update method for soft delete (#8967)

* fix: use update method for soft delete

* fix: remove unnecessary argument

---------

Co-authored-by: mertmit <mertmit99@gmail.com>
pull/8972/head
Raju Udava 5 months ago committed by GitHub
parent
commit
827f9390b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 31
      packages/nocodb/src/models/Source.ts
  2. 2
      packages/nocodb/src/services/sources.service.ts
  3. 1
      packages/nocodb/src/version-upgrader/ncProjectConfigUpgrader.ts

31
packages/nocodb/src/models/Source.ts

@ -111,7 +111,6 @@ export default class Source implements SourceType {
context: NcContext,
sourceId: string,
source: SourceType & {
baseId: string;
meta?: any;
deleted?: boolean;
fk_sql_executor_id?: string;
@ -157,7 +156,7 @@ export default class Source implements SourceType {
// if order is missing (possible in old versions), get next order
if (!oldSource.order && !updateObj.order) {
updateObj.order = await ncMeta.metaGetNextOrder(MetaTable.BASES, {
base_id: source.baseId,
base_id: oldSource.base_id,
});
if (updateObj.order <= 1 && !oldSource.isMeta()) {
@ -179,7 +178,7 @@ export default class Source implements SourceType {
// if order is 1 for non-default source, move it to last
if (oldSource.order <= 1 && !updateObj.order) {
updateObj.order = await ncMeta.metaGetNextOrder(MetaTable.BASES, {
base_id: source.baseId,
base_id: oldSource.base_id,
});
}
}
@ -202,10 +201,7 @@ export default class Source implements SourceType {
await JobsRedis.emitPrimaryCommand(InstanceCommands.RELEASE, sourceId);
}
// call before reorder to update cache
const returnBase = await this.get(context, oldSource.id, false, ncMeta);
return returnBase;
return await this.get(context, oldSource.id, false, ncMeta);
}
static async list(
@ -397,7 +393,7 @@ export default class Source implements SourceType {
ncMeta,
);
if (sources[0].id === this.id && !force) {
if ((sources[0].id === this.id || this.isMeta()) && !force) {
NcError.badRequest('Cannot delete first source');
}
@ -498,20 +494,21 @@ export default class Source implements SourceType {
ncMeta = Noco.ncMeta,
{ force }: { force?: boolean } = {},
) {
const sources = await Source.list(context, { baseId: this.id }, ncMeta);
const sources = await Source.list(
context,
{ baseId: this.base_id },
ncMeta,
);
if (sources[0].id === this.id && !force) {
if ((sources[0].id === this.id || this.isMeta()) && !force) {
NcError.badRequest('Cannot delete first base');
}
await ncMeta.metaUpdate(
context.workspace_id,
context.base_id,
MetaTable.BASES,
{
deleted: true,
},
await Source.updateBase(
context,
this.id,
{ deleted: true, fk_sql_executor_id: null },
ncMeta,
);
await NocoCache.deepDel(

2
packages/nocodb/src/services/sources.service.ts

@ -33,11 +33,9 @@ export class SourcesService {
validatePayload('swagger.json#/components/schemas/BaseReq', param.source);
const baseBody = param.source;
const base = await Base.getWithInfo(context, param.baseId);
const source = await Source.updateBase(context, param.sourceId, {
...baseBody,
type: baseBody.config?.client,
baseId: base.id,
id: param.sourceId,
});

1
packages/nocodb/src/version-upgrader/ncProjectConfigUpgrader.ts

@ -41,7 +41,6 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
source.id,
{
id: source.id,
baseId: source.base_id,
config,
},
ncMeta,

Loading…
Cancel
Save