From f691603a8e7a1700783b2be6f855f30d30f645f1 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 6 Jun 2024 15:36:11 -0500 Subject: migration: Create `resource_roles` db table --- ...0240606_02_ubZri-create-resource-roles-table.py | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 migrations/auth/20240606_02_ubZri-create-resource-roles-table.py 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 + """) +] -- cgit v1.2.3