Skip to content

Commit

Permalink
Store instance version with schema data, so schema is refreshed when …
Browse files Browse the repository at this point in the history
…instance is upgraded (#333)
  • Loading branch information
jaclarke authored Feb 29, 2024
1 parent 7bc54f7 commit 8bcf0c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
19 changes: 10 additions & 9 deletions shared/studio/state/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const SCHEMA_DATA_VERSION = 8;

export interface StoredSchemaData {
version: number;
migrationId: string | null;
schemaId: string | null;
data: RawIntrospectionResult;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -222,7 +223,7 @@ export class DatabaseState extends Model({
])
);

if (this.migrationId === schemaInfo.migrationId) {
if (this.schemaId === schemaInfo.schemaId) {
return;
}

Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -320,7 +321,7 @@ export class DatabaseState extends Model({
}, new Map<string, Set<string>>()),
};

this.migrationId = schemaInfo.migrationId;
this.schemaId = schemaInfo.schemaId;
this.schemaData = schemaData;
} finally {
this.fetchingSchemaData = false;
Expand Down
8 changes: 4 additions & 4 deletions shared/studio/tabs/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <div className={styles.dashboard} />;
}

if (dbState.migrationId === null) {
if (dbState.schemaId.endsWith("__empty")) {
return <FirstRunDashboard />;
}

Expand Down

0 comments on commit 8bcf0c0

Please sign in to comment.