snapshot of https://github.com/raimohanska/ourboard.git (master, 2026-09-23; blobs > 131072B omitted)
This commit is contained in:
16
backend/migrations/001_init.js
Normal file
16
backend/migrations/001_init.js
Normal file
@@ -0,0 +1,16 @@
|
||||
exports.up = (pgm) => {
|
||||
pgm.sql(`
|
||||
CREATE TABLE IF NOT EXISTS board (id text PRIMARY KEY, name text NOT NULL);
|
||||
ALTER TABLE board ADD COLUMN IF NOT EXISTS content JSONB NOT NULL;
|
||||
ALTER TABLE board ADD COLUMN IF NOT EXISTS history JSONB NOT NULL default '[]';
|
||||
CREATE TABLE IF NOT EXISTS board_event (board_id text REFERENCES board(id), last_serial integer, events JSONB NOT NULL, PRIMARY KEY (board_id, last_serial));
|
||||
ALTER TABLE board_event ALTER COLUMN last_serial SET NOT NULL;
|
||||
ALTER TABLE board_event ALTER COLUMN board_id SET NOT NULL;
|
||||
CREATE TABLE IF NOT EXISTS board_api_token (board_id text REFERENCES board(id), token TEXT NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS app_user (id text PRIMARY KEY, email text NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS user_board (user_id text REFERENCES app_user(id), board_id text REFERENCES board(id), last_opened TIMESTAMP NOT NULL, PRIMARY KEY (user_id, board_id));
|
||||
ALTER TABLE board ADD COLUMN IF NOT EXISTS ws_host TEXT NULL;
|
||||
ALTER TABLE board ADD COLUMN IF NOT EXISTS created_at TIMESTAMP NULL DEFAULT now();
|
||||
ALTER TABLE board_event ADD COLUMN IF NOT EXISTS saved_at TIMESTAMP NULL DEFAULT now();
|
||||
`)
|
||||
}
|
||||
7
backend/migrations/002_add_first_serial.js
Normal file
7
backend/migrations/002_add_first_serial.js
Normal file
@@ -0,0 +1,7 @@
|
||||
exports.up = (pgm) => {
|
||||
pgm.sql(`
|
||||
ALTER TABLE board_event ADD COLUMN IF NOT EXISTS first_serial int;
|
||||
UPDATE board_event SET first_serial = COALESCE(CAST(events#>'{events, 0, serial}' as int), 0);
|
||||
ALTER TABLE board_event ALTER COLUMN first_serial SET NOT NULL;
|
||||
`)
|
||||
}
|
||||
27
backend/migrations/003_refactor_access.sql
Normal file
27
backend/migrations/003_refactor_access.sql
Normal file
@@ -0,0 +1,27 @@
|
||||
alter table board add public_read boolean null;
|
||||
alter table board add public_write boolean null;
|
||||
create table board_access (
|
||||
board_id text not null references board(id),
|
||||
domain text null,
|
||||
email text null,
|
||||
access text null
|
||||
);
|
||||
|
||||
with allow_json as (
|
||||
select id, jsonb_array_elements(content -> 'accessPolicy' -> 'allowList') as e
|
||||
from board),
|
||||
|
||||
allow_entry as (
|
||||
select id, e ->> 'domain' as domain, e ->> 'email' as email, e ->> 'access' as access
|
||||
from allow_json
|
||||
)
|
||||
|
||||
insert into board_access(board_id, domain, email, access) (
|
||||
select ae.id as board_id, ae.domain, ae.email, ae.access
|
||||
from allow_entry ae
|
||||
);
|
||||
|
||||
update board
|
||||
set public_read = coalesce(content -> 'accessPolicy' ->> 'publicRead', 'false') :: boolean,
|
||||
public_write = coalesce(content -> 'accessPolicy' ->> 'publicWrite', 'false') :: boolean
|
||||
where content -> 'accessPolicy' is not null
|
||||
4
backend/migrations/004_public_boards_access.sql
Normal file
4
backend/migrations/004_public_boards_access.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
update board
|
||||
set public_read = 't',
|
||||
public_write = 't'
|
||||
where content -> 'accessPolicy' is null
|
||||
1
backend/migrations/005_uuid_extension.sql
Normal file
1
backend/migrations/005_uuid_extension.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
1
backend/migrations/006_unique_email.sql
Normal file
1
backend/migrations/006_unique_email.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE app_user ADD CONSTRAINT unique_email UNIQUE (email);
|
||||
1
backend/migrations/007_add_crdt_update.sql
Normal file
1
backend/migrations/007_add_crdt_update.sql
Normal file
@@ -0,0 +1 @@
|
||||
alter table board_event add column crdt_update bytea null;
|
||||
2
backend/migrations/008_allow_crdt_only_bundle.sql
Normal file
2
backend/migrations/008_allow_crdt_only_bundle.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
alter table board_event alter column first_serial drop not null;
|
||||
alter table board_event add constraint first_serial_or_crdt check (crdt_update is not null OR first_serial is not null);
|
||||
2
backend/migrations/009_drop_board_event_primary_key.sql
Normal file
2
backend/migrations/009_drop_board_event_primary_key.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE board_event DROP CONSTRAINT board_event_pkey;
|
||||
CREATE INDEX board_event_board_index ON board_event (board_id);
|
||||
1
backend/migrations/010_drop_history_column.sql
Normal file
1
backend/migrations/010_drop_history_column.sql
Normal file
@@ -0,0 +1 @@
|
||||
alter table board drop column history;
|
||||
Reference in New Issue
Block a user