|
| 1 | +"""popular times |
| 2 | +
|
| 3 | +Revision ID: 31b1fa20772f |
| 4 | +Revises: |
| 5 | +Create Date: 2025-02-28 20:57:19.922403 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | +from sqlalchemy.dialects import postgresql |
| 11 | + |
| 12 | + |
| 13 | +# revision identifiers, used by Alembic. |
| 14 | +revision = '31b1fa20772f' |
| 15 | +down_revision = None |
| 16 | +branch_labels = None |
| 17 | +depends_on = None |
| 18 | + |
| 19 | + |
| 20 | +### Ensures alembic does not try to create enum |
| 21 | +day_of_week_enum = postgresql.ENUM( |
| 22 | + 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', |
| 23 | + name='dayofweekenum', create_type=False |
| 24 | +) |
| 25 | + |
| 26 | +def upgrade(): |
| 27 | + # ### commands auto generated by Alembic - please adjust! ### |
| 28 | + op.alter_column('gear', 'cost', |
| 29 | + existing_type=postgresql.DOUBLE_PRECISION(precision=53), |
| 30 | + nullable=0) |
| 31 | + |
| 32 | + ### Alembic is running command multiple times. |
| 33 | + op.execute(""" |
| 34 | + DO $$ |
| 35 | + BEGIN |
| 36 | + IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'hourly_average_capacity') THEN |
| 37 | + CREATE TABLE hourly_average_capacity ( |
| 38 | + id SERIAL PRIMARY KEY, |
| 39 | + facility_id INTEGER NOT NULL REFERENCES facility(id), |
| 40 | + average_percent FLOAT NOT NULL, |
| 41 | + hour_of_day INTEGER NOT NULL, |
| 42 | + day_of_week dayofweekenum, |
| 43 | + history NUMERIC[] DEFAULT '{}' NOT NULL |
| 44 | + ); |
| 45 | + END IF; |
| 46 | + END $$; |
| 47 | + """) |
| 48 | + # ### end Alembic commands ### |
| 49 | + |
| 50 | + |
| 51 | +def downgrade(): |
| 52 | + # ### commands auto generated by Alembic - please adjust! ### |
| 53 | + |
| 54 | + op.drop_table('hourly_average_capacity') |
| 55 | + # ### end Alembic commands ### |
| 56 | + |
0 commit comments