From 6e515bd019c5ac6c4c224cd85805e2c608f41c69 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 12 Sep 2023 06:01:05 +0300 Subject: Add a 'system' resource Add a 'system' resource to allow users to have roles they can use to act on the system itself. --- .../auth/20230912_01_BxrhE-add-system-resource.py | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 migrations/auth/20230912_01_BxrhE-add-system-resource.py (limited to 'migrations') diff --git a/migrations/auth/20230912_01_BxrhE-add-system-resource.py b/migrations/auth/20230912_01_BxrhE-add-system-resource.py new file mode 100644 index 0000000..66c6461 --- /dev/null +++ b/migrations/auth/20230912_01_BxrhE-add-system-resource.py @@ -0,0 +1,39 @@ +""" +Add 'system' resource. +""" + +import uuid + +import sqlite3 +from yoyo import step + +__depends__ = {'20230907_04_3LnrG-refactor-create-group-resources-table'} + +def add_system_resource(conn): + """Add a system resource.""" + conn.row_factory = sqlite3.Row + cursor = conn.cursor() + cursor.execute( + "SELECT resource_category_id FROM resource_categories " + "WHERE resource_category_key='system'") + category_id = cursor.fetchone()["resource_category_id"] + cursor.execute( + "INSERT INTO " + "resources(resource_id, resource_name, resource_category_id, public) " + "VALUES(?, ?, ?, ?)", + (str(uuid.uuid4()), "GeneNetwork System", category_id, "1")) + +def delete_system_resource(conn): + """Add a system resource.""" + conn.row_factory = sqlite3.Row + cursor = conn.cursor() + cursor.execute( + "SELECT resource_category_id FROM resource_categories " + "WHERE resource_category_key='system'") + category_id = cursor.fetchone()["resource_category_id"] + cursor.execute("DELETE FROM resources WHERE resource_category_id = ?", + (category_id,)) + +steps = [ + step(add_system_resource, delete_system_resource) +] -- cgit v1.2.3