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

chore(grouping): delete old grouping_records table #917

Merged
merged 8 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""drop old grouping_records table

Revision ID: 2597db647e9a
Revises: d87a6410efe4
Create Date: 2024-07-17 03:16:52.924194

"""

from alembic import op

# revision identifiers, used by Alembic.
revision = "2597db647e9a"
down_revision = "d87a6410efe4"
branch_labels = None
depends_on = None


def upgrade():
op.execute("ALTER TABLE IF EXISTS grouping_records RENAME to grouping_records_old;")

op.execute("ALTER TABLE grouping_records_new RENAME TO grouping_records;")
for i in range(100):
op.execute(f"ALTER TABLE grouping_records_new_p{i} RENAME TO grouping_records_p{i};")

op.execute("DROP TABLE IF EXISTS grouping_records_old")


def downgrade():
op.execute("ALTER TABLE IF EXISTS grouping_records RENAME TO grouping_records_new;")

for i in range(100):
op.execute(f"ALTER TABLE grouping_records_p{i} RENAME TO grouping_records_new_p{i};")

op.execute("ALTER TABLE grouping_records_old RENAME TO grouping_records;")

op.execute("DROP TABLE IF EXISTS grouping_records_new")
68 changes: 68 additions & 0 deletions src/migrations/versions/d87a6410efe4_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""Update HNSW parameters for grouping_records

Revision ID: d87a6410efe4
Revises: a0d00121d118
Create Date: 2024-07-09 22:28:26.035785

"""

from alembic import op

# revision identifiers, used by Alembic.
revision = "d87a6410efe4"
down_revision = "a0d00121d118"
branch_labels = None
depends_on = None


def upgrade():
op.execute("DROP TABLE IF EXISTS grouping_records_new CASCADE;")

op.execute(
"""
CREATE TABLE grouping_records_new (
id INTEGER NOT NULL,
project_id BIGINT NOT NULL,
hash VARCHAR(32) NOT NULL,
message VARCHAR NOT NULL,
error_type VARCHAR,
stacktrace_embedding VECTOR(768) NOT NULL,
PRIMARY KEY (id, project_id)
) PARTITION BY HASH (project_id);
"""
)

for i in range(100):
op.execute(
f"""
CREATE TABLE grouping_records_new_p{i} PARTITION OF grouping_records_new
FOR VALUES WITH (MODULUS 100, REMAINDER {i});
"""
)

op.execute(
"""
INSERT INTO grouping_records_new (id, project_id, message, error_type, stacktrace_embedding, hash)
SELECT id, project_id, message, error_type, stacktrace_embedding, hash
FROM grouping_records;
"""
)

op.execute(
"""
CREATE INDEX IF NOT EXISTS ix_grouping_records_new_stacktrace_embedding_hnsw
ON grouping_records_new USING hnsw (stacktrace_embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 200);
"""
)

op.execute(
"CREATE INDEX IF NOT EXISTS ix_grouping_records_project_id ON grouping_records_new (project_id);"
)

with op.batch_alter_table("grouping_records_new", schema=None) as batch_op:
batch_op.create_unique_constraint("u_project_id_hash_composite", ["project_id", "hash"])


def downgrade():
op.execute("DROP TABLE IF EXISTS grouping_records_new CASCADE;")
Loading