Skip to content

Commit

Permalink
Merge pull request #808 from jan-stanek/migrations-fix
Browse files Browse the repository at this point in the history
Oprava migrací
  • Loading branch information
msusicky authored Apr 18, 2024
2 parents 126f46b + c488637 commit 53af775
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 58 deletions.
9 changes: 5 additions & 4 deletions migrations/versions/130cce777d35_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
Expand Down Expand Up @@ -42,16 +43,16 @@ def upgrade():
op.create_index(op.f('ix_ockovani_lide_kraj_bydl_nuts'), 'ockovani_lide', ['kraj_bydl_nuts'], unique=False)
op.drop_column('ockovani_lide', 'kraj_nazev')
connection = op.get_bind()
connection.execute("alter table ockovani_lide drop CONSTRAINT ockovani_lide_pkey")
connection.execute("alter table ockovani_lide add CONSTRAINT ockovani_lide_pkey PRIMARY KEY (datum, vakcina, zarizeni_kod, poradi_davky, vekova_skupina, kraj_bydl_nuts, indikace_bezpecnostni_infrastruktura, indikace_chronicke_onemocneni, indikace_ostatni, indikace_pedagog, indikace_skolstvi_ostatni, indikace_socialni_sluzby, indikace_zdravotnik)")
connection.execute(text("alter table ockovani_lide drop CONSTRAINT ockovani_lide_pkey"))
connection.execute(text("alter table ockovani_lide add CONSTRAINT ockovani_lide_pkey PRIMARY KEY (datum, vakcina, zarizeni_kod, poradi_davky, vekova_skupina, kraj_bydl_nuts, indikace_bezpecnostni_infrastruktura, indikace_chronicke_onemocneni, indikace_ostatni, indikace_pedagog, indikace_skolstvi_ostatni, indikace_socialni_sluzby, indikace_zdravotnik)"))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
connection = op.get_bind()
connection.execute("alter table ockovani_lide drop CONSTRAINT ockovani_lide_pkey")
connection.execute("alter table ockovani_lide add CONSTRAINT ockovani_lide_pkey PRIMARY KEY (datum, vakcina, zarizeni_kod, poradi_davky, vekova_skupina)")
connection.execute(text("alter table ockovani_lide drop CONSTRAINT ockovani_lide_pkey"))
connection.execute(text("alter table ockovani_lide add CONSTRAINT ockovani_lide_pkey PRIMARY KEY (datum, vakcina, zarizeni_kod, poradi_davky, vekova_skupina)"))
op.add_column('ockovani_lide', sa.Column('kraj_nazev', sa.VARCHAR(), autoincrement=False, nullable=True))
op.drop_index(op.f('ix_ockovani_lide_kraj_bydl_nuts'), table_name='ockovani_lide')
op.drop_column('ockovani_lide', 'kraj_bydl_nuts')
Expand Down
13 changes: 7 additions & 6 deletions migrations/versions/1ed9516441be_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
Expand All @@ -18,13 +19,13 @@

def upgrade():
connection = op.get_bind()
connection.execute("alter table ockovani_registrace add column ockovani smallint default -1")
connection.execute("alter table ockovani_registrace drop CONSTRAINT ockovani_registrace_part_pkey")
connection.execute("alter table ockovani_registrace add CONSTRAINT ockovani_registrace_part_pkey PRIMARY KEY (datum, ockovaci_misto_id, vekova_skupina, povolani, stat, rezervace, datum_rezervace, import_id, ockovani)")
connection.execute(text("alter table ockovani_registrace add column ockovani smallint default -1"))
connection.execute(text("alter table ockovani_registrace drop CONSTRAINT ockovani_registrace_part_pkey"))
connection.execute(text("alter table ockovani_registrace add CONSTRAINT ockovani_registrace_part_pkey PRIMARY KEY (datum, ockovaci_misto_id, vekova_skupina, povolani, stat, rezervace, datum_rezervace, import_id, ockovani)"))


