Skip to content

Commit 864190c

Browse files
authored
♻️DB maintenance: drop clusters and cluster_to_groups db tables (🗃️) (#7373)
1 parent dcef4b4 commit 864190c

File tree

16 files changed

+210
-382
lines changed

16 files changed

+210
-382
lines changed

.codecov.yml

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ flag_management:
1818

1919
component_management:
2020
default_rules:
21-
carryforward: true
2221
statuses:
2322
- type: project
2423
target: auto
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""remove cluster_to_groups
2+
3+
Revision ID: 7994074c4d98
4+
Revises: 381336fa8001
5+
Create Date: 2025-03-17 14:19:54.675073+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 = "7994074c4d98"
15+
down_revision = "381336fa8001"
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.drop_table("cluster_to_groups")
23+
# ### end Alembic commands ###
24+
25+
26+
def downgrade():
27+
# ### commands auto generated by Alembic - please adjust! ###
28+
op.create_table(
29+
"cluster_to_groups",
30+
sa.Column("cluster_id", sa.BIGINT(), autoincrement=False, nullable=True),
31+
sa.Column("gid", sa.BIGINT(), autoincrement=False, nullable=True),
32+
sa.Column(
33+
"read",
34+
sa.BOOLEAN(),
35+
server_default=sa.text("false"),
36+
autoincrement=False,
37+
nullable=False,
38+
),
39+
sa.Column(
40+
"write",
41+
sa.BOOLEAN(),
42+
server_default=sa.text("false"),
43+
autoincrement=False,
44+
nullable=False,
45+
),
46+
sa.Column(
47+
"delete",
48+
sa.BOOLEAN(),
49+
server_default=sa.text("false"),
50+
autoincrement=False,
51+
nullable=False,
52+
),
53+
sa.Column(
54+
"created",
55+
postgresql.TIMESTAMP(),
56+
server_default=sa.text("now()"),
57+
autoincrement=False,
58+
nullable=False,
59+
),
60+
sa.Column(
61+
"modified",
62+
postgresql.TIMESTAMP(),
63+
server_default=sa.text("now()"),
64+
autoincrement=False,
65+
nullable=False,
66+
),
67+
sa.ForeignKeyConstraint(
68+
["cluster_id"],
69+
["clusters.id"],
70+
name="fk_cluster_to_groups_id_clusters",
71+
onupdate="CASCADE",
72+
ondelete="CASCADE",
73+
),
74+
sa.ForeignKeyConstraint(
75+
["gid"],
76+
["groups.gid"],
77+
name="fk_cluster_to_groups_gid_groups",
78+
onupdate="CASCADE",
79+
ondelete="CASCADE",
80+
),
81+
sa.UniqueConstraint(
82+
"cluster_id", "gid", name="cluster_to_groups_cluster_id_gid_key"
83+
),
84+
)
85+
# ### end Alembic commands ###
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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)

packages/postgres-database/src/simcore_postgres_database/models/cluster_to_groups.py

-73
This file was deleted.

0 commit comments

Comments
 (0)