From 97c67a1b09b375d2d28945c454caacd8fb358ddf Mon Sep 17 00:00:00 2001 From: Tillman Elser Date: Wed, 17 Jul 2024 16:54:31 -0700 Subject: [PATCH] make id bigint sequence --- .../versions/95b4ba4f731d_migration.py | 33 +++++++++++++++++++ src/seer/db.py | 4 +-- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/migrations/versions/95b4ba4f731d_migration.py diff --git a/src/migrations/versions/95b4ba4f731d_migration.py b/src/migrations/versions/95b4ba4f731d_migration.py new file mode 100644 index 000000000..366c90b07 --- /dev/null +++ b/src/migrations/versions/95b4ba4f731d_migration.py @@ -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") diff --git a/src/seer/db.py b/src/seer/db.py index 2d1c5e3f3..bd0493729 100644 --- a/src/seer/db.py +++ b/src/seer/db.py @@ -233,8 +233,8 @@ 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) + id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) + 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)