Browse Source

Merge pull request #1050 from nocodb/fix/meta-sync

fix: handle meta sync properly and keep proper column metadata
pull/1053/head
աɨռɢӄաօռɢ 3 years ago committed by GitHub
parent
commit
621943f424
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 43
      packages/nc-gui/components/project/projectMetadata/sync/disableOrEnableTables.vue
  2. 10
      packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts
  3. 5
      packages/nocodb/src/lib/noco/common/handlers/xcMetaDiffSync.ts
  4. 15
      packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts
  5. 9
      packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts

43
packages/nc-gui/components/project/projectMetadata/sync/disableOrEnableTables.vue

@ -200,7 +200,7 @@
<div class="d-flex"> <div class="d-flex">
<v-spacer /> <v-spacer />
<v-tooltip bottom> <!-- <v-tooltip bottom>-->
<!-- template #activator="{on}"> <!-- template #activator="{on}">
<v-alert <v-alert
v-if="isNewOrDeletedModelFound" v-if="isNewOrDeletedModelFound"
@ -232,35 +232,32 @@
Metadata for API creation & management isn't sync with Metadata for API creation & management isn't sync with
'{{ dbAliasList[dbsTab].connection.database }}' Database. '{{ dbAliasList[dbsTab].connection.database }}' Database.
</template--> </template-->
</v-tooltip> <!-- </v-tooltip>-->
<v-spacer /> <v-spacer />
</div> </div>
<!-- <div--> <!-- <div-->
<!-- v-if="isNewOrDeletedModelFound" --> <!-- v-if="isNewOrDeletedModelFound" -->
<div class="d-flex justify-center"> <div class="d-flex justify-center">
<!-- <x-btn <v-btn
v-if="isChanged"
x-large x-large
btn.class="mx-auto primary nc-btn-sync-meta-data" class="mx-auto primary nc-btn-metasync-sync-now"
tooltip="Sync metadata" @click="syncMetaDiff"
@click="syncMetadata"
> >
<v-icon color="white" class="mr-2 mt-n1"> <v-icon color="white" class="mr-2 mt-n1">
mdi-database-sync mdi-database-sync
</v-icon> </v-icon>
Sync Now Sync Now
</x-btn>--> </v-btn>
<x-btn <v-alert
x-large v-else
btn.class="mx-auto primary nc-btn-metasync-sync-now" dense
tooltip="Sync metadata" outlined
@click="syncMetaDiff" type="success"
> >
<v-icon color="white" class="mr-2 mt-n1"> Tables metadata is in sync
mdi-database-sync </v-alert>
</v-icon>
Sync Now
</x-btn>
</div> </div>
</v-col> </v-col>
</v-row> </v-row>
@ -270,17 +267,12 @@
<script> <script>
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
// import { isMetaTable } from '@/helpers/xutils'
import XIcon from '@/components/global/xIcon'
import XBtn from '@/components/global/xBtn'
import viewIcons from '~/helpers/viewIcons' import viewIcons from '~/helpers/viewIcons'
import XBtn from '~/components/global/xBtn'
export default { export default {
name: 'DisableOrEnableTables', name: 'DisableOrEnableTables',
components: { components: { XBtn },
XBtn,
XIcon
},
props: ['nodes', 'db'], props: ['nodes', 'db'],
data: () => ({ data: () => ({
viewIcons, viewIcons,
@ -425,6 +417,9 @@ export default {
...mapGetters({ ...mapGetters({
dbAliasList: 'project/GtrDbAliasList' dbAliasList: 'project/GtrDbAliasList'
}), }),
isChanged() {
return this.diff && this.diff.some(d => d && d.detectedChanges && d.detectedChanges.length)
},
prefix() { prefix() {
return this.$store.getters['project/GtrProjectPrefix'] || '' return this.$store.getters['project/GtrProjectPrefix'] || ''
} }

10
packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts

@ -726,6 +726,9 @@ export default abstract class BaseApiBuilder<T extends Noco>
this.baseLog(`onTableUpdate : Getting old model meta for '%s'`, tn); this.baseLog(`onTableUpdate : Getting old model meta for '%s'`, tn);
XcCache.del([this.projectId, this.dbAlias, 'table', tn].join('::')); XcCache.del([this.projectId, this.dbAlias, 'table', tn].join('::'));
// get columns list from db
const columnsFromDb = await this.getColumnList(tn);
const relationTableMetas: Set<any> = new Set(); const relationTableMetas: Set<any> = new Set();
const oldModelRow = await this.xcMeta.metaGet( const oldModelRow = await this.xcMeta.metaGet(
@ -752,8 +755,11 @@ export default abstract class BaseApiBuilder<T extends Noco>
const columns = const columns =
changeObj.columns changeObj.columns
.filter(c => c.altered !== 4) .filter(c => c.altered !== 4)
.map(({ altered: _al, ...rest }) => rest) || .map(({ altered: _al, ...rest }) => ({
(await this.getColumnList(tn)); ...rest,
// find and overwrite column property from db
...(columnsFromDb?.find(c => c.cn === rest.cn) || {})
})) || (await this.getColumnList(tn));
/* Get all relations */ /* Get all relations */
const relations = await this.relationsSyncAndGet(); const relations = await this.relationsSyncAndGet();

5
packages/nocodb/src/lib/noco/common/handlers/xcMetaDiffSync.ts

@ -785,8 +785,13 @@ if (sIndex > -1) {
populateParams.tableNames = populateParams.tableNames?.filter(t => { populateParams.tableNames = populateParams.tableNames?.filter(t => {
return t === populateParams.tableNames.find(t1 => t1.tn === t.tn); return t === populateParams.tableNames.find(t1 => t1.tn === t.tn);
}); });
// invoke only if there is change in at least one table
if (populateParams.tableNames?.length) {
await this.xcTablesPopulate(populateParams); await this.xcTablesPopulate(populateParams);
} else if (populateViewsParams.tableNames?.length) {
await this.xcTablesPopulate(populateViewsParams); await this.xcTablesPopulate(populateViewsParams);
}
if (this instanceof GqlApiBuilder) { if (this instanceof GqlApiBuilder) {
await (this as GqlApiBuilder).reInitializeGraphqlEndpoint(); await (this as GqlApiBuilder).reInitializeGraphqlEndpoint();

15
packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts

@ -190,9 +190,18 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
await super.onTableCreate(tn, args); await super.onTableCreate(tn, args);
const columns = { // get columns list from db
[tn]: args?.columns?.map(({ altered: _al, ...rest }) => rest) const columnsFromDb = await this.getColumnList(tn);
};
const columns = args.columns
? {
[tn]: args.columns?.map(({ altered: _al, ...rest }) => ({
...rest,
// find and overwrite column property from db
...columnsFromDb?.find(c => c.cn === rest.cn)
}))
}
: {};
await this.xcTablesPopulate({ await this.xcTablesPopulate({
tableNames: [{ tn, _tn: args._tn }], tableNames: [{ tn, _tn: args._tn }],

9
packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts

@ -876,9 +876,16 @@ export class RestApiBuilder extends BaseApiBuilder<Noco> {
): Promise<void> { ): Promise<void> {
await super.onTableCreate(tn, args); await super.onTableCreate(tn, args);
// get columns list from db
const columnsFromDb = await this.getColumnList(tn);
const columns = args.columns const columns = args.columns
? { ? {
[tn]: args.columns?.map(({ altered: _al, ...rest }) => rest) [tn]: args.columns?.map(({ altered: _al, ...rest }) => ({
...rest,
// find and overwrite column property from db
...(columnsFromDb?.find(c => c.cn === rest.cn) || {})
}))
} }
: {}; : {};

Loading…
Cancel
Save