Skip to content

Commit

Permalink
remove explicit id sequence, add initial migration
Browse files Browse the repository at this point in the history
  • Loading branch information
lunakv committed Sep 28, 2022
1 parent 4e1f710 commit be7ca41
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 6 deletions.
97 changes: 97 additions & 0 deletions alembic/versions/0cb715a5aac5_initial_autogen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""initial_autogen
Revision ID: 0cb715a5aac5
Revises:
Create Date: 2022-09-28 11:30:45.896529
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '0cb715a5aac5'
down_revision = None
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('cr',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('creation_day', sa.Date(), nullable=True),
sa.Column('set_code', sa.String(length=5), nullable=True),
sa.Column('set_name', sa.String(length=50), nullable=True),
sa.Column('data', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('file_name', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('cr_pending',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('creation_day', sa.Date(), nullable=True),
sa.Column('data', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('file_name', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('ipg',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('creation_day', sa.Date(), nullable=True),
sa.Column('file_name', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_ipg_creation_day'), 'ipg', ['creation_day'], unique=False)
op.create_table('mtr',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('file_name', sa.Text(), nullable=True),
sa.Column('creation_day', sa.Date(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_mtr_creation_day'), 'mtr', ['creation_day'], unique=False)
op.create_table('redirects',
sa.Column('resource', sa.Text(), nullable=False),
sa.Column('link', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('resource')
)
op.create_table('redirects_pending',
sa.Column('resource', sa.Text(), nullable=False),
sa.Column('link', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('resource')
)
op.create_table('cr_diffs',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('creation_day', sa.Date(), nullable=False),
sa.Column('changes', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('source_id', sa.Integer(), nullable=False),
sa.Column('dest_id', sa.Integer(), nullable=False),
sa.Column('bulletin_url', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['dest_id'], ['cr.id'], ),
sa.ForeignKeyConstraint(['source_id'], ['cr.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('cr_diffs_pending',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('creation_day', sa.Date(), nullable=True),
sa.Column('source_id', sa.Integer(), nullable=False),
sa.Column('dest_id', sa.Integer(), nullable=False),
sa.Column('changes', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.ForeignKeyConstraint(['dest_id'], ['cr_pending.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['source_id'], ['cr.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('cr_diffs_pending')
op.drop_table('cr_diffs')
op.drop_table('redirects_pending')
op.drop_table('redirects')
op.drop_index(op.f('ix_mtr_creation_day'), table_name='mtr')
op.drop_table('mtr')
op.drop_index(op.f('ix_ipg_creation_day'), table_name='ipg')
op.drop_table('ipg')
op.drop_table('cr_pending')
op.drop_table('cr')
# ### end Alembic commands ###
12 changes: 6 additions & 6 deletions app/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Cr(Base):
__tablename__ = "cr"

id = Column(Integer, primary_key=True, server_default=text("nextval('cr_id_seq'::regclass)"))
id = Column(Integer, primary_key=True)
creation_day = Column(Date)
set_code = Column(String(5))
set_name = Column(String(50))
Expand All @@ -19,7 +19,7 @@ class Cr(Base):
class PendingCr(Base):
__tablename__ = "cr_pending"

id = Column(Integer, primary_key=True, server_default=text("nextval('cr_pending_id_seq'::regclass)"))
id = Column(Integer, primary_key=True)
creation_day = Column(Date)
data = Column(JSONB(astext_type=Text()))
file_name = Column(Text)
Expand All @@ -28,15 +28,15 @@ class PendingCr(Base):
class Ipg(Base):
__tablename__ = "ipg"

id = Column(Integer, primary_key=True, server_default=text("nextval('table_name_id_seq'::regclass)"))
id = Column(Integer, primary_key=True)
creation_day = Column(Date, index=True)
file_name = Column(Text)


class Mtr(Base):
__tablename__ = "mtr"

id = Column(Integer, primary_key=True, server_default=text("nextval('mtr_id_seq'::regclass)"))
id = Column(Integer, primary_key=True)
file_name = Column(Text)
creation_day = Column(Date, index=True)

Expand All @@ -58,7 +58,7 @@ class PendingRedirect(Base):
class CrDiff(Base):
__tablename__ = "cr_diffs"

id = Column(Integer, primary_key=True, server_default=text("nextval('cr_diffs_id_seq'::regclass)"))
id = Column(Integer, primary_key=True)
creation_day = Column(Date, nullable=False)
changes = Column(JSONB(astext_type=Text()))
source_id = Column(ForeignKey("cr.id"), nullable=False)
Expand All @@ -72,7 +72,7 @@ class CrDiff(Base):
class PendingCrDiff(Base):
__tablename__ = "cr_diffs_pending"

id = Column(Integer, primary_key=True, server_default=text("nextval('cr_diffs_pending_id_seq'::regclass)"))
id = Column(Integer, primary_key=True)
creation_day = Column(Date)
source_id = Column(ForeignKey("cr.id"), nullable=False)
dest_id = Column(ForeignKey("cr_pending.id", ondelete="CASCADE"), nullable=False)
Expand Down

0 comments on commit be7ca41

Please sign in to comment.