Skip to content

Commit

Permalink
make id bigint sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
trillville committed Jul 17, 2024
1 parent 197c676 commit 97c67a1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
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")
4 changes: 2 additions & 2 deletions src/seer/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 97c67a1

Please sign in to comment.