diff options
author | Frederick Muriuki Muriithi | 2023-09-12 06:01:05 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-09-26 03:44:28 +0300 |
commit | 6e515bd019c5ac6c4c224cd85805e2c608f41c69 (patch) | |
tree | 479902c4d0cb04c06cff97ed8aa26c81620a7953 /migrations/auth | |
parent | 7cfd3ba3e2bc37f2433301b455b70034690a5683 (diff) | |
download | gn-auth-6e515bd019c5ac6c4c224cd85805e2c608f41c69.tar.gz |
Add a 'system' resource
Add a 'system' resource to allow users to have roles they can use to
act on the system itself.
Diffstat (limited to 'migrations/auth')
-rw-r--r-- | migrations/auth/20230912_01_BxrhE-add-system-resource.py | 39 |
1 files changed, 39 insertions, 0 deletions
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) +] |