29306f749043_alter_conceptvisitlog_concept_id_to_   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4

2 Functions

Rating   Name   Duplication   Size   Complexity  
A upgrade() 0 3 2
A downgrade() 0 8 2
1
"""alter ConceptVisitLog concept_id to string
2
3
Revision ID: 29306f749043
4
Revises: b2a7d7614973
5
Create Date: 2024-07-30 09:12:37.521748
6
7
"""
8
9
from alembic import op
10
import sqlalchemy as sa
11
12
13
# revision identifiers, used by Alembic.
14
revision = '29306f749043'
15
down_revision = 'b2a7d7614973'
16
17
18
def upgrade():
19
    with op.batch_alter_table('concept_visit_log') as batch_op:
20
        batch_op.alter_column('concept_id', type_=sa.String, existing_type=sa.Integer)
21
22
23
def downgrade():
24
    # Drop concept_visit_log which have non-integer concept_id
25
    op.execute(
26
        "DELETE FROM concept_visit_log "
27
        "WHERE cast(cast(concept_id AS INTEGER) AS TEXT) != concept_id"
28
    )
29
    with op.batch_alter_table('concept_visit_log') as batch_op:
30
        batch_op.alter_column('concept_id', type_=sa.Integer, existing_type=sa.String)
31