From 25a92b6ebcdbc1453a9f8ea4a46dea96c906af71 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 10 Nov 2022 12:19:05 +0300 Subject: Migrations: migration for 'genotype_resources' table * migrations/auth/20221110_04_6PRFQ-create-genotype-resources-table.py: new migration * tests/unit/auth/test_create_table_migrations.py: test new migration --- ...110_04_6PRFQ-create-genotype-resources-table.py | 23 ++++++++++++++++++++++ tests/unit/auth/test_create_table_migrations.py | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 migrations/auth/20221110_04_6PRFQ-create-genotype-resources-table.py diff --git a/migrations/auth/20221110_04_6PRFQ-create-genotype-resources-table.py b/migrations/auth/20221110_04_6PRFQ-create-genotype-resources-table.py new file mode 100644 index 0000000..9200774 --- /dev/null +++ b/migrations/auth/20221110_04_6PRFQ-create-genotype-resources-table.py @@ -0,0 +1,23 @@ +""" +Create 'genotype_resources' table + +NOTE: A "genotype resource" can only ever be linked to one and only one "resource object" + A "resource object" can be linked to one or more "genotype resource". +""" + +from yoyo import step + +__depends__ = {'20221110_03_ka3W0-create-phenotype-resources-table'} + +steps = [ + step( + """ + CREATE TABLE IF NOT EXISTS genotype_resources( + resource_id TEXT NOT NULL, + trait_id TEXT NOT NULL UNIQUE, + PRIMARY KEY(resource_id, trait_id), + FOREIGN KEY(resource_id) REFERENCES resources(resource_id) + ) WITHOUT ROWID + """, + "DROP TABLE IF EXISTS genotype_resources") +] diff --git a/tests/unit/auth/test_create_table_migrations.py b/tests/unit/auth/test_create_table_migrations.py index c84e017..6898d9d 100644 --- a/tests/unit/auth/test_create_table_migrations.py +++ b/tests/unit/auth/test_create_table_migrations.py @@ -17,7 +17,8 @@ migrations_and_tables = ( ("20221108_03_Pbhb1-create-resource-categories-table.py", "resource_categories"), ("20221110_01_WtZ1I-create-resources-table.py", "resources"), ("20221110_02_z1dWf-create-mrna-resources-table.py", "mrna_resources"), - ("20221110_03_ka3W0-create-phenotype-resources-table.py", "phenotype_resources")) + ("20221110_03_ka3W0-create-phenotype-resources-table.py", "phenotype_resources"), + ("20221110_04_6PRFQ-create-genotype-resources-table.py", "genotype_resources"), @pytest.mark.unit_test @pytest.mark.parametrize("migration_file,the_table", migrations_and_tables) -- cgit v1.2.3