aboutsummaryrefslogtreecommitdiff
path: root/migrations/auth
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-06-06 15:55:54 -0500
committerFrederick Muriuki Muriithi2024-06-07 10:13:21 -0500
commitbd56f2cdaef1716cf5207911f9facbe80733519c (patch)
tree163c9f888196eb5113c8572f217708baf07eaf85 /migrations/auth
parentf691603a8e7a1700783b2be6f855f30d30f645f1 (diff)
downloadgn-auth-bd56f2cdaef1716cf5207911f9facbe80733519c.tar.gz
migration: Drop `group_roles` db table.
Diffstat (limited to 'migrations/auth')
-rw-r--r--migrations/auth/20240606_03_BY7Us-drop-group-roles-table.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/migrations/auth/20240606_03_BY7Us-drop-group-roles-table.py b/migrations/auth/20240606_03_BY7Us-drop-group-roles-table.py
new file mode 100644
index 0000000..45d689c
--- /dev/null
+++ b/migrations/auth/20240606_03_BY7Us-drop-group-roles-table.py
@@ -0,0 +1,35 @@
+"""
+Drop 'group_roles' table.
+"""
+import sqlite3
+from yoyo import step
+
+__depends__ = {'20240606_02_ubZri-create-resource-roles-table'}
+
+def restore_group_roles(conn):
+ """Restore the `group_roles` table."""
+ conn.row_factory = sqlite3.Row
+ cursor = conn.cursor()
+ cursor.execute(
+ """
+ CREATE TABLE group_roles(
+ group_role_id TEXT PRIMARY KEY,
+ group_id TEXT NOT NULL,
+ role_id TEXT NOT NULL,
+ UNIQUE (group_id, role_id),
+ FOREIGN KEY(group_id) REFERENCES groups(group_id)
+ ON UPDATE CASCADE ON DELETE RESTRICT,
+ FOREIGN KEY(role_id) REFERENCES roles(role_id)
+ ON UPDATE CASCADE ON DELETE RESTRICT
+ ) WITHOUT ROWID
+ """)
+ cursor.execute(
+ """
+ CREATE INDEX idx_tbl_group_roles_cols_group_id
+ ON group_roles(group_id)
+ """)
+ cursor.close()
+
+steps = [
+ step("DROP TABLE IF EXISTS group_roles", restore_group_roles)
+]