Skip to content

Commit

Permalink
Add database migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Nov 27, 2024
1 parent 7519473 commit a4d2874
Showing 1 changed file with 151 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
"""Update database nullable constraints
Revision ID: e3ba1f29c1c4
Revises: 272da5f400de
Create Date: 2024-11-27 15:55:09.495649+00:00
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "e3ba1f29c1c4"
down_revision = "272da5f400de"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.alter_column(
"classifications", "data_source_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column(
"coveragerecords", "data_source_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column(
"credentials", "data_source_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column(
"customlists", "data_source_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column(
"customlists", "auto_update_enabled", existing_type=sa.BOOLEAN(), nullable=False
)
op.alter_column("datasources", "name", existing_type=sa.VARCHAR(), nullable=False)
op.alter_column(
"editions", "data_source_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column(
"editions", "primary_identifier_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column(
"equivalents", "input_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column(
"equivalents", "data_source_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column(
"equivalents",
"strength",
existing_type=postgresql.DOUBLE_PRECISION(precision=53),
nullable=False,
)
op.alter_column(
"equivalentscoveragerecords",
"equivalency_id",
existing_type=sa.INTEGER(),
nullable=False,
)
op.alter_column("holds", "patron_id", existing_type=sa.INTEGER(), nullable=False)
op.alter_column(
"holds", "license_pool_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column("libraries", "name", existing_type=sa.VARCHAR(), nullable=False)
op.alter_column(
"licensepools", "data_source_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column(
"licensepools", "identifier_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column(
"licenses", "license_pool_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column("loans", "patron_id", existing_type=sa.INTEGER(), nullable=False)
op.alter_column(
"loans", "license_pool_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column(
"resources", "data_source_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column(
"workgenres", "genre_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column("workgenres", "work_id", existing_type=sa.INTEGER(), nullable=False)


def downgrade() -> None:
op.alter_column("workgenres", "work_id", existing_type=sa.INTEGER(), nullable=True)
op.alter_column("workgenres", "genre_id", existing_type=sa.INTEGER(), nullable=True)
op.alter_column(
"resources", "data_source_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column(
"loans", "license_pool_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column("loans", "patron_id", existing_type=sa.INTEGER(), nullable=True)
op.alter_column(
"licenses", "license_pool_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column(
"licensepools", "identifier_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column(
"licensepools", "data_source_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column("libraries", "name", existing_type=sa.VARCHAR(), nullable=True)
op.alter_column(
"holds", "license_pool_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column("holds", "patron_id", existing_type=sa.INTEGER(), nullable=True)
op.alter_column(
"equivalentscoveragerecords",
"equivalency_id",
existing_type=sa.INTEGER(),
nullable=True,
)
op.alter_column(
"equivalents",
"strength",
existing_type=postgresql.DOUBLE_PRECISION(precision=53),
nullable=True,
)
op.alter_column(
"equivalents", "data_source_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column(
"equivalents", "input_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column(
"editions", "primary_identifier_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column(
"editions", "data_source_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column("datasources", "name", existing_type=sa.VARCHAR(), nullable=True)
op.alter_column(
"customlists", "auto_update_enabled", existing_type=sa.BOOLEAN(), nullable=True
)
op.alter_column(
"customlists", "data_source_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column(
"credentials", "data_source_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column(
"coveragerecords", "data_source_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column(
"classifications", "data_source_id", existing_type=sa.INTEGER(), nullable=True
)

0 comments on commit a4d2874

Please sign in to comment.