-
Notifications
You must be signed in to change notification settings - Fork 0
/
migration.sql
48 lines (40 loc) · 1.63 KB
/
migration.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
PRAGMA foreign_keys = OFF;
BEGIN EXCLUSIVE TRANSACTION;
CREATE TABLE groups
( id INTEGER PRIMARY KEY
, name TEXT NOT NULL
, created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
);
CREATE TABLE members
( id INTEGER PRIMARY KEY
, group_id INTEGER NOT NULL REFERENCES groups(id) ON DELETE CASCADE
, user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE
, created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
);
CREATE TABLE events_
( id INTEGER PRIMARY KEY
, starts_at TEXT NULL
, title TEXT NOT NULL
, description TEXT NOT NULL
, location_id INTEGER NOT NULL REFERENCES locations(id) ON DELETE RESTRICT
, restrict_to INTEGER NULL REFERENCES groups(id) ON DELETE RESTRICT
, created_by INTEGER NOT NULL REFERENCES users(id) ON DELETE RESTRICT
, created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
);
CREATE TABLE polls_
( id INTEGER PRIMARY KEY
, min_participants INTEGER NOT NULL
, strategy TEXT NOT NULL
, open_until TEXT NOT NULl
, stage TEXT NOT NULL
, event_id INTEGER NOT NULL REFERENCES events(id) ON DELETE CASCADE
, created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
);
INSERT INTO events_ SELECT id, starts_at, title, description, location_id, NULL as restrict_to, created_by, created_at FROM events;
DROP TABLE events;
ALTER TABLE events_ RENAME TO events;
INSERT INTO polls_ SELECT id, min_participants, strategy, open_until, stage, event_id, created_at FROM polls;
DROP TABLE polls;
ALTER TABLE polls_ RENAME TO polls;
PRAGMA foreign_key_check;
COMMIT;