Skip to content

Commit 25468b8

Browse files
authoredAug 27, 2023
chore: Bump schema version. (#156)
1 parent 88d1dda commit 25468b8

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed
 

‎backend/data.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@ export type SampleData = {
1616

1717
export async function createDatabase(executor: Executor) {
1818
const schemaVersion = await getSchemaVersion(executor);
19-
if (schemaVersion < 0 || schemaVersion > 1) {
19+
if (schemaVersion < 0 || schemaVersion > 2) {
2020
throw new Error("Unexpected schema version: " + schemaVersion);
2121
}
22-
if (schemaVersion === 0) {
23-
await createSchemaVersion1(executor);
22+
23+
if (schemaVersion === 2) {
24+
console.log("schemaVersion is 2 - nothing to do");
25+
return;
2426
}
25-
console.log("schemaVersion is 1 - nothing to do");
27+
28+
console.log("creating schema");
29+
await executor("drop schema if exists public cascade");
30+
await executor("create schema public");
31+
await executor("grant all on schema public to postgres");
32+
await executor("grant all on schema public to public");
33+
await createSchema(executor);
2634
}
2735

2836
async function getSchemaVersion(executor: Executor) {
@@ -41,9 +49,9 @@ async function getSchemaVersion(executor: Executor) {
4149
// nanoid's don't include $, so cannot collide with other space ids.
4250
export const BASE_SPACE_ID = "$base-space-id";
4351

44-
export async function createSchemaVersion1(executor: Executor) {
52+
export async function createSchema(executor: Executor) {
4553
await executor(`create table meta (key text primary key, value json)`);
46-
await executor(`insert into meta (key, value) values ('schemaVersion', '1')`);
54+
await executor(`insert into meta (key, value) values ('schemaVersion', '2')`);
4755

4856
await executor(`create table space (
4957
id text primary key not null,

0 commit comments

Comments
 (0)