def downgrade():
connection = op.get_bind()
connection.execute("alter table ockovani_registrace drop column ockovani")
connection.execute("alter table ockovani_registrace drop CONSTRAINT ockovani_registrace_part_pkey")
connection.execute("alter table ockovani_registrace add CONSTRAINT ockovani_registrace_part_pkey PRIMARY KEY (datum, ockovaci_misto_id, vekova_skupina, povolani, stat, rezervace, datum_rezervace, import_id)")
connection.execute(text("alter table ockovani_registrace drop column ockovani"))
connection.execute(text("alter table ockovani_registrace drop CONSTRAINT ockovani_registrace_part_pkey"))
connection.execute(text("alter table ockovani_registrace add CONSTRAINT ockovani_registrace_part_pkey PRIMARY KEY (datum, ockovaci_misto_id, vekova_skupina, povolani, stat, rezervace, datum_rezervace, import_id)"))
18 changes: 9 additions & 9 deletions migrations/versions/5480e96df417_.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
Expand All @@ -18,15 +18,15 @@

def upgrade():
connection = op.get_bind()
connection.execute("DELETE FROM populace_kategorie WHERE vekova_skupina='0-17'")
connection.execute("INSERT INTO populace_kategorie (vekova_skupina,min_vek,max_vek) VALUES ('0-11',0,11)")
connection.execute("INSERT INTO populace_kategorie (vekova_skupina,min_vek,max_vek) VALUES ('12-15',12,15)")
connection.execute("INSERT INTO populace_kategorie (vekova_skupina,min_vek,max_vek) VALUES ('16-17',16,17)")
connection.execute(text("DELETE FROM populace_kategorie WHERE vekova_skupina='0-17'"))
connection.execute(text("INSERT INTO populace_kategorie (vekova_skupina,min_vek,max_vek) VALUES ('0-11',0,11)"))
connection.execute(text("INSERT INTO populace_kategorie (vekova_skupina,min_vek,max_vek) VALUES ('12-15',12,15)"))
connection.execute(text("INSERT INTO populace_kategorie (vekova_skupina,min_vek,max_vek) VALUES ('16-17',16,17)"))


def downgrade():
connection = op.get_bind()
connection.execute("DELETE FROM populace_kategorie WHERE vekova_skupina='0-11'")
connection.execute("DELETE FROM populace_kategorie WHERE vekova_skupina='12-15'")
connection.execute("DELETE FROM populace_kategorie WHERE vekova_skupina='16-17'")
connection.execute("INSERT INTO populace_kategorie (vekova_skupina,min_vek,max_vek) VALUES ('0-17',0,17)")
connection.execute(text("DELETE FROM populace_kategorie WHERE vekova_skupina='0-11'"))
connection.execute(text("DELETE FROM populace_kategorie WHERE vekova_skupina='12-15'"))
connection.execute(text("DELETE FROM populace_kategorie WHERE vekova_skupina='16-17'"))
connection.execute(text("INSERT INTO populace_kategorie (vekova_skupina,min_vek,max_vek) VALUES ('0-17',0,17)"))
3 changes: 2 additions & 1 deletion migrations/versions/6d30bda90e50_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
Expand All @@ -18,7 +19,7 @@

def upgrade():
connection = op.get_bind()
connection.execute("update ockovani_lide set zarizeni_kod=lpad(zarizeni_kod,11,'0')")
connection.execute(text("update ockovani_lide set zarizeni_kod=lpad(zarizeni_kod,11,'0')"))


def downgrade():
Expand Down
7 changes: 4 additions & 3 deletions migrations/versions/b3623a352bec_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
Expand All @@ -18,9 +19,9 @@

