From 8bcf0c0411ad434fdcfa469dcf624953ef2a6fd4 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Thu, 29 Feb 2024 14:23:36 +0000 Subject: [PATCH] Store instance version with schema data, so schema is refreshed when instance is upgraded (#333) --- shared/studio/state/database.ts | 19 ++++++++++--------- shared/studio/tabs/dashboard/index.tsx | 8 ++++---- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/shared/studio/state/database.ts b/shared/studio/state/database.ts index 86618efb..3f895e8a 100644 --- a/shared/studio/state/database.ts +++ b/shared/studio/state/database.ts @@ -49,7 +49,7 @@ const SCHEMA_DATA_VERSION = 8; export interface StoredSchemaData { version: number; - migrationId: string | null; + schemaId: string | null; data: RawIntrospectionResult; } @@ -110,7 +110,7 @@ export class DatabaseState extends Model({ } @observable - migrationId: string | null | undefined = undefined; + schemaId: string | null = null; @observable.ref schemaData: SchemaData | null = null; @observable @@ -202,14 +202,15 @@ export class DatabaseState extends Model({ } FILTER NOT EXISTS .children).id ), version := sys::get_version(), + versionStr := sys::get_version_as_str(), }`, undefined, {ignoreSessionConfig: true, ignoreForceDatabaseError: true} ) .then(({result}) => ({ - migrationId: (result![0].migrationId[0] ?? null) as - | string - | null, + schemaId: `${result![0].versionStr}__${ + result![0].migrationId[0] ?? "empty" + }`, version: result![0].version as { major: number; minor: number; @@ -222,7 +223,7 @@ export class DatabaseState extends Model({ ]) ); - if (this.migrationId === schemaInfo.migrationId) { + if (this.schemaId === schemaInfo.schemaId) { return; } @@ -235,7 +236,7 @@ export class DatabaseState extends Model({ let rawData: RawIntrospectionResult; if ( - storedSchemaData?.migrationId !== schemaInfo.migrationId || + storedSchemaData?.schemaId !== schemaInfo.schemaId || storedSchemaData.version !== SCHEMA_DATA_VERSION ) { // Directly set loading tab by model name to avoid cyclic dependency @@ -257,7 +258,7 @@ export class DatabaseState extends Model({ } storeSchemaData(this.name, instanceState.instanceId!, { version: SCHEMA_DATA_VERSION, - migrationId: schemaInfo.migrationId, + schemaId: schemaInfo.schemaId, data: rawData, }); } else { @@ -320,7 +321,7 @@ export class DatabaseState extends Model({ }, new Map>()), }; - this.migrationId = schemaInfo.migrationId; + this.schemaId = schemaInfo.schemaId; this.schemaData = schemaData; } finally { this.fetchingSchemaData = false; diff --git a/shared/studio/tabs/dashboard/index.tsx b/shared/studio/tabs/dashboard/index.tsx index 06c9a7c7..6812a93a 100644 --- a/shared/studio/tabs/dashboard/index.tsx +++ b/shared/studio/tabs/dashboard/index.tsx @@ -35,16 +35,16 @@ export const DatabaseDashboard = observer(function DatabaseDashboard() { navigate(`${currentPath[0]}/${tabPath}`); useEffect(() => { - if (dbState.migrationId != undefined) { + if (dbState.schemaId != null) { dbState.updateObjectCount(); } - }, [dbState.migrationId]); + }, [dbState.schemaId]); - if (dbState.migrationId === undefined) { + if (dbState.schemaId == null) { return
; } - if (dbState.migrationId === null) { + if (dbState.schemaId.endsWith("__empty")) { return ; }