aboutsummaryrefslogtreecommitdiff
path: root/migrations
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-09-08 02:25:00 +0300
committerFrederick Muriuki Muriithi2023-09-26 03:44:26 +0300
commitff18444c08b0b4ae8478274d1fd793112971484e (patch)
treeb9963259df8e14111ff70744d74b44447d272d9b /migrations
parent9d519e79f65ff30286e3f763614e6fb632e2c028 (diff)
downloadgn-auth-ff18444c08b0b4ae8478274d1fd793112971484e.tar.gz
Resources refactor: Add `resource_ownership` table
New table to link resources to groups, where relevant.
Diffstat (limited to 'migrations')
-rw-r--r--migrations/auth/20230907_01_pjnxz-refactor-add-resource-ownership-table.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/migrations/auth/20230907_01_pjnxz-refactor-add-resource-ownership-table.py b/migrations/auth/20230907_01_pjnxz-refactor-add-resource-ownership-table.py
new file mode 100644
index 0000000..37fcfe7
--- /dev/null
+++ b/migrations/auth/20230907_01_pjnxz-refactor-add-resource-ownership-table.py
@@ -0,0 +1,32 @@
+"""
+refactor: add resource_ownership table
+"""
+
+from yoyo import step
+
+__depends__ = {'20230410_02_WZqSf-create-mrna-resources-table'}
+
+steps = [
+ step(
+ """
+ CREATE TABLE IF NOT EXISTS resource_ownership(
+ -- This table links resources to groups, where relevant
+ group_id TEXT NOT NULL,
+ resource_id TEXT NOT NULL,
+ PRIMARY KEY(group_id, resource_id),
+ FOREIGN KEY(group_id)
+ REFERENCES groups(group_id)
+ ON UPDATE CASCADE ON DELETE RESTRICT,
+ FOREIGN KEY(resource_id)
+ REFERENCES resources(resource_id)
+ ON UPDATE CASCADE ON DELETE RESTRICT
+ ) WITHOUT ROWID
+ """,
+ "DROP TABLE IF EXISTS resource_ownership"),
+ step(# Copy over data
+ """
+ INSERT INTO resource_ownership
+ SELECT group_id, resource_id FROM resources
+ """
+ )
+]