def upgrade():
connection = op.get_bind()
connection.execute("INSERT INTO ockovaci_mista (id, nazev, okres_id, status, nrpzs_kod) VALUES('4561f6a6-a019-4fb6-8552-6e15c74a3d04', 'EUC klinika Ostrava', 'CZ0806', false, '25860836000')")
connection.execute("INSERT INTO ockovaci_mista (id, nazev, okres_id, status, nrpzs_kod) VALUES('68fcce7d-b37b-4073-a8a0-c21a62976442', 'VITA, s.r.o.', 'CZ0426', false, '61537713000')")
connection.execute("INSERT INTO ockovaci_mista (id, nazev, okres_id, status, nrpzs_kod) VALUES('9d29801f-7265-47cc-abfc-0167f8f58b2d', 'HNsP Bílina', 'CZ0426', false, '61325422000')")
connection.execute(text("INSERT INTO ockovaci_mista (id, nazev, okres_id, status, nrpzs_kod) VALUES('4561f6a6-a019-4fb6-8552-6e15c74a3d04', 'EUC klinika Ostrava', 'CZ0806', false, '25860836000')"))
connection.execute(text("INSERT INTO ockovaci_mista (id, nazev, okres_id, status, nrpzs_kod) VALUES('68fcce7d-b37b-4073-a8a0-c21a62976442', 'VITA, s.r.o.', 'CZ0426', false, '61537713000')"))
connection.execute(text("INSERT INTO ockovaci_mista (id, nazev, okres_id, status, nrpzs_kod) VALUES('9d29801f-7265-47cc-abfc-0167f8f58b2d', 'HNsP Bílina', 'CZ0426', false, '61325422000')"))

def downgrade():
pass
7 changes: 4 additions & 3 deletions migrations/versions/b8604a1102c8_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
Expand All @@ -18,9 +19,9 @@

def upgrade():
connection = op.get_bind()
connection.execute("update importy set date=start")
connection.execute("delete from importy where status='FAILED'")
connection.execute("delete from importy where id in (select id from importy except select max(id) from importy group by date)")
connection.execute(text("update importy set date=start"))
connection.execute(text("delete from importy where status='FAILED'"))
connection.execute(text("delete from importy where id in (select id from importy except select max(id) from importy group by date)"))

def downgrade():
pass
17 changes: 9 additions & 8 deletions migrations/versions/b8e5763ba835_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
Expand Down Expand Up @@ -35,10 +36,10 @@ def upgrade():
# ### end Alembic commands ###

connection = op.get_bind()
connection.execute("alter table ockovani_registrace add column pred_zavorou boolean default false")
connection.execute("alter table ockovani_registrace add column za_zavorou boolean default false")
connection.execute("alter table ockovani_registrace drop CONSTRAINT ockovani_registrace_part_pkey")
connection.execute("alter table ockovani_registrace add CONSTRAINT ockovani_registrace_part_pkey PRIMARY KEY (datum, ockovaci_misto_id, vekova_skupina, povolani, stat, rezervace, datum_rezervace, import_id, ockovani, pred_zavorou, za_zavorou)")
connection.execute(text("alter table ockovani_registrace add column pred_zavorou boolean default false"))
connection.execute(text("alter table ockovani_registrace add column za_zavorou boolean default false"))
connection.execute(text("alter table ockovani_registrace drop CONSTRAINT ockovani_registrace_part_pkey"))
connection.execute(text("alter table ockovani_registrace add CONSTRAINT ockovani_registrace_part_pkey PRIMARY KEY (datum, ockovaci_misto_id, vekova_skupina, povolani, stat, rezervace, datum_rezervace, import_id, ockovani, pred_zavorou, za_zavorou)"))


def downgrade():
Expand All @@ -58,7 +59,7 @@ def downgrade():
# ### end Alembic commands ###

