|
| 1 | +"""remove clusters |
| 2 | +
|
| 3 | +Revision ID: f7f3c835f38a |
| 4 | +Revises: 7994074c4d98 |
| 5 | +Create Date: 2025-03-17 14:26:58.117504+00:00 |
| 6 | +
|
| 7 | +""" |
| 8 | + |
| 9 | +import sqlalchemy as sa |
| 10 | +from alembic import op |
| 11 | +from sqlalchemy.dialects import postgresql |
| 12 | + |
| 13 | +# revision identifiers, used by Alembic. |
| 14 | +revision = "f7f3c835f38a" |
| 15 | +down_revision = "7994074c4d98" |
| 16 | +branch_labels = None |
| 17 | +depends_on = None |
| 18 | + |
| 19 | + |
| 20 | +def upgrade(): |
| 21 | + # ### commands auto generated by Alembic - please adjust! ### |
| 22 | + op.drop_constraint( |
| 23 | + "fk_comp_runs_cluster_id_clusters", "comp_runs", type_="foreignkey" |
| 24 | + ) |
| 25 | + op.drop_column("comp_runs", "cluster_id") |
| 26 | + op.drop_table("clusters") |
| 27 | + op.execute("DROP TRIGGER IF EXISTS cluster_modification on clusters;") |
| 28 | + op.execute("DROP FUNCTION set_cluster_to_owner_group() CASCADE") |
| 29 | + op.execute("DROP TYPE IF EXISTS clustertype") |
| 30 | + # ### end Alembic commands ### |
| 31 | + |
| 32 | + |
| 33 | +new_cluster_trigger = sa.DDL( |
| 34 | + """ |
| 35 | +DROP TRIGGER IF EXISTS cluster_modification on clusters; |
| 36 | +CREATE TRIGGER cluster_modification |
| 37 | +AFTER INSERT ON clusters |
| 38 | + FOR EACH ROW |
| 39 | + EXECUTE PROCEDURE set_cluster_to_owner_group(); |
| 40 | +""" |
| 41 | +) |
| 42 | +assign_cluster_access_rights_to_owner_group_procedure_new = sa.DDL( |
| 43 | + """ |
| 44 | +CREATE OR REPLACE FUNCTION set_cluster_to_owner_group() RETURNS TRIGGER AS $$ |
| 45 | +DECLARE |
| 46 | + group_id BIGINT; |
| 47 | +BEGIN |
| 48 | + IF TG_OP = 'INSERT' THEN |
| 49 | + INSERT INTO "cluster_to_groups" ("gid", "cluster_id", "read", "write", "delete") VALUES (NEW.owner, NEW.id, TRUE, TRUE, TRUE); |
| 50 | + END IF; |
| 51 | + RETURN NULL; |
| 52 | +END; $$ LANGUAGE 'plpgsql'; |
| 53 | + """ |
| 54 | +) |
| 55 | + |
| 56 | + |
| 57 | +def downgrade(): |
| 58 | + # ### commands auto generated by Alembic - please adjust! ### |
| 59 | + op.execute(sa.DDL("DROP TRIGGER IF EXISTS cluster_modification on clusters;")) |
| 60 | + op.execute("DROP TYPE IF EXISTS clustertype") |
| 61 | + op.create_table( |
| 62 | + "clusters", |
| 63 | + sa.Column("id", sa.BIGINT(), autoincrement=True, nullable=False), |
| 64 | + sa.Column("name", sa.VARCHAR(), autoincrement=False, nullable=False), |
| 65 | + sa.Column("description", sa.VARCHAR(), autoincrement=False, nullable=True), |
| 66 | + sa.Column( |
| 67 | + "type", |
| 68 | + postgresql.ENUM("AWS", "ON_PREMISE", name="clustertype"), |
| 69 | + autoincrement=False, |
| 70 | + nullable=False, |
| 71 | + ), |
| 72 | + sa.Column("owner", sa.BIGINT(), autoincrement=False, nullable=False), |
| 73 | + sa.Column("thumbnail", sa.VARCHAR(), autoincrement=False, nullable=True), |
| 74 | + sa.Column( |
| 75 | + "created", |
| 76 | + postgresql.TIMESTAMP(), |
| 77 | + server_default=sa.text("now()"), |
| 78 | + autoincrement=False, |
| 79 | + nullable=False, |
| 80 | + ), |
| 81 | + sa.Column( |
| 82 | + "modified", |
| 83 | + postgresql.TIMESTAMP(), |
| 84 | + server_default=sa.text("now()"), |
| 85 | + autoincrement=False, |
| 86 | + nullable=False, |
| 87 | + ), |
| 88 | + sa.Column("endpoint", sa.VARCHAR(), autoincrement=False, nullable=False), |
| 89 | + sa.Column( |
| 90 | + "authentication", |
| 91 | + postgresql.JSONB(astext_type=sa.Text()), |
| 92 | + autoincrement=False, |
| 93 | + nullable=False, |
| 94 | + ), |
| 95 | + sa.ForeignKeyConstraint( |
| 96 | + ["owner"], |
| 97 | + ["groups.gid"], |
| 98 | + name="fk_clusters_gid_groups", |
| 99 | + onupdate="CASCADE", |
| 100 | + ondelete="RESTRICT", |
| 101 | + ), |
| 102 | + sa.PrimaryKeyConstraint("id", name="clusters_pkey"), |
| 103 | + ) |
| 104 | + |
| 105 | + op.add_column( |
| 106 | + "comp_runs", |
| 107 | + sa.Column("cluster_id", sa.BIGINT(), autoincrement=False, nullable=True), |
| 108 | + ) |
| 109 | + op.create_foreign_key( |
| 110 | + "fk_comp_runs_cluster_id_clusters", |
| 111 | + "comp_runs", |
| 112 | + "clusters", |
| 113 | + ["cluster_id"], |
| 114 | + ["id"], |
| 115 | + onupdate="CASCADE", |
| 116 | + ondelete="SET NULL", |
| 117 | + ) |
| 118 | + # ### end Alembic commands ### |
| 119 | + op.execute(assign_cluster_access_rights_to_owner_group_procedure_new) |
| 120 | + op.execute(new_cluster_trigger) |
0 commit comments