Looking good
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
"""Added birth_date, storing revenue as number
|
||||
|
||||
Revision ID: b33fd7a2da6c
|
||||
Revises: 630b0c367dcb
|
||||
Create Date: 2025-11-18 14:41:17.567595
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'b33fd7a2da6c'
|
||||
down_revision: Union[str, Sequence[str], None] = '630b0c367dcb'
|
||||
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! ###
|
||||
|
||||
# Convert VARCHAR to Double with explicit CAST for PostgreSQL compatibility
|
||||
# PostgreSQL requires USING clause for type conversion
|
||||
connection = op.get_bind()
|
||||
if connection.dialect.name == 'postgresql':
|
||||
op.execute(
|
||||
"ALTER TABLE conversion_rooms "
|
||||
"ALTER COLUMN total_revenue TYPE DOUBLE PRECISION "
|
||||
"USING total_revenue::DOUBLE PRECISION"
|
||||
)
|
||||
else:
|
||||
# For SQLite and other databases, use standard alter_column
|
||||
op.alter_column('conversion_rooms', 'total_revenue',
|
||||
existing_type=sa.VARCHAR(),
|
||||
type_=sa.Double(),
|
||||
existing_nullable=True)
|
||||
|
||||
op.add_column('conversions', sa.Column('guest_birth_date', sa.Date(), nullable=True))
|
||||
op.add_column('conversions', sa.Column('guest_id', sa.String(), nullable=True))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('conversions', 'guest_id')
|
||||
op.drop_column('conversions', 'guest_birth_date')
|
||||
|
||||
# Convert Double back to VARCHAR with explicit CAST for PostgreSQL compatibility
|
||||
connection = op.get_bind()
|
||||
if connection.dialect.name == 'postgresql':
|
||||
op.execute(
|
||||
"ALTER TABLE conversion_rooms "
|
||||
"ALTER COLUMN total_revenue TYPE VARCHAR "
|
||||
"USING total_revenue::VARCHAR"
|
||||
)
|
||||
else:
|
||||
# For SQLite and other databases, use standard alter_column
|
||||
op.alter_column('conversion_rooms', 'total_revenue',
|
||||
existing_type=sa.Double(),
|
||||
type_=sa.VARCHAR(),
|
||||
existing_nullable=True)
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user