File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,8 +79,16 @@ def run_migrations_online() -> None:
7979 if "prod" in os .getenv ("PG_HOST" ).lower ():
8080 print ("Connecting to production database for migrations!" )
8181 input ("Press Enter to continue..." )
82- elif "dev" in os .getenv ("PG_HOST" "" ).lower ():
83- print ("Connecting to development database for migrations!" )
82+ elif (
83+ "dev" in os .getenv ("PG_HOST" "" ).lower ()
84+ and "staging" in os .getenv ("PG_DB" "" ).lower ()
85+ ):
86+ print ("Connecting to staging database for migrations!" )
87+ elif (
88+ "dev" in os .getenv ("PG_HOST" "" ).lower ()
89+ and not "staging" in os .getenv ("PG_DB" "" ).lower ()
90+ ):
91+ print ("Connecting to dev database for migrations!" )
8492 else :
8593 print ("Connecting to unknown database for migrations!" )
8694
Original file line number Diff line number Diff line change 99from typing import Sequence , Union
1010
1111import sqlalchemy as sa
12- from sqlalchemy .dialects import postgresql
13-
1412from alembic import op
13+ from sqlalchemy .dialects import postgresql
1514
1615# revision identifiers, used by Alembic.
1716revision : str = "16ff997426d3"
2120
2221
2322def upgrade () -> None :
24- op .drop_index (
23+ op .drop_constraint (
2524 "error_retrieval_document_id_http_error_code_idx" ,
2625 "error_retrieval" ,
26+ type_ = "unique" ,
2727 schema = "document_related" ,
2828 )
2929
Original file line number Diff line number Diff line change 1818
1919
2020def upgrade ():
21+ op .execute ("CREATE SCHEMA IF NOT EXISTS grafana;" )
22+
2123 op .execute (
2224 """
2325 CREATE OR REPLACE VIEW grafana.corpus
@@ -162,6 +164,21 @@ def upgrade():
162164 op .execute (
163165 """
164166CREATE OR REPLACE VIEW grafana.document_latest_state
167+ AS SELECT DISTINCT ON (ps.document_id) ps.id,
168+ ps.document_id,
169+ wd.corpus_id,
170+ wd.lang,
171+ ps.title,
172+ ps.created_at,
173+ ps.operation_order
174+ FROM document_related.process_state ps
175+ JOIN document_related.welearn_document wd ON ps.document_id = wd.id
176+ ORDER BY ps.document_id, ps.operation_order DESC;
177+ """
178+ )
179+ op .execute (
180+ """
181+ CREATE OR REPLACE VIEW grafana.test_document_latest_state
165182AS SELECT DISTINCT ON (ps.document_id) ps.id,
166183 ps.document_id,
167184 wd.corpus_id,
Original file line number Diff line number Diff line change @@ -258,6 +258,7 @@ def upgrade() -> None:
258258 sa .ForeignKeyConstraint (
259259 ["user_id" ],
260260 ["user_related.user_profile.id" ],
261+ name = "message_user_id_fkey" ,
261262 ),
262263 sa .PrimaryKeyConstraint ("id" ),
263264 schema = "user_related" ,
You can’t perform that action at this time.
0 commit comments