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

fix(grouping): make id bigint sequence #924

Merged
merged 9 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
33 changes: 33 additions & 0 deletions src/migrations/versions/95b4ba4f731d_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Migration

Revision ID: 95b4ba4f731d
Revises: 2597db647e9a
Create Date: 2024-07-17 23:35:18.871569

"""

from alembic import op

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


def upgrade():
op.execute("ALTER TABLE grouping_records ALTER COLUMN id TYPE BIGINT")
op.execute("CREATE SEQUENCE IF NOT EXISTS grouping_records_id_seq")
op.execute(
"ALTER TABLE grouping_records ALTER COLUMN id SET DEFAULT nextval('grouping_records_id_seq')"
)
op.execute("ALTER SEQUENCE grouping_records_id_seq OWNED BY grouping_records.id")
op.execute(
"SELECT setval('grouping_records_id_seq', COALESCE((SELECT MAX(id) FROM grouping_records), 1), true)"
)


def downgrade():
op.execute("ALTER TABLE grouping_records ALTER COLUMN id DROP DEFAULT")
op.execute("DROP SEQUENCE grouping_records_id_seq")
op.execute("ALTER TABLE grouping_records ALTER COLUMN id TYPE INTEGER")
53 changes: 43 additions & 10 deletions src/seer/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,28 +231,61 @@ class DbPrIdToAutofixRunIdMapping(Base):
)


class DbGroupingRecord(Base):
__tablename__ = "grouping_records"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
project_id: Mapped[int] = mapped_column(BigInteger, nullable=False)
class DbGroupingRecordBase:
id: Mapped[int] = mapped_column(
BigInteger, primary_key=True, server_default="nextval('grouping_records_id_seq')"
)
project_id: Mapped[int] = mapped_column(BigInteger, primary_key=True, nullable=False)
message: Mapped[str] = mapped_column(String, nullable=False)
error_type: Mapped[str] = mapped_column(String, nullable=True)
stacktrace_embedding: Mapped[Vector] = mapped_column(Vector(768), nullable=False)
hash: Mapped[str] = mapped_column(
String(32), nullable=False, default="00000000000000000000000000000000"
)
hash: Mapped[str] = mapped_column(String(32), nullable=False)


class DbGroupingRecord(DbGroupingRecordBase, Base):
__tablename__ = "grouping_records"
__table_args__ = (
Index(
"ix_grouping_records_stacktrace_embedding_hnsw",
"ix_grouping_records_new_stacktrace_embedding_hnsw",
"stacktrace_embedding",
postgresql_using="hnsw",
postgresql_with={"m": 16, "ef_construction": 200},
postgresql_ops={"stacktrace_embedding": "vector_cosine_ops"},
),
Index(
"ix_grouping_records_project_id",
"ix_grouping_records_new_project_id",
"project_id",
),
UniqueConstraint("project_id", "hash", name="u_project_id_hash"),
UniqueConstraint("project_id", "hash", name="u_project_id_hash_composite"),
{"postgresql_partition_by": "HASH (project_id)"},
)


globals().update(
{
f"DbGroupingRecord{i}": type(
f"DbGroupingRecord{i}",
(DbGroupingRecordBase, Base),
dict(
__tablename__=f"grouping_records_p{i}",
__table_args__=(
Index(
f"grouping_records_new_p{i}_stacktrace_embedding_idx",
"stacktrace_embedding",
postgresql_using="hnsw",
postgresql_with={"m": 16, "ef_construction": 200},
postgresql_ops={"stacktrace_embedding": "vector_cosine_ops"},
),
Index(
f"grouping_records_new_p{i}_project_id_idx",
"project_id",
),
UniqueConstraint(
"project_id", "hash", name=f"grouping_records_new_p{i}_project_id_hash_key"
),
),
),
)
for i in range(100)
}
)
Loading