diff options
-rw-r--r-- | migrations/auth/20230907_01_pjnxz-refactor-add-resource-ownership-table.py | 32 | ||||
-rw-r--r-- | tests/unit/auth/test_migrations_create_tables.py | 4 |
2 files changed, 35 insertions, 1 deletions
diff --git a/migrations/auth/20230907_01_pjnxz-refactor-add-resource-ownership-table.py b/migrations/auth/20230907_01_pjnxz-refactor-add-resource-ownership-table.py new file mode 100644 index 0000000..37fcfe7 --- /dev/null +++ b/migrations/auth/20230907_01_pjnxz-refactor-add-resource-ownership-table.py @@ -0,0 +1,32 @@ +""" +refactor: add resource_ownership table +""" + +from yoyo import step + +__depends__ = {'20230410_02_WZqSf-create-mrna-resources-table'} + +steps = [ + step( + """ + CREATE TABLE IF NOT EXISTS resource_ownership( + -- This table links resources to groups, where relevant + group_id TEXT NOT NULL, + resource_id TEXT NOT NULL, + PRIMARY KEY(group_id, resource_id), + FOREIGN KEY(group_id) + REFERENCES groups(group_id) + ON UPDATE CASCADE ON DELETE RESTRICT, + FOREIGN KEY(resource_id) + REFERENCES resources(resource_id) + ON UPDATE CASCADE ON DELETE RESTRICT + ) WITHOUT ROWID + """, + "DROP TABLE IF EXISTS resource_ownership"), + step(# Copy over data + """ + INSERT INTO resource_ownership + SELECT group_id, resource_id FROM resources + """ + ) +] diff --git a/tests/unit/auth/test_migrations_create_tables.py b/tests/unit/auth/test_migrations_create_tables.py index bd0164e..eb0e161 100644 --- a/tests/unit/auth/test_migrations_create_tables.py +++ b/tests/unit/auth/test_migrations_create_tables.py @@ -39,7 +39,9 @@ migrations_and_tables = ( ("20230404_02_la33P-create-genotype-resources-table.py", "genotype_resources"), ("20230410_01_8mwaf-create-linked-mrna-data-table.py", "linked_mrna_data"), - ("20230410_02_WZqSf-create-mrna-resources-table.py", "mrna_resources")) + ("20230410_02_WZqSf-create-mrna-resources-table.py", "mrna_resources"), + ("20230907_01_pjnxz-refactor-add-resource-ownership-table.py", + "resource_ownership")) @pytest.mark.unit_test @pytest.mark.parametrize("migration_file,the_table", migrations_and_tables) |