Added in_use and priority_id field for channels urls. Added priorities table. Setup sql alchemy migration. Generate first migration.
All checks were successful
AWS Deploy on Push / build (push) Successful in 2m4s
All checks were successful
AWS Deploy on Push / build (push) Successful in 2m4s
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
"""Add priority and in_use fields
|
||||
|
||||
Revision ID: 036879e47172
|
||||
Revises:
|
||||
Create Date: 2025-05-26 19:21:32.285656
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '036879e47172'
|
||||
down_revision: Union[str, None] = None
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
# 1. Create priorities table if not exists
|
||||
if not op.get_bind().engine.dialect.has_table(op.get_bind(), 'priorities'):
|
||||
op.create_table('priorities',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('description', sa.String(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
|
||||
# 2. Insert default priorities (skip if already exists)
|
||||
op.execute("""
|
||||
INSERT INTO priorities (id, description)
|
||||
VALUES (100, 'High'), (200, 'Medium'), (300, 'Low')
|
||||
ON CONFLICT (id) DO NOTHING
|
||||
""")
|
||||
# Add new columns with temporary nullable=True
|
||||
op.add_column('channels_urls', sa.Column('in_use', sa.Boolean(), nullable=True))
|
||||
op.add_column('channels_urls', sa.Column('priority_id', sa.Integer(), nullable=True))
|
||||
|
||||
# Set default values
|
||||
op.execute("UPDATE channels_urls SET in_use = false, priority_id = 100")
|
||||
|
||||
# Convert to NOT NULL
|
||||
op.alter_column('channels_urls', 'in_use', nullable=False)
|
||||
op.alter_column('channels_urls', 'priority_id', nullable=False)
|
||||
op.create_foreign_key(None, 'channels_urls', 'priorities', ['priority_id'], ['id'])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint('channels_urls_priority_id_fkey', 'channels_urls', type_='foreignkey')
|
||||
op.drop_column('channels_urls', 'priority_id')
|
||||
op.drop_column('channels_urls', 'in_use')
|
||||
op.drop_table('priorities')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user