@@ -16,13 +16,21 @@ export type SampleData = {
16
16
17
17
export async function createDatabase ( executor : Executor ) {
18
18
const schemaVersion = await getSchemaVersion ( executor ) ;
19
- if ( schemaVersion < 0 || schemaVersion > 1 ) {
19
+ if ( schemaVersion < 0 || schemaVersion > 2 ) {
20
20
throw new Error ( "Unexpected schema version: " + schemaVersion ) ;
21
21
}
22
- if ( schemaVersion === 0 ) {
23
- await createSchemaVersion1 ( executor ) ;
22
+
23
+ if ( schemaVersion === 2 ) {
24
+ console . log ( "schemaVersion is 2 - nothing to do" ) ;
25
+ return ;
24
26
}
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 ) ;
26
34
}
27
35
28
36
async function getSchemaVersion ( executor : Executor ) {
@@ -41,9 +49,9 @@ async function getSchemaVersion(executor: Executor) {
41
49
// nanoid's don't include $, so cannot collide with other space ids.
42
50
export const BASE_SPACE_ID = "$base-space-id" ;
43
51
44
- export async function createSchemaVersion1 ( executor : Executor ) {
52
+ export async function createSchema ( executor : Executor ) {
45
53
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 ')` ) ;
47
55
48
56
await executor ( `create table space (
49
57
id text primary key not null,
0 commit comments