|
|
@ -8,6 +8,7 @@ import { |
|
|
|
UITypes, |
|
|
|
UITypes, |
|
|
|
} from 'nocodb-sdk'; |
|
|
|
} from 'nocodb-sdk'; |
|
|
|
import { pluralize, singularize } from 'inflection'; |
|
|
|
import { pluralize, singularize } from 'inflection'; |
|
|
|
|
|
|
|
import type { UserType } from 'nocodb-sdk'; |
|
|
|
import type { LinksColumn, LinkToAnotherRecordColumn } from '~/models'; |
|
|
|
import type { LinksColumn, LinkToAnotherRecordColumn } from '~/models'; |
|
|
|
import type { NcContext } from '~/interface/config'; |
|
|
|
import type { NcContext } from '~/interface/config'; |
|
|
|
import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; |
|
|
|
import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; |
|
|
@ -647,7 +648,7 @@ export class MetaDiffsService { |
|
|
|
|
|
|
|
|
|
|
|
async baseMetaDiff( |
|
|
|
async baseMetaDiff( |
|
|
|
context: NcContext, |
|
|
|
context: NcContext, |
|
|
|
param: { baseId: string; sourceId: string }, |
|
|
|
param: { baseId: string; sourceId: string; user: UserType }, |
|
|
|
) { |
|
|
|
) { |
|
|
|
const base = await Base.getWithInfo(context, param.baseId); |
|
|
|
const base = await Base.getWithInfo(context, param.baseId); |
|
|
|
const source = await Source.get(context, param.sourceId); |
|
|
|
const source = await Source.get(context, param.sourceId); |
|
|
@ -662,9 +663,17 @@ export class MetaDiffsService { |
|
|
|
|
|
|
|
|
|
|
|
async syncBaseMeta( |
|
|
|
async syncBaseMeta( |
|
|
|
context: NcContext, |
|
|
|
context: NcContext, |
|
|
|
base: Base, |
|
|
|
{ |
|
|
|
source: Source, |
|
|
|
base, |
|
|
|
|
|
|
|
source, |
|
|
|
throwOnFail = false, |
|
|
|
throwOnFail = false, |
|
|
|
|
|
|
|
user, |
|
|
|
|
|
|
|
}: { |
|
|
|
|
|
|
|
base: Base; |
|
|
|
|
|
|
|
source: Source; |
|
|
|
|
|
|
|
throwOnFail?: boolean; |
|
|
|
|
|
|
|
user: UserType; |
|
|
|
|
|
|
|
}, |
|
|
|
) { |
|
|
|
) { |
|
|
|
if (source.is_meta) { |
|
|
|
if (source.is_meta) { |
|
|
|
if (throwOnFail) NcError.badRequest('Cannot sync meta source'); |
|
|
|
if (throwOnFail) NcError.badRequest('Cannot sync meta source'); |
|
|
@ -711,6 +720,7 @@ export class MetaDiffsService { |
|
|
|
source, |
|
|
|
source, |
|
|
|
), |
|
|
|
), |
|
|
|
type: ModelTypes.TABLE, |
|
|
|
type: ModelTypes.TABLE, |
|
|
|
|
|
|
|
user_id: user.id, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
for (const column of columns) { |
|
|
|
for (const column of columns) { |
|
|
@ -738,6 +748,7 @@ export class MetaDiffsService { |
|
|
|
table_name: table_name, |
|
|
|
table_name: table_name, |
|
|
|
title: getTableNameAlias(table_name, base.prefix, source), |
|
|
|
title: getTableNameAlias(table_name, base.prefix, source), |
|
|
|
type: ModelTypes.VIEW, |
|
|
|
type: ModelTypes.VIEW, |
|
|
|
|
|
|
|
user_id: user.id, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
for (const column of columns) { |
|
|
|
for (const column of columns) { |
|
|
@ -909,7 +920,7 @@ export class MetaDiffsService { |
|
|
|
async metaDiffSync(context: NcContext, param: { baseId: string; req: any }) { |
|
|
|
async metaDiffSync(context: NcContext, param: { baseId: string; req: any }) { |
|
|
|
const base = await Base.getWithInfo(context, param.baseId); |
|
|
|
const base = await Base.getWithInfo(context, param.baseId); |
|
|
|
for (const source of base.sources) { |
|
|
|
for (const source of base.sources) { |
|
|
|
await this.syncBaseMeta(context, base, source); |
|
|
|
await this.syncBaseMeta(context, { base, source, user: param.req.user }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.appHooksService.emit(AppEvents.META_DIFF_SYNC, { |
|
|
|
this.appHooksService.emit(AppEvents.META_DIFF_SYNC, { |
|
|
@ -931,7 +942,12 @@ export class MetaDiffsService { |
|
|
|
const base = await Base.getWithInfo(context, param.baseId); |
|
|
|
const base = await Base.getWithInfo(context, param.baseId); |
|
|
|
const source = await Source.get(context, param.sourceId); |
|
|
|
const source = await Source.get(context, param.sourceId); |
|
|
|
|
|
|
|
|
|
|
|
await this.syncBaseMeta(context, base, source, true); |
|
|
|
await this.syncBaseMeta(context, { |
|
|
|
|
|
|
|
base, |
|
|
|
|
|
|
|
source, |
|
|
|
|
|
|
|
throwOnFail: true, |
|
|
|
|
|
|
|
user: param.req.user, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.appHooksService.emit(AppEvents.META_DIFF_SYNC, { |
|
|
|
this.appHooksService.emit(AppEvents.META_DIFF_SYNC, { |
|
|
|
base, |
|
|
|
base, |
|
|
|