|
| 1 | +"""Add resource exports imports |
| 2 | +
|
| 3 | +Revision ID: ea7cca121fcb |
| 4 | +Revises: 46150101edec |
| 5 | +Create Date: 2026-03-02 13:45:57.118841+00:00 |
| 6 | +
|
| 7 | +""" |
| 8 | + |
| 9 | +import sqlalchemy as sa |
| 10 | +import sqlalchemy_utils |
| 11 | +from alembic import op |
| 12 | + |
| 13 | +import dstack._internal.server.models |
| 14 | + |
| 15 | +# revision identifiers, used by Alembic. |
| 16 | +revision = "ea7cca121fcb" |
| 17 | +down_revision = "46150101edec" |
| 18 | +branch_labels = None |
| 19 | +depends_on = None |
| 20 | + |
| 21 | + |
| 22 | +def upgrade() -> None: |
| 23 | + # ### commands auto generated by Alembic - please adjust! ### |
| 24 | + op.create_table( |
| 25 | + "resource_exports", |
| 26 | + sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(binary=False), nullable=False), |
| 27 | + sa.Column("name", sa.String(length=100), nullable=False), |
| 28 | + sa.Column( |
| 29 | + "project_id", sqlalchemy_utils.types.uuid.UUIDType(binary=False), nullable=False |
| 30 | + ), |
| 31 | + sa.Column("created_at", dstack._internal.server.models.NaiveDateTime(), nullable=False), |
| 32 | + sa.ForeignKeyConstraint( |
| 33 | + ["project_id"], |
| 34 | + ["projects.id"], |
| 35 | + name=op.f("fk_resource_exports_project_id_projects"), |
| 36 | + ondelete="CASCADE", |
| 37 | + ), |
| 38 | + sa.PrimaryKeyConstraint("id", name=op.f("pk_resource_exports")), |
| 39 | + sa.UniqueConstraint("project_id", "name", name="uq_resource_exports_project_id_name"), |
| 40 | + ) |
| 41 | + with op.batch_alter_table("resource_exports", schema=None) as batch_op: |
| 42 | + batch_op.create_index( |
| 43 | + batch_op.f("ix_resource_exports_project_id"), ["project_id"], unique=False |
| 44 | + ) |
| 45 | + |
| 46 | + op.create_table( |
| 47 | + "exported_fleets", |
| 48 | + sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(binary=False), nullable=False), |
| 49 | + sa.Column( |
| 50 | + "resource_export_id", |
| 51 | + sqlalchemy_utils.types.uuid.UUIDType(binary=False), |
| 52 | + nullable=False, |
| 53 | + ), |
| 54 | + sa.Column("fleet_id", sqlalchemy_utils.types.uuid.UUIDType(binary=False), nullable=False), |
| 55 | + sa.ForeignKeyConstraint( |
| 56 | + ["fleet_id"], |
| 57 | + ["fleets.id"], |
| 58 | + name=op.f("fk_exported_fleets_fleet_id_fleets"), |
| 59 | + ondelete="CASCADE", |
| 60 | + ), |
| 61 | + sa.ForeignKeyConstraint( |
| 62 | + ["resource_export_id"], |
| 63 | + ["resource_exports.id"], |
| 64 | + name=op.f("fk_exported_fleets_resource_export_id_resource_exports"), |
| 65 | + ondelete="CASCADE", |
| 66 | + ), |
| 67 | + sa.PrimaryKeyConstraint("id", name=op.f("pk_exported_fleets")), |
| 68 | + sa.UniqueConstraint( |
| 69 | + "resource_export_id", "fleet_id", name="uq_exported_fleets_resource_export_id_fleet_id" |
| 70 | + ), |
| 71 | + ) |
| 72 | + with op.batch_alter_table("exported_fleets", schema=None) as batch_op: |
| 73 | + batch_op.create_index( |
| 74 | + batch_op.f("ix_exported_fleets_fleet_id"), ["fleet_id"], unique=False |
| 75 | + ) |
| 76 | + batch_op.create_index( |
| 77 | + batch_op.f("ix_exported_fleets_resource_export_id"), |
| 78 | + ["resource_export_id"], |
| 79 | + unique=False, |
| 80 | + ) |
| 81 | + |
| 82 | + op.create_table( |
| 83 | + "resource_imports", |
| 84 | + sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(binary=False), nullable=False), |
| 85 | + sa.Column( |
| 86 | + "project_id", sqlalchemy_utils.types.uuid.UUIDType(binary=False), nullable=False |
| 87 | + ), |
| 88 | + sa.Column( |
| 89 | + "resource_export_id", |
| 90 | + sqlalchemy_utils.types.uuid.UUIDType(binary=False), |
| 91 | + nullable=False, |
| 92 | + ), |
| 93 | + sa.Column("created_at", dstack._internal.server.models.NaiveDateTime(), nullable=False), |
| 94 | + sa.ForeignKeyConstraint( |
| 95 | + ["project_id"], |
| 96 | + ["projects.id"], |
| 97 | + name=op.f("fk_resource_imports_project_id_projects"), |
| 98 | + ondelete="CASCADE", |
| 99 | + ), |
| 100 | + sa.ForeignKeyConstraint( |
| 101 | + ["resource_export_id"], |
| 102 | + ["resource_exports.id"], |
| 103 | + name=op.f("fk_resource_imports_resource_export_id_resource_exports"), |
| 104 | + ondelete="CASCADE", |
| 105 | + ), |
| 106 | + sa.PrimaryKeyConstraint("id", name=op.f("pk_resource_imports")), |
| 107 | + sa.UniqueConstraint( |
| 108 | + "project_id", |
| 109 | + "resource_export_id", |
| 110 | + name="uq_resource_imports_project_id_resource_export_id", |
| 111 | + ), |
| 112 | + ) |
| 113 | + with op.batch_alter_table("resource_imports", schema=None) as batch_op: |
| 114 | + batch_op.create_index( |
| 115 | + batch_op.f("ix_resource_imports_project_id"), ["project_id"], unique=False |
| 116 | + ) |
| 117 | + batch_op.create_index( |
| 118 | + batch_op.f("ix_resource_imports_resource_export_id"), |
| 119 | + ["resource_export_id"], |
| 120 | + unique=False, |
| 121 | + ) |
| 122 | + |
| 123 | + # ### end Alembic commands ### |
| 124 | + |
| 125 | + |
| 126 | +def downgrade() -> None: |
| 127 | + # ### commands auto generated by Alembic - please adjust! ### |
| 128 | + with op.batch_alter_table("resource_imports", schema=None) as batch_op: |
| 129 | + batch_op.drop_index(batch_op.f("ix_resource_imports_resource_export_id")) |
| 130 | + batch_op.drop_index(batch_op.f("ix_resource_imports_project_id")) |
| 131 | + |
| 132 | + op.drop_table("resource_imports") |
| 133 | + with op.batch_alter_table("exported_fleets", schema=None) as batch_op: |
| 134 | + batch_op.drop_index(batch_op.f("ix_exported_fleets_resource_export_id")) |
| 135 | + batch_op.drop_index(batch_op.f("ix_exported_fleets_fleet_id")) |
| 136 | + |
| 137 | + op.drop_table("exported_fleets") |
| 138 | + with op.batch_alter_table("resource_exports", schema=None) as batch_op: |
| 139 | + batch_op.drop_index(batch_op.f("ix_resource_exports_project_id")) |
| 140 | + |
| 141 | + op.drop_table("resource_exports") |
| 142 | + # ### end Alembic commands ### |
0 commit comments