about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--migrations/auth/20240606_02_ubZri-create-resource-roles-table.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/migrations/auth/20240606_02_ubZri-create-resource-roles-table.py b/migrations/auth/20240606_02_ubZri-create-resource-roles-table.py
new file mode 100644
index 0000000..0695c0e
--- /dev/null
+++ b/migrations/auth/20240606_02_ubZri-create-resource-roles-table.py
@@ -0,0 +1,36 @@
+"""
+Create 'resource_roles' table.
+"""
+
+from yoyo import step
+
+__depends__ = {'20240606_01_xQDwL-move-role-manipulation-privileges-from-group-to-resources'}
+
+steps = [
+    step(
+        """
+        CREATE TABLE IF NOT EXISTS resource_roles(
+          resource_id TEXT NOT NULL,
+          role_created_by TEXT NOT NULL,
+          role_id TEXT NOT NULL,
+          PRIMARY KEY (resource_id, role_created_by, role_id),
+          FOREIGN KEY(resource_id) REFERENCES resources(resource_id)
+            ON UPDATE CASCADE ON DELETE RESTRICT,
+          FOREIGN KEY(role_created_by) REFERENCES users(user_id)
+            ON UPDATE CASCADE ON DELETE RESTRICT,
+          FOREIGN KEY(role_id) REFERENCES roles(role_id)
+            ON UPDATE CASCADE ON DELETE RESTRICT
+        ) WITHOUT ROWID
+        """,
+        "DROP TABLE IF EXISTS resource_roles"),
+    step(
+        """
+        CREATE INDEX IF NOT EXISTS
+        tbl_resource_roles_cols_resource_id_role_created_by
+        ON resource_roles(resource_id, role_created_by)
+        """,
+        """
+        DROP INDEX IF EXISTS
+        tbl_resource_roles_cols_resource_id_role_created_by
+        """)
+]