<reponame>kokes/ockovani-covid<filename>migrations/versions/bc40d86be5e9_.py
"""empty message

Revision ID: <KEY>
Revises: <PASSWORD>
Create Date: 2021-03-17 20:59:27.391819

"""
from alembic import op
import sqlalchemy as sa
import csv
from app.models import PopulaceKategorie



# revision identifiers, used by Alembic.
revision = '<KEY>'
down_revision = 'db2b53362b1c'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('populace_kategorie',
    sa.Column('vekova_skupina', sa.Unicode(), nullable=False),
    sa.Column('min_vek', sa.Integer(), nullable=True),
    sa.Column('max_vek', sa.Integer(), nullable=True),
    sa.PrimaryKeyConstraint('vekova_skupina')
    )
    # ### end Alembic commands ###

    with open('data/populace_kategorie.csv', mode='r', encoding='utf-8') as populace_file:
        reader = csv.reader(populace_file, delimiter=';')
        next(reader, None)
        populace_arr = [{'vekova_skupina': row[0], 'min_vek': row[1], 'max_vek': row[2] } for row in reader]

    # print(populace_arr)

    op.bulk_insert(PopulaceKategorie.__table__, populace_arr)


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('populace_kategorie')
    # ### end Alembic commands ###

"""empty message

Revision ID: <KEY>
Revises: <PASSWORD>
Create Date: 2021-03-17 20:59:27.391819

"""
from alembic import op
import sqlalchemy as sa
import csv
from app.models import PopulaceKategorie



# revision identifiers, used by Alembic.
revision = '<KEY>'
down_revision = 'db2b53362b1c'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('populace_kategorie',
    sa.Column('vekova_skupina', sa.Unicode(), nullable=False),
    sa.Column('min_vek', sa.Integer(), nullable=True),
    sa.Column('max_vek', sa.Integer(), nullable=True),
    sa.PrimaryKeyConstraint('vekova_skupina')
    )
    # ### end Alembic commands ###

    with open('data/populace_kategorie.csv', mode='r', encoding='utf-8') as populace_file:
        reader = csv.reader(populace_file, delimiter=';')
        next(reader, None)
        populace_arr = [{'vekova_skupina': row[0], 'min_vek': row[1], 'max_vek': row[2] } for row in reader]

    # print(populace_arr)

    op.bulk_insert(PopulaceKategorie.__table__, populace_arr)


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('populace_kategorie')
    # ### end Alembic commands ###
empty message  Revision ID: <KEY> Revises: <PASSWORD> Create Date: 2021-03-17 20:59:27.391819 # revision identifiers, used by Alembic. # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ### # print(populace_arr) # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ###