|
| 1 | +"""Trip multi-users |
| 2 | +
|
| 3 | +Revision ID: 26c89b7466f2 |
| 4 | +Revises: 60a9bb641d8a |
| 5 | +Create Date: 2025-08-18 23:19:37.457354 |
| 6 | +
|
| 7 | +""" |
| 8 | + |
| 9 | +import sqlalchemy as sa |
| 10 | +import sqlmodel.sql.sqltypes |
| 11 | +from alembic import op |
| 12 | + |
| 13 | +# revision identifiers, used by Alembic. |
| 14 | +revision = "26c89b7466f2" |
| 15 | +down_revision = "60a9bb641d8a" |
| 16 | +branch_labels = None |
| 17 | +depends_on = None |
| 18 | + |
| 19 | + |
| 20 | +def upgrade(): |
| 21 | + op.create_table( |
| 22 | + "tripmember", |
| 23 | + sa.Column("id", sa.Integer(), nullable=False), |
| 24 | + sa.Column("user", sqlmodel.sql.sqltypes.AutoString(), nullable=False), |
| 25 | + sa.Column("invited_by", sqlmodel.sql.sqltypes.AutoString(), nullable=True), |
| 26 | + sa.Column("invited_at", sa.DateTime(), nullable=False), |
| 27 | + sa.Column("joined_at", sa.DateTime(), nullable=True), |
| 28 | + sa.Column("trip_id", sa.Integer(), nullable=False), |
| 29 | + sa.ForeignKeyConstraint( |
| 30 | + ["invited_by"], |
| 31 | + ["user.username"], |
| 32 | + name=op.f("fk_tripmember_invited_by_user"), |
| 33 | + ondelete="SET NULL", |
| 34 | + ), |
| 35 | + sa.ForeignKeyConstraint( |
| 36 | + ["trip_id"], ["trip.id"], name=op.f("fk_tripmember_trip_id_trip"), ondelete="CASCADE" |
| 37 | + ), |
| 38 | + sa.ForeignKeyConstraint( |
| 39 | + ["user"], ["user.username"], name=op.f("fk_tripmember_user_user"), ondelete="CASCADE" |
| 40 | + ), |
| 41 | + sa.PrimaryKeyConstraint("id", name=op.f("pk_tripmember")), |
| 42 | + ) |
| 43 | + with op.batch_alter_table("tripchecklistitem", schema=None) as batch_op: |
| 44 | + batch_op.drop_constraint(batch_op.f("fk_tripchecklistitem_user_user"), type_="foreignkey") |
| 45 | + batch_op.drop_column("user") |
| 46 | + |
| 47 | + with op.batch_alter_table("trippackinglistitem", schema=None) as batch_op: |
| 48 | + batch_op.drop_constraint(batch_op.f("fk_trippackinglistitem_user_user"), type_="foreignkey") |
| 49 | + batch_op.drop_column("user") |
| 50 | + |
| 51 | + with op.batch_alter_table("tripitem", schema=None) as batch_op: |
| 52 | + batch_op.drop_constraint(batch_op.f("fk_tripitem_day_id_tripday"), type_="foreignkey") |
| 53 | + |
| 54 | + with op.batch_alter_table("tripday", schema=None) as batch_op: |
| 55 | + batch_op.drop_constraint(batch_op.f("fk_tripday_user_user"), type_="foreignkey") |
| 56 | + batch_op.drop_column("user") |
| 57 | + |
| 58 | + with op.batch_alter_table("tripitem", schema=None) as batch_op: |
| 59 | + batch_op.create_foreign_key( |
| 60 | + batch_op.f("fk_tripitem_day_id_tripday"), |
| 61 | + "tripday", |
| 62 | + ["day_id"], |
| 63 | + ["id"], |
| 64 | + ondelete="CASCADE", |
| 65 | + ) |
| 66 | + |
| 67 | + |
| 68 | +def downgrade(): |
| 69 | + with op.batch_alter_table("trippackinglistitem", schema=None) as batch_op: |
| 70 | + batch_op.add_column(sa.Column("user", sa.VARCHAR(), nullable=False)) |
| 71 | + batch_op.create_foreign_key( |
| 72 | + batch_op.f("fk_trippackinglistitem_user_user"), |
| 73 | + "user", |
| 74 | + ["user"], |
| 75 | + ["username"], |
| 76 | + ondelete="CASCADE", |
| 77 | + ) |
| 78 | + |
| 79 | + with op.batch_alter_table("tripday", schema=None) as batch_op: |
| 80 | + batch_op.add_column(sa.Column("user", sa.VARCHAR(), nullable=False)) |
| 81 | + batch_op.create_foreign_key( |
| 82 | + batch_op.f("fk_tripday_user_user"), "user", ["user"], ["username"], ondelete="CASCADE" |
| 83 | + ) |
| 84 | + |
| 85 | + with op.batch_alter_table("tripchecklistitem", schema=None) as batch_op: |
| 86 | + batch_op.add_column(sa.Column("user", sa.VARCHAR(), nullable=False)) |
| 87 | + batch_op.create_foreign_key( |
| 88 | + batch_op.f("fk_tripchecklistitem_user_user"), "user", ["user"], ["username"], ondelete="CASCADE" |
| 89 | + ) |
| 90 | + |
| 91 | + op.drop_table("tripmember") |
0 commit comments