connection = op.get_bind()
connection.execute("alter table ockovani_registrace drop column pred_zavorou")
connection.execute("alter table ockovani_registrace drop column za_zavorou")
connection.execute("alter table ockovani_registrace drop CONSTRAINT ockovani_registrace_part_pkey")
connection.execute("alter table ockovani_registrace add CONSTRAINT ockovani_registrace_part_pkey PRIMARY KEY (datum, ockovaci_misto_id, vekova_skupina, povolani, stat, rezervace, datum_rezervace, import_id, ockovani)")
connection.execute(text("alter table ockovani_registrace drop column pred_zavorou"))
connection.execute(text("alter table ockovani_registrace drop column za_zavorou"))
connection.execute(text("alter table ockovani_registrace drop CONSTRAINT ockovani_registrace_part_pkey"))
connection.execute(text("alter table ockovani_registrace add CONSTRAINT ockovani_registrace_part_pkey PRIMARY KEY (datum, ockovaci_misto_id, vekova_skupina, povolani, stat, rezervace, datum_rezervace, import_id, ockovani)"))
15 changes: 8 additions & 7 deletions migrations/versions/c703c687dcbf_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
Expand All @@ -34,13 +35,13 @@ def upgrade():
)

connection = op.get_bind()
connection.execute("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('Pfizer', 'Comirnaty', 2)")
connection.execute("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('Moderna', 'COVID-19 Vaccine Moderna', 2)")
connection.execute("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('AstraZeneca', 'VAXZEVRIA', 2)")
connection.execute("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('Janssen', 'COVID-19 Vaccine Janssen', 1)")
connection.execute("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('Novavax', 'Novavax', 2)")
connection.execute("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('CureVac', 'CureVac', 2)")
connection.execute("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('GSK', 'GSK', 2)")
connection.execute(text("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('Pfizer', 'Comirnaty', 2)"))
connection.execute(text("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('Moderna', 'COVID-19 Vaccine Moderna', 2)"))
connection.execute(text("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('AstraZeneca', 'VAXZEVRIA', 2)"))
connection.execute(text("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('Janssen', 'COVID-19 Vaccine Janssen', 1)"))
connection.execute(text("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('Novavax', 'Novavax', 2)"))
connection.execute(text("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('CureVac', 'CureVac', 2)"))
connection.execute(text("INSERT INTO vakciny (vyrobce, vakcina, davky) VALUES('GSK', 'GSK', 2)"))

op.create_foreign_key(None, 'ockovani_distribuce', 'vakciny', ['vyrobce'], ['vyrobce'])
op.create_foreign_key(None, 'ockovani_lide', 'vakciny', ['vakcina'], ['vakcina'])
Expand Down
4 changes: 2 additions & 2 deletions migrations/versions/cb94fb60af8b_.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text
import csv
import urllib
from app.models import ZdravotnickeStredisko
Expand All @@ -23,7 +23,7 @@ def upgrade():

# ### end Alembic commands ###
connection = op.get_bind()
connection.execute("truncate table zdravotnicke_stredisko")
connection.execute(text("truncate table zdravotnicke_stredisko"))

url = "https://nrpzs.uzis.cz/res/file/export/export-2021-10.csv"
response = urllib.request.urlopen(url)
Expand Down
3 changes: 2 additions & 1 deletion migrations/versions/d0ff680fad37_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
Expand All @@ -18,7 +19,7 @@

def upgrade():
connection = op.get_bind()
connection.execute("update praktici_kapacity set adresa=split_part(adresa, ',', 1)")
connection.execute(text("update praktici_kapacity set adresa=split_part(adresa, ',', 1)"))


def downgrade():
Expand Down
5 changes: 3 additions & 2 deletions migrations/versions/dd9f6e3ad7c1_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
Expand All @@ -24,8 +25,8 @@ def upgrade():
sa.PrimaryKeyConstraint('bezregistrace_id', 'cas_mereni')
)
connection = op.get_bind()
connection.execute("truncate table ockovani_lide")
connection.execute("update vakciny set vakcina='Spikevax' where vyrobce='Moderna'")
connection.execute(text("truncate table ockovani_lide"))
connection.execute(text("update vakciny set vakcina='Spikevax' where vyrobce='Moderna'"))


