fix: manejar error 401 automaticamente y agregar migracion de columnas routes
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
"""Fix routes table: ensure color, direction, average_speed_kmh columns exist
|
||||
|
||||
This migration uses IF NOT EXISTS to safely add missing columns regardless
|
||||
of the current database state in production.
|
||||
|
||||
Revision ID: a1b2c3d4e5f6
|
||||
Revises: ffcd1234abcd
|
||||
Create Date: 2026-02-26 00:30:00.000000
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'a1b2c3d4e5f6'
|
||||
down_revision: Union[str, None] = 'ffcd1234abcd'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Use raw SQL with IF NOT EXISTS to be safe regardless of prior migration state.
|
||||
# This ensures the columns exist in production even if the previous migration
|
||||
# had issues being applied.
|
||||
with op.get_context().autocommit_block():
|
||||
op.execute("ALTER TABLE routes ADD COLUMN IF NOT EXISTS color VARCHAR DEFAULT '#FEE715'")
|
||||
op.execute("ALTER TABLE routes ADD COLUMN IF NOT EXISTS direction VARCHAR DEFAULT 'outbound'")
|
||||
op.execute("ALTER TABLE routes ADD COLUMN IF NOT EXISTS average_speed_kmh FLOAT")
|
||||
# Update any existing NULLs
|
||||
op.execute("UPDATE routes SET color = '#FEE715' WHERE color IS NULL")
|
||||
op.execute("UPDATE routes SET direction = 'outbound' WHERE direction IS NULL")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
pass
|
||||
Reference in New Issue
Block a user