From dd934ecd88d4e9e4b91e46e215cb3c4647f3c813 Mon Sep 17 00:00:00 2001 From: Mohammad Date: Fri, 3 Jul 2026 12:22:56 +0330 Subject: [PATCH] fix: detect admins.id type at runtime in api_keys migration --- .../versions/c9b48df42f10_add_api_keys_table.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/db/migrations/versions/c9b48df42f10_add_api_keys_table.py b/app/db/migrations/versions/c9b48df42f10_add_api_keys_table.py index 280217e78..920d37317 100644 --- a/app/db/migrations/versions/c9b48df42f10_add_api_keys_table.py +++ b/app/db/migrations/versions/c9b48df42f10_add_api_keys_table.py @@ -20,10 +20,18 @@ def upgrade() -> None: + # Match the actual type of admins.id (may be INT or BIGINT depending on + # whether the bigint migration has run on this database). + bind = op.get_bind() + inspector = sa.inspect(bind) + admins_id_type = inspector.get_columns("admins")[0]["type"] + is_bigint = "BIGINT" in str(admins_id_type).upper() + col_type = app.db.compiles_types.SqliteCompatibleBigInteger() if is_bigint else sa.Integer() + op.create_table( "api_keys", - sa.Column("id", app.db.compiles_types.SqliteCompatibleBigInteger(), autoincrement=True, nullable=False), - sa.Column("admin_id", app.db.compiles_types.SqliteCompatibleBigInteger(), nullable=False), + sa.Column("id", col_type, autoincrement=True, nullable=False), + sa.Column("admin_id", col_type, nullable=False), sa.Column("name", sa.String(length=128), nullable=False), sa.Column("note", sa.String(length=512), nullable=True), sa.Column("key_hash", sa.String(length=128), nullable=False),