def downgrade():
Expand Down
15 changes: 8 additions & 7 deletions migrations/versions/eb41821d2f4c_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
Expand All @@ -19,21 +20,21 @@
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
connection = op.get_bind()
connection.execute("truncate table ockovani_rezervace")
connection.execute("alter table ockovani_rezervace drop CONSTRAINT if exists ockovani_rezervace_pkey")
connection.execute("alter table ockovani_rezervace drop CONSTRAINT if exists ockovani_rezervace_import_id_fkey")
connection.execute(text("truncate table ockovani_rezervace"))
connection.execute(text("alter table ockovani_rezervace drop CONSTRAINT if exists ockovani_rezervace_pkey"))
connection.execute(text("alter table ockovani_rezervace drop CONSTRAINT if exists ockovani_rezervace_import_id_fkey"))
op.drop_column('ockovani_rezervace', 'import_id')
connection.execute("alter table ockovani_rezervace add CONSTRAINT ockovani_rezervace_pkey PRIMARY KEY (datum, ockovaci_misto_id, kalendar_ockovani)")
connection.execute(text("alter table ockovani_rezervace add CONSTRAINT ockovani_rezervace_pkey PRIMARY KEY (datum, ockovaci_misto_id, kalendar_ockovani)"))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
connection = op.get_bind()
connection.execute("truncate table ockovani_rezervace")
connection.execute("alter table ockovani_rezervace drop CONSTRAINT if exists ockovani_rezervace_pkey")
connection.execute(text("truncate table ockovani_rezervace"))
connection.execute(text("alter table ockovani_rezervace drop CONSTRAINT if exists ockovani_rezervace_pkey"))
op.add_column('ockovani_rezervace', sa.Column('import_id', sa.INTEGER(), autoincrement=False, nullable=False))
op.create_foreign_key('ockovani_rezervace_import_id_fkey', 'ockovani_rezervace', 'importy', ['import_id'], ['id'], ondelete='CASCADE')
connection.execute("alter table ockovani_rezervace add CONSTRAINT ockovani_rezervace_pkey PRIMARY KEY (datum, ockovaci_misto_id, kalendar_ockovani, import_id)")
connection.execute(text("alter table ockovani_rezervace add CONSTRAINT ockovani_rezervace_pkey PRIMARY KEY (datum, ockovaci_misto_id, kalendar_ockovani, import_id)"))

# ### end Alembic commands ###
7 changes: 4 additions & 3 deletions migrations/versions/f238461c71d7_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
Expand Down Expand Up @@ -92,9 +93,9 @@ def upgrade():
op.drop_column('okresy_metriky', 'typ_metriky')
op.drop_column('okresy_metriky', 'hodnota_int')
connection = op.get_bind()
connection.execute("truncate table ockovaci_mista_metriky")
connection.execute("truncate table okresy_metriky")
connection.execute("truncate table kraje_metriky")
connection.execute(text("truncate table ockovaci_mista_metriky"))
connection.execute(text("truncate table okresy_metriky"))
connection.execute(text("truncate table kraje_metriky"))
op.add_column('kraje_metriky', sa.Column('kraj_id', sa.Unicode(), nullable=False))
op.drop_constraint('kraje_metriky_id_fkey', 'kraje_metriky', type_='foreignkey')
op.create_foreign_key(None, 'kraje_metriky', 'kraje', ['kraj_id'], ['id'])
Expand Down
5 changes: 3 additions & 2 deletions migrations/versions/f636a63c48d6_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
Expand Down Expand Up @@ -57,8 +58,8 @@ def upgrade():
op.drop_table('srovnani_ockovani')

connection = op.get_bind()
connection.execute("truncate table ockovani_lide")
connection.execute("update vakciny set vakcina='SPIKEVAX' where vyrobce='Moderna'")
connection.execute(text("truncate table ockovani_lide"))
connection.execute(text("update vakciny set vakcina='SPIKEVAX' where vyrobce='Moderna'"))
# ### end Alembic commands ###


Expand Down

0 comments on commit 53af775

Please sign in to comment.