Files
Lark-Snooper/migrate_add_is_read.py

26 lines
694 B
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
"""给 messages 表添加 is_read 字段(默认 false)。"""
import os
import sqlite3
def main():
db_path = os.path.expanduser("~/.larkx/messages.db")
conn = sqlite3.connect(db_path)
try:
cursor = conn.execute("PRAGMA table_info(messages)")
columns = {row[1] for row in cursor.fetchall()}
if "is_read" in columns:
print("is_read 字段已存在,无需迁移")
return
conn.execute("ALTER TABLE messages ADD COLUMN is_read BOOLEAN DEFAULT 0")
conn.commit()
print("已添加 is_read 字段,默认 false")
finally:
conn.close()
if __name__ == "__main__":
main()