@@ -51,24 +51,47 @@ def upgrade() -> None:
5151 sa .Column ("research_consent_missing_justifications" , AutoString (), nullable = True ),
5252 )
5353
54+ # explicitly create enums if needed (PostgreSQL)
55+ genomic_study_type_enum = sa .Enum ("single" , "duo" , "trio" , name = "genomicstudytype" )
56+ genomic_study_type_enum .create (op .get_bind ())
57+ genomic_study_subtype_enum = sa .Enum ("tumor_only" , "tumor_germline" , "germline_only" , name = "genomicstudysubtype" )
58+ genomic_study_subtype_enum .create (op .get_bind ())
59+ coverage_type_enum = sa .Enum (
60+ "GKV" , "PKV" , "BG" , "SEL" , "SOZ" , "GPV" , "PPV" , "BEI" , "SKT" , "UNK" , name = "coveragetype"
61+ )
62+ coverage_type_enum .create (op .get_bind ())
63+
5464 # we have to batch alter because SQLite doesn't support ALTER on column types
5565 with op .batch_alter_table ("submissions" ) as batch_op :
5666 # will need to be repopulated in donors table before reporting, so just drop
5767 batch_op .drop_column ("library_type" )
5868 # modified/extra submission table columns
59- batch_op .add_column (sa .Column ("genomic_study_type" , sa . Enum ( "single" , "duo" , "trio" , name = "genomicstudytype" ) ))
69+ batch_op .add_column (sa .Column ("genomic_study_type" , genomic_study_type_enum ))
6070 batch_op .add_column (
6171 sa .Column (
6272 "genomic_study_subtype" ,
63- sa . Enum ( "tumor_only" , "tumor_germline" , "germline_only" , name = "genomicstudysubtype" ) ,
73+ genomic_study_subtype_enum ,
6474 ),
6575 )
66- batch_op .add_column (
67- sa .Column (
68- "coverage_type" ,
69- sa .Enum ("GKV" , "PKV" , "BG" , "SEL" , "SOZ" , "GPV" , "PPV" , "BEI" , "SKT" , "UNK" , name = "coveragetype" ),
70- )
71- )
76+ batch_op .add_column (sa .Column ("coverage_type" , coverage_type_enum ))
77+
78+ # already should exist so don't need to re-create, just define
79+ # but must be postgresql.ENUM until fixed in sqlalchemy 2.1
80+ # see https://github.com/sqlalchemy/alembic/issues/1347
81+ library_type_enum = sa .dialects .postgresql .ENUM (
82+ "panel" ,
83+ "panel_lr" ,
84+ "wes" ,
85+ "wes_lr" ,
86+ "wgs" ,
87+ "wgs_lr" ,
88+ "wxs" ,
89+ "wxs_lr" ,
90+ "other" ,
91+ "unknown" ,
92+ name = "librarytype" ,
93+ create_type = False ,
94+ )
7295
7396 # new detailed QC results table
7497 op .create_table (
@@ -90,19 +113,7 @@ def upgrade() -> None:
90113 ),
91114 sa .Column (
92115 "library_type" ,
93- sa .Enum (
94- "panel" ,
95- "panel_lr" ,
96- "wes" ,
97- "wes_lr" ,
98- "wgs" ,
99- "wgs_lr" ,
100- "wxs" ,
101- "wxs_lr" ,
102- "other" ,
103- "unknown" ,
104- name = "librarytype" ,
105- ),
116+ library_type_enum ,
106117 nullable = False ,
107118 ),
108119 sa .Column ("percent_bases_above_quality_threshold_minimum_quality" , sa .Float (), nullable = False ),
0 commit comments