mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-05-11 10:33:18 +08:00
Fix database sequence errors (#4777)
* Fix database upgrade script to handle existing identity columns Co-authored-by: jxxghp <jxxghp@live.cn> * Improve identity column conversion with error handling and cleanup Co-authored-by: jxxghp <jxxghp@live.cn> * Fix database upgrade script to handle existing identity columns Co-authored-by: jxxghp <jxxghp@live.cn> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: jxxghp <jxxghp@live.cn>
This commit is contained in:
@@ -59,7 +59,7 @@ def fix_table_sequence(connection, table_name):
|
||||
|
||||
# 检查表是否有id列
|
||||
result = connection.execute(sa.text(f"""
|
||||
SELECT column_name, data_type, is_nullable, column_default
|
||||
SELECT is_identity, column_default
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = '{table_name}'
|
||||
AND column_name = 'id'
|
||||
@@ -70,10 +70,10 @@ def fix_table_sequence(connection, table_name):
|
||||
print(f"表 {table_name} 没有id列,跳过")
|
||||
return
|
||||
|
||||
_, _, _, column_default = id_column
|
||||
is_identity, column_default = id_column
|
||||
|
||||
# 检查是否已经是Identity类型
|
||||
if column_default and 'GENERATED BY DEFAULT AS IDENTITY' in column_default:
|
||||
if is_identity == 'YES' or (column_default and 'GENERATED BY DEFAULT AS IDENTITY' in column_default):
|
||||
print(f"表 {table_name} 的id列已经是Identity类型,跳过")
|
||||
return
|
||||
|
||||
@@ -110,4 +110,8 @@ def convert_to_identity(connection, table_name):
|
||||
|
||||
except Exception as e:
|
||||
print(f"转换表 {table_name} 序列时出错: {e}")
|
||||
# 如果是已经存在的Identity错误,则忽略
|
||||
if "already an identity column" in str(e):
|
||||
print(f"表 {table_name} 的id列已经是Identity类型,忽略此错误")
|
||||
return
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user