Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️DB maintenance: drop clusters and cluster_to_groups db tables (🗃️) #7373

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ flag_management:

component_management:
default_rules:
carryforward: true
statuses:
- type: project
target: auto
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""remove cluster_to_groups

Revision ID: 7994074c4d98
Revises: 381336fa8001
Create Date: 2025-03-17 14:19:54.675073+00:00

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "7994074c4d98"
down_revision = "381336fa8001"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("cluster_to_groups")
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"cluster_to_groups",
sa.Column("cluster_id", sa.BIGINT(), autoincrement=False, nullable=True),
sa.Column("gid", sa.BIGINT(), autoincrement=False, nullable=True),
sa.Column(
"read",
sa.BOOLEAN(),
server_default=sa.text("false"),
autoincrement=False,
nullable=False,
),
sa.Column(
"write",
sa.BOOLEAN(),
server_default=sa.text("false"),
autoincrement=False,
nullable=False,
),
sa.Column(
"delete",
sa.BOOLEAN(),
server_default=sa.text("false"),
autoincrement=False,
nullable=False,
),
sa.Column(
"created",
postgresql.TIMESTAMP(),
server_default=sa.text("now()"),
autoincrement=False,
nullable=False,
),
sa.Column(
"modified",
postgresql.TIMESTAMP(),
server_default=sa.text("now()"),
autoincrement=False,
nullable=False,
),
sa.ForeignKeyConstraint(
["cluster_id"],
["clusters.id"],
name="fk_cluster_to_groups_id_clusters",
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
["gid"],
["groups.gid"],
name="fk_cluster_to_groups_gid_groups",
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.UniqueConstraint(
"cluster_id", "gid", name="cluster_to_groups_cluster_id_gid_key"
),
)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"""remove clusters

Revision ID: f7f3c835f38a
Revises: 7994074c4d98
Create Date: 2025-03-17 14:26:58.117504+00:00

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "f7f3c835f38a"
down_revision = "7994074c4d98"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"fk_comp_runs_cluster_id_clusters", "comp_runs", type_="foreignkey"
)
op.drop_column("comp_runs", "cluster_id")
op.drop_table("clusters")
op.execute("DROP TRIGGER IF EXISTS cluster_modification on clusters;")
op.execute("DROP FUNCTION set_cluster_to_owner_group() CASCADE")
op.execute("DROP TYPE IF EXISTS clustertype")
# ### end Alembic commands ###


new_cluster_trigger = sa.DDL(
"""
DROP TRIGGER IF EXISTS cluster_modification on clusters;
CREATE TRIGGER cluster_modification
AFTER INSERT ON clusters
FOR EACH ROW
EXECUTE PROCEDURE set_cluster_to_owner_group();
"""
)
assign_cluster_access_rights_to_owner_group_procedure_new = sa.DDL(
"""
CREATE OR REPLACE FUNCTION set_cluster_to_owner_group() RETURNS TRIGGER AS $$
DECLARE
group_id BIGINT;
BEGIN
IF TG_OP = 'INSERT' THEN
INSERT INTO "cluster_to_groups" ("gid", "cluster_id", "read", "write", "delete") VALUES (NEW.owner, NEW.id, TRUE, TRUE, TRUE);
END IF;
RETURN NULL;
END; $$ LANGUAGE 'plpgsql';
"""
)


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.execute(sa.DDL("DROP TRIGGER IF EXISTS cluster_modification on clusters;"))
op.execute("DROP TYPE IF EXISTS clustertype")
op.create_table(
"clusters",
sa.Column("id", sa.BIGINT(), autoincrement=True, nullable=False),
sa.Column("name", sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column("description", sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column(
"type",
postgresql.ENUM("AWS", "ON_PREMISE", name="clustertype"),
autoincrement=False,
nullable=False,
),
sa.Column("owner", sa.BIGINT(), autoincrement=False, nullable=False),
sa.Column("thumbnail", sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column(
"created",
postgresql.TIMESTAMP(),
server_default=sa.text("now()"),
autoincrement=False,
nullable=False,
),
sa.Column(
"modified",
postgresql.TIMESTAMP(),
server_default=sa.text("now()"),
autoincrement=False,
nullable=False,
),
sa.Column("endpoint", sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column(
"authentication",
postgresql.JSONB(astext_type=sa.Text()),
autoincrement=False,
nullable=False,
),
sa.ForeignKeyConstraint(
["owner"],
["groups.gid"],
name="fk_clusters_gid_groups",
onupdate="CASCADE",
ondelete="RESTRICT",
),
sa.PrimaryKeyConstraint("id", name="clusters_pkey"),
)

op.add_column(
"comp_runs",
sa.Column("cluster_id", sa.BIGINT(), autoincrement=False, nullable=True),
)
op.create_foreign_key(
"fk_comp_runs_cluster_id_clusters",
"comp_runs",
"clusters",
["cluster_id"],
["id"],
onupdate="CASCADE",
ondelete="SET NULL",
)
# ### end Alembic commands ###
op.execute(assign_cluster_access_rights_to_owner_group_procedure_new)
op.execute(new_cluster_trigger)

This file was deleted.

Loading
Loading