File size: 2,199 Bytes
ae31891 208adf4 9c8de54 ef22967 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
"""
๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง์ด๊ทธ๋ ์ด์
์คํฌ๋ฆฝํธ
uploaded_file ํ
์ด๋ธ์ is_public ์ปฌ๋ผ์ ์ถ๊ฐํฉ๋๋ค.
"""
import sqlite3
import os
from pathlib import Path
# ๋ฐ์ดํฐ๋ฒ ์ด์ค ๊ฒฝ๋ก
db_path = Path(__file__).parent / 'instance' / 'finance_analysis.db'
def migrate_database():
"""๋ฐ์ดํฐ๋ฒ ์ด์ค์ is_public ์ปฌ๋ผ ์ถ๊ฐ"""
if not db_path.exists():
print(f"๋ฐ์ดํฐ๋ฒ ์ด์ค ํ์ผ์ด ์์ต๋๋ค: {db_path}")
print("์ฑ์ ์คํํ๋ฉด ์๋์ผ๋ก ์์ฑ๋ฉ๋๋ค.")
return
try:
conn = sqlite3.connect(str(db_path))
cursor = conn.cursor()
# uploaded_file ํ
์ด๋ธ์ is_public ์ปฌ๋ผ์ด ์๋์ง ํ์ธ
cursor.execute("PRAGMA table_info(uploaded_file)")
columns = [column[1] for column in cursor.fetchall()]
if 'is_public' in columns:
print("is_public ์ปฌ๋ผ์ด ์ด๋ฏธ ์กด์ฌํฉ๋๋ค.")
conn.close()
return
# is_public ์ปฌ๋ผ ์ถ๊ฐ (๊ธฐ๋ณธ๊ฐ: 0 = False)
print("is_public ์ปฌ๋ผ์ ์ถ๊ฐํ๋ ์ค...")
cursor.execute("ALTER TABLE uploaded_file ADD COLUMN is_public BOOLEAN DEFAULT 0")
conn.commit()
print("is_public ์ปฌ๋ผ์ด ์ฑ๊ณต์ ์ผ๋ก ์ถ๊ฐ๋์์ต๋๋ค.")
# ๊ธฐ์กด ๋ฐ์ดํฐ์ is_public ๊ฐ์ 0(False)์ผ๋ก ์ค์
cursor.execute("UPDATE uploaded_file SET is_public = 0 WHERE is_public IS NULL")
conn.commit()
print("๊ธฐ์กด ๋ฐ์ดํฐ์ is_public ๊ฐ์ 0(False)์ผ๋ก ์ค์ ํ์ต๋๋ค.")
conn.close()
print("๋ง์ด๊ทธ๋ ์ด์
์ด ์๋ฃ๋์์ต๋๋ค.")
except sqlite3.OperationalError as e:
print(f"์ค๋ฅ ๋ฐ์: {e}")
if "duplicate column name" in str(e).lower() or "already exists" in str(e).lower():
print("is_public ์ปฌ๋ผ์ด ์ด๋ฏธ ์กด์ฌํฉ๋๋ค.")
else:
raise
except Exception as e:
print(f"์์์น ๋ชปํ ์ค๋ฅ: {e}")
raise
if __name__ == '__main__':
print("=" * 60)
print("๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง์ด๊ทธ๋ ์ด์
: is_public ์ปฌ๋ผ ์ถ๊ฐ")
print("=" * 60)
migrate_database()
|