11
11
12
12
import sqlalchemy as sa
13
13
from sqlalchemy import schema
14
- from sqlalchemy .engine .reflection import Inspector
15
14
16
15
from alembic import op
17
16
from app .config import QUERIES_DIR
26
25
27
26
def upgrade ():
28
27
conn = op .get_bind ()
29
- inspector = Inspector .from_engine (conn )
30
- tables = inspector .get_table_names ()
31
28
32
29
# skip the following tables:
33
30
# - hobolink
@@ -36,44 +33,53 @@ def upgrade():
36
33
# - model_outputs
37
34
# These are rewritten each time; their data doesn't need to be persisted.
38
35
39
- if "boathouses" not in tables :
40
- op .execute (schema .CreateSequence (schema .Sequence ("boathouses_id_seq" )))
41
- op .create_table (
42
- "boathouses" ,
43
- sa .Column (
44
- "id" ,
45
- sa .Integer (),
46
- autoincrement = True ,
47
- nullable = False ,
48
- server_default = sa .text ("nextval('boathouses_id_seq'::regclass)" ),
49
- ),
50
- sa .Column ("boathouse" , sa .String (length = 255 ), nullable = False ),
51
- sa .Column ("reach" , sa .Integer (), nullable = True ),
52
- sa .Column ("latitude" , sa .Numeric (), nullable = True ),
53
- sa .Column ("longitude" , sa .Numeric (), nullable = True ),
54
- sa .Column ("overridden" , sa .Boolean (), nullable = True ),
55
- sa .Column ("reason" , sa .String (length = 255 ), nullable = True ),
56
- sa .PrimaryKeyConstraint ("boathouse" ),
57
- )
58
- with open (QUERIES_DIR + "/override_event_triggers_v1.sql" , "r" ) as f :
59
- sql = sa .text (f .read ())
60
- conn .execute (sql )
61
- if "live_website_options" not in tables :
62
- op .create_table (
63
- "live_website_options" ,
64
- sa .Column ("id" , sa .Integer (), nullable = False ),
65
- sa .Column ("flagging_message" , sa .Text (), nullable = True ),
66
- sa .Column ("boating_season" , sa .Boolean (), nullable = False ),
67
- sa .PrimaryKeyConstraint ("id" ),
68
- )
69
- if "override_history" not in tables :
70
- op .create_table (
71
- "override_history" ,
72
- sa .Column ("time" , sa .TIMESTAMP (), nullable = True ),
73
- sa .Column ("boathouse" , sa .TEXT (), nullable = True ),
74
- sa .Column ("overridden" , sa .BOOLEAN (), nullable = True ),
75
- sa .Column ("reason" , sa .TEXT (), nullable = True ),
76
- )
36
+ op .execute (schema .CreateSequence (schema .Sequence ("boathouses_id_seq" )))
37
+ op .create_table (
38
+ "boathouses" ,
39
+ sa .Column (
40
+ "id" ,
41
+ sa .Integer (),
42
+ autoincrement = True ,
43
+ nullable = False ,
44
+ server_default = sa .text ("nextval('boathouses_id_seq'::regclass)" ),
45
+ ),
46
+ sa .Column ("boathouse" , sa .String (length = 255 ), nullable = False ),
47
+ sa .Column ("reach" , sa .Integer (), nullable = True ),
48
+ sa .Column ("latitude" , sa .Numeric (), nullable = True ),
49
+ sa .Column ("longitude" , sa .Numeric (), nullable = True ),
50
+ sa .Column ("overridden" , sa .Boolean (), nullable = True ),
51
+ sa .Column ("reason" , sa .String (length = 255 ), nullable = True ),
52
+ sa .PrimaryKeyConstraint ("boathouse" ),
53
+ )
54
+
55
+ with open (f"{ QUERIES_DIR } /override_event_triggers_v1.sql" , "r" ) as f :
56
+ sql = sa .text (f .read ())
57
+ conn .execute (sql )
58
+
59
+ op .create_table (
60
+ "live_website_options" ,
61
+ sa .Column ("id" , sa .Integer (), nullable = False ),
62
+ sa .Column ("flagging_message" , sa .Text (), nullable = True ),
63
+ sa .Column ("boating_season" , sa .Boolean (), nullable = False ),
64
+ sa .PrimaryKeyConstraint ("id" ),
65
+ )
66
+ op .create_table (
67
+ "override_history" ,
68
+ sa .Column ("time" , sa .TIMESTAMP (), nullable = True ),
69
+ sa .Column ("boathouse" , sa .TEXT (), nullable = True ),
70
+ sa .Column ("overridden" , sa .BOOLEAN (), nullable = True ),
71
+ sa .Column ("reason" , sa .TEXT (), nullable = True ),
72
+ )
73
+
74
+ with open (f"{ QUERIES_DIR } /define_reach.sql" , "r" ) as f :
75
+ sql = sa .text (f .read ())
76
+ conn .execute (sql )
77
+ with open (f"{ QUERIES_DIR } /define_boathouse.sql" , "r" ) as f :
78
+ sql = sa .text (f .read ())
79
+ conn .execute (sql )
80
+ with open (f"{ QUERIES_DIR } /define_default_options.sql" , "r" ) as f :
81
+ sql = sa .text (f .read ())
82
+ conn .execute (sql )
77
83
78
84
79
85
def downgrade ():
0 commit comments