SOY NV AI commited on
Commit ยท
ff774af
1
Parent(s): f40b5cd
Add DB schema check and migration scripts for tags column
Browse files- check_tags_table_schema.py +151 -0
- migrate_add_tags_column.py +111 -0
- ํ๊ทธ_์์ฑ_DB_์ ์ฅ_๋ฌธ์ _ํด๊ฒฐ.md +140 -0
check_tags_table_schema.py
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
"""uploaded_file ํ
์ด๋ธ์ tags ์ปฌ๋ผ ์กด์ฌ ์ฌ๋ถ ํ์ธ ๋ฐ ์์ """
|
| 4 |
+
import sys
|
| 5 |
+
import os
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
# ํ๋ก์ ํธ ๋ฃจํธ๋ฅผ Python ๊ฒฝ๋ก์ ์ถ๊ฐ
|
| 9 |
+
project_root = Path(__file__).parent
|
| 10 |
+
sys.path.insert(0, str(project_root))
|
| 11 |
+
|
| 12 |
+
from app import create_app
|
| 13 |
+
from app.database import db
|
| 14 |
+
from sqlalchemy import inspect, text
|
| 15 |
+
|
| 16 |
+
def check_and_fix_tags_column():
|
| 17 |
+
"""uploaded_file ํ
์ด๋ธ์ tags ์ปฌ๋ผ์ด ์๋์ง ํ์ธํ๊ณ ์์ผ๋ฉด ์ถ๊ฐ"""
|
| 18 |
+
app = create_app()
|
| 19 |
+
|
| 20 |
+
with app.app_context():
|
| 21 |
+
try:
|
| 22 |
+
print("\n" + "="*80)
|
| 23 |
+
print("๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ์ ๋ณด:")
|
| 24 |
+
print("="*80)
|
| 25 |
+
print(f"DB URI: {app.config.get('SQLALCHEMY_DATABASE_URI', 'N/A')}")
|
| 26 |
+
|
| 27 |
+
# DB ์์ง ๊ฐ์ ธ์ค๊ธฐ
|
| 28 |
+
engine = db.engine
|
| 29 |
+
|
| 30 |
+
# Inspector๋ก ํ
์ด๋ธ ๊ตฌ์กฐ ํ์ธ
|
| 31 |
+
inspector = inspect(engine)
|
| 32 |
+
|
| 33 |
+
# uploaded_file ํ
์ด๋ธ์ด ์๋์ง ํ์ธ
|
| 34 |
+
tables = inspector.get_table_names()
|
| 35 |
+
print(f"\n๋ฐ์ดํฐ๋ฒ ์ด์ค ํ
์ด๋ธ ๋ชฉ๋ก ({len(tables)}๊ฐ):")
|
| 36 |
+
for table in sorted(tables):
|
| 37 |
+
print(f" - {table}")
|
| 38 |
+
|
| 39 |
+
if 'uploaded_file' not in tables:
|
| 40 |
+
print("\nโ uploaded_file ํ
์ด๋ธ์ด ์กด์ฌํ์ง ์์ต๋๋ค!")
|
| 41 |
+
print(" ํ
์ด๋ธ์ ์์ฑํฉ๋๋ค...")
|
| 42 |
+
db.create_all()
|
| 43 |
+
print("โ
ํ
์ด๋ธ ์์ฑ ์๋ฃ")
|
| 44 |
+
return
|
| 45 |
+
|
| 46 |
+
# uploaded_file ํ
์ด๋ธ์ ์ปฌ๋ผ ํ์ธ
|
| 47 |
+
columns = inspector.get_columns('uploaded_file')
|
| 48 |
+
column_names = [col['name'] for col in columns]
|
| 49 |
+
|
| 50 |
+
print(f"\n{'='*80}")
|
| 51 |
+
print(f"uploaded_file ํ
์ด๋ธ ์ปฌ๋ผ ๋ชฉ๋ก ({len(columns)}๊ฐ):")
|
| 52 |
+
print('='*80)
|
| 53 |
+
for col in columns:
|
| 54 |
+
nullable = col.get('nullable', True)
|
| 55 |
+
nullable_str = "NULL ํ์ฉ" if nullable else "NOT NULL"
|
| 56 |
+
print(f" - {col['name']}: {col['type']} ({nullable_str})")
|
| 57 |
+
|
| 58 |
+
# tags ์ปฌ๋ผ ํ์ธ
|
| 59 |
+
if 'tags' in column_names:
|
| 60 |
+
print(f"\nโ
tags ์ปฌ๋ผ์ด ์กด์ฌํฉ๋๋ค!")
|
| 61 |
+
|
| 62 |
+
# tags ์ปฌ๋ผ์ ์์ธ ์ ๋ณด
|
| 63 |
+
tags_col = next((col for col in columns if col['name'] == 'tags'), None)
|
| 64 |
+
if tags_col:
|
| 65 |
+
print(f" ํ์
: {tags_col['type']}")
|
| 66 |
+
print(f" Nullable: {tags_col.get('nullable', True)}")
|
| 67 |
+
|
| 68 |
+
# ์ค์ ๋ฐ์ดํฐ ํ์ธ
|
| 69 |
+
print(f"\n{'='*80}")
|
| 70 |
+
print("ํ๊ทธ ๋ฐ์ดํฐ ํ์ธ:")
|
| 71 |
+
print('='*80)
|
| 72 |
+
|
| 73 |
+
result = db.session.execute(text("SELECT COUNT(*) FROM uploaded_file"))
|
| 74 |
+
total_files = result.scalar()
|
| 75 |
+
print(f"์ ์ฒด ํ์ผ ์: {total_files}")
|
| 76 |
+
|
| 77 |
+
result = db.session.execute(text("""
|
| 78 |
+
SELECT COUNT(*) FROM uploaded_file
|
| 79 |
+
WHERE tags IS NOT NULL AND tags != ''
|
| 80 |
+
"""))
|
| 81 |
+
files_with_tags = result.scalar()
|
| 82 |
+
print(f"ํ๊ทธ๊ฐ ์๋ ํ์ผ ์: {files_with_tags}")
|
| 83 |
+
|
| 84 |
+
if files_with_tags > 0:
|
| 85 |
+
result = db.session.execute(text("""
|
| 86 |
+
SELECT id, original_filename,
|
| 87 |
+
LENGTH(tags) as tag_length,
|
| 88 |
+
SUBSTR(tags, 1, 100) as tag_preview
|
| 89 |
+
FROM uploaded_file
|
| 90 |
+
WHERE tags IS NOT NULL AND tags != ''
|
| 91 |
+
ORDER BY id DESC
|
| 92 |
+
LIMIT 5
|
| 93 |
+
"""))
|
| 94 |
+
|
| 95 |
+
print(f"\n์ต๊ทผ ํ๊ทธ๊ฐ ์๋ ํ์ผ (์ต๋ 5๊ฐ):")
|
| 96 |
+
for row in result:
|
| 97 |
+
print(f" - ID: {row[0]}, ํ์ผ๋ช
: {row[1]}")
|
| 98 |
+
print(f" ํ๊ทธ ๊ธธ์ด: {row[2]} ๋ฌธ์")
|
| 99 |
+
print(f" ํ๊ทธ ๋ฏธ๋ฆฌ๋ณด๊ธฐ: {row[3]}...")
|
| 100 |
+
else:
|
| 101 |
+
print("\nโ ๏ธ ํ๊ทธ๊ฐ ์๋ ํ์ผ์ด ์์ต๋๋ค.")
|
| 102 |
+
print(" '์ผ๋ฐ ํ๊ทธ ์์ฑ' ๋๋ '์์ธ ํ๊ทธ ์์ฑ'์ ์คํํ ํ ๋ค์ ํ์ธํด์ฃผ์ธ์.")
|
| 103 |
+
|
| 104 |
+
else:
|
| 105 |
+
print(f"\nโ tags ์ปฌ๋ผ์ด ์กด์ฌํ์ง ์์ต๋๋ค!")
|
| 106 |
+
print(" ์ปฌ๋ผ์ ์ถ๊ฐํฉ๋๋ค...")
|
| 107 |
+
|
| 108 |
+
# SQLite์ธ ๊ฒฝ์ฐ
|
| 109 |
+
if 'sqlite' in str(engine.url):
|
| 110 |
+
print(" SQLite ๋ฐ์ดํฐ๋ฒ ์ด์ค ๊ฐ์ง")
|
| 111 |
+
db.session.execute(text("ALTER TABLE uploaded_file ADD COLUMN tags TEXT"))
|
| 112 |
+
db.session.commit()
|
| 113 |
+
print("โ
tags ์ปฌ๋ผ ์ถ๊ฐ ์๋ฃ (SQLite)")
|
| 114 |
+
else:
|
| 115 |
+
# PostgreSQL, MySQL ๋ฑ ๋ค๋ฅธ DB
|
| 116 |
+
print(f" {engine.url.drivername} ๋ฐ์ดํฐ๋ฒ ์ด์ค ๊ฐ์ง")
|
| 117 |
+
try:
|
| 118 |
+
db.session.execute(text("ALTER TABLE uploaded_file ADD COLUMN tags TEXT"))
|
| 119 |
+
db.session.commit()
|
| 120 |
+
print("โ
tags ์ปฌ๋ผ ์ถ๊ฐ ์๋ฃ")
|
| 121 |
+
except Exception as e:
|
| 122 |
+
print(f"โ ์ปฌ๋ผ ์ถ๊ฐ ์คํจ: {e}")
|
| 123 |
+
db.session.rollback()
|
| 124 |
+
raise
|
| 125 |
+
|
| 126 |
+
# ๋ค์ ํ์ธ
|
| 127 |
+
inspector = inspect(engine)
|
| 128 |
+
columns = inspector.get_columns('uploaded_file')
|
| 129 |
+
column_names = [col['name'] for col in columns]
|
| 130 |
+
if 'tags' in column_names:
|
| 131 |
+
print("โ
ํ์ธ: tags ์ปฌ๋ผ์ด ์ฑ๊ณต์ ์ผ๋ก ์ถ๊ฐ๋์์ต๋๋ค!")
|
| 132 |
+
else:
|
| 133 |
+
print("โ ๊ฒฝ๊ณ : ์ปฌ๋ผ ์ถ๊ฐ ํ์๋ ํ์ธ๋์ง ์์ต๋๋ค!")
|
| 134 |
+
|
| 135 |
+
print("\n" + "="*80)
|
| 136 |
+
print("ํ์ธ ์๋ฃ")
|
| 137 |
+
print("="*80)
|
| 138 |
+
|
| 139 |
+
except Exception as e:
|
| 140 |
+
print(f"\nโ ์ค๋ฅ ๋ฐ์: {e}")
|
| 141 |
+
import traceback
|
| 142 |
+
traceback.print_exc()
|
| 143 |
+
db.session.rollback()
|
| 144 |
+
sys.exit(1)
|
| 145 |
+
|
| 146 |
+
if __name__ == '__main__':
|
| 147 |
+
print("="*80)
|
| 148 |
+
print("uploaded_file ํ
์ด๋ธ tags ์ปฌ๋ผ ํ์ธ ๋ฐ ์์ ")
|
| 149 |
+
print("="*80)
|
| 150 |
+
check_and_fix_tags_column()
|
| 151 |
+
|
migrate_add_tags_column.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
"""
|
| 4 |
+
uploaded_file ํ
์ด๋ธ์ tags ์ปฌ๋ผ ์ถ๊ฐ ๋ง์ด๊ทธ๋ ์ด์
์คํฌ๋ฆฝํธ
|
| 5 |
+
์ค์๋ฒ์์ ์คํํ์ฌ tags ์ปฌ๋ผ์ด ์์ผ๋ฉด ์ถ๊ฐํฉ๋๋ค.
|
| 6 |
+
"""
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
# ํ๋ก์ ํธ ๋ฃจํธ๋ฅผ Python ๊ฒฝ๋ก์ ์ถ๊ฐ
|
| 12 |
+
project_root = Path(__file__).parent
|
| 13 |
+
sys.path.insert(0, str(project_root))
|
| 14 |
+
|
| 15 |
+
from app import create_app
|
| 16 |
+
from app.database import db
|
| 17 |
+
from sqlalchemy import inspect, text
|
| 18 |
+
|
| 19 |
+
def migrate_add_tags_column():
|
| 20 |
+
"""uploaded_file ํ
์ด๋ธ์ tags ์ปฌ๋ผ ์ถ๊ฐ"""
|
| 21 |
+
app = create_app()
|
| 22 |
+
|
| 23 |
+
with app.app_context():
|
| 24 |
+
try:
|
| 25 |
+
print("="*80)
|
| 26 |
+
print("uploaded_file ํ
์ด๋ธ tags ์ปฌ๋ผ ๋ง์ด๊ทธ๋ ์ด์
")
|
| 27 |
+
print("="*80)
|
| 28 |
+
|
| 29 |
+
# DB ์์ง ๊ฐ์ ธ์ค๊ธฐ
|
| 30 |
+
engine = db.engine
|
| 31 |
+
print(f"\n๋ฐ์ดํฐ๋ฒ ์ด์ค: {engine.url}")
|
| 32 |
+
|
| 33 |
+
# Inspector๋ก ํ
์ด๋ธ ๊ตฌ์กฐ ํ์ธ
|
| 34 |
+
inspector = inspect(engine)
|
| 35 |
+
|
| 36 |
+
# uploaded_file ํ
์ด๋ธ์ด ์๋์ง ํ์ธ
|
| 37 |
+
tables = inspector.get_table_names()
|
| 38 |
+
if 'uploaded_file' not in tables:
|
| 39 |
+
print("โ uploaded_file ํ
์ด๋ธ์ด ์กด์ฌํ์ง ์์ต๋๋ค!")
|
| 40 |
+
print(" ๋จผ์ ์ ํ๋ฆฌ์ผ์ด์
์ ์คํํ์ฌ ํ
์ด๋ธ์ ์์ฑํ์ธ์.")
|
| 41 |
+
return False
|
| 42 |
+
|
| 43 |
+
# uploaded_file ํ
์ด๋ธ์ ์ปฌ๋ผ ํ์ธ
|
| 44 |
+
columns = inspector.get_columns('uploaded_file')
|
| 45 |
+
column_names = [col['name'] for col in columns]
|
| 46 |
+
|
| 47 |
+
print(f"\nํ์ฌ ์ปฌ๋ผ ๋ชฉ๋ก: {', '.join(column_names)}")
|
| 48 |
+
|
| 49 |
+
# tags ์ปฌ๋ผ ํ์ธ
|
| 50 |
+
if 'tags' in column_names:
|
| 51 |
+
print("\nโ
tags ์ปฌ๋ผ์ด ์ด๋ฏธ ์กด์ฌํฉ๋๋ค!")
|
| 52 |
+
print(" ๋ง์ด๊ทธ๋ ์ด์
์ด ํ์ํ์ง ์์ต๋๋ค.")
|
| 53 |
+
return True
|
| 54 |
+
|
| 55 |
+
# tags ์ปฌ๋ผ ์ถ๊ฐ
|
| 56 |
+
print("\nโ ๏ธ tags ์ปฌ๋ผ์ด ์์ต๋๋ค. ์ถ๊ฐํฉ๋๋ค...")
|
| 57 |
+
|
| 58 |
+
# SQLite์ธ ๊ฒฝ์ฐ
|
| 59 |
+
if 'sqlite' in str(engine.url):
|
| 60 |
+
print(" SQLite ๋ฐ์ดํฐ๋ฒ ์ด์ค ๊ฐ์ง")
|
| 61 |
+
db.session.execute(text("ALTER TABLE uploaded_file ADD COLUMN tags TEXT"))
|
| 62 |
+
db.session.commit()
|
| 63 |
+
print("โ
tags ์ปฌ๋ผ ์ถ๊ฐ ์๋ฃ (SQLite)")
|
| 64 |
+
else:
|
| 65 |
+
# PostgreSQL, MySQL ๋ฑ ๋ค๋ฅธ DB
|
| 66 |
+
db_type = engine.url.drivername
|
| 67 |
+
print(f" {db_type} ๋ฐ์ดํฐ๋ฒ ์ด์ค ๊ฐ์ง")
|
| 68 |
+
try:
|
| 69 |
+
if 'postgresql' in db_type or 'postgres' in db_type:
|
| 70 |
+
# PostgreSQL
|
| 71 |
+
db.session.execute(text("ALTER TABLE uploaded_file ADD COLUMN IF NOT EXISTS tags TEXT"))
|
| 72 |
+
elif 'mysql' in db_type:
|
| 73 |
+
# MySQL
|
| 74 |
+
db.session.execute(text("ALTER TABLE uploaded_file ADD COLUMN tags TEXT"))
|
| 75 |
+
else:
|
| 76 |
+
# ๊ธฐํ
|
| 77 |
+
db.session.execute(text("ALTER TABLE uploaded_file ADD COLUMN tags TEXT"))
|
| 78 |
+
|
| 79 |
+
db.session.commit()
|
| 80 |
+
print("โ
tags ์ปฌ๋ผ ์ถ๊ฐ ์๋ฃ")
|
| 81 |
+
except Exception as e:
|
| 82 |
+
print(f"โ ์ปฌ๋ผ ์ถ๊ฐ ์คํจ: {e}")
|
| 83 |
+
db.session.rollback()
|
| 84 |
+
import traceback
|
| 85 |
+
traceback.print_exc()
|
| 86 |
+
return False
|
| 87 |
+
|
| 88 |
+
# ๋ค์ ํ์ธ
|
| 89 |
+
inspector = inspect(engine)
|
| 90 |
+
columns = inspector.get_columns('uploaded_file')
|
| 91 |
+
column_names = [col['name'] for col in columns]
|
| 92 |
+
|
| 93 |
+
if 'tags' in column_names:
|
| 94 |
+
print("\nโ
ํ์ธ: tags ์ปฌ๋ผ์ด ์ฑ๊ณต์ ์ผ๋ก ์ถ๊ฐ๋์์ต๋๋ค!")
|
| 95 |
+
print(" ์ด์ '์ผ๋ฐ ํ๊ทธ ์์ฑ'๊ณผ '์์ธ ํ๊ทธ ์์ฑ' ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.")
|
| 96 |
+
return True
|
| 97 |
+
else:
|
| 98 |
+
print("\nโ ๊ฒฝ๊ณ : ์ปฌ๋ผ ์ถ๊ฐ ํ์๋ ํ์ธ๋์ง ์์ต๋๋ค!")
|
| 99 |
+
return False
|
| 100 |
+
|
| 101 |
+
except Exception as e:
|
| 102 |
+
print(f"\nโ ์ค๋ฅ ๋ฐ์: {e}")
|
| 103 |
+
import traceback
|
| 104 |
+
traceback.print_exc()
|
| 105 |
+
db.session.rollback()
|
| 106 |
+
return False
|
| 107 |
+
|
| 108 |
+
if __name__ == '__main__':
|
| 109 |
+
success = migrate_add_tags_column()
|
| 110 |
+
sys.exit(0 if success else 1)
|
| 111 |
+
|
ํ๊ทธ_์์ฑ_DB_์ ์ฅ_๋ฌธ์ _ํด๊ฒฐ.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ํ๊ทธ ์์ฑ DB ์ ์ฅ ๋ฌธ์ ํด๊ฒฐ ๊ฐ์ด๋
|
| 2 |
+
|
| 3 |
+
## ๋ฌธ์ ์ํฉ
|
| 4 |
+
์ค์๋ฒ์์ '์ผ๋ฐ ํ๊ทธ ์์ฑ'๊ณผ '์์ธ ํ๊ทธ ์์ฑ'์ ์คํํ๋๋ฐ ๊ฒฐ๊ณผ ๊ฐ์ด DB์ ์ ์ฅ๋์ง ์๋ ๋ฌธ์
|
| 5 |
+
|
| 6 |
+
## ์์ธ ๋ถ์
|
| 7 |
+
๊ฐ์ฅ ๊ฐ๋ฅ์ฑ ๋์ ์์ธ: **`uploaded_file` ํ
์ด๋ธ์ `tags` ์ปฌ๋ผ์ด ์์**
|
| 8 |
+
|
| 9 |
+
## ํด๊ฒฐ ๋ฐฉ๋ฒ
|
| 10 |
+
|
| 11 |
+
### 1๋จ๊ณ: DB ์คํค๋ง ํ์ธ
|
| 12 |
+
|
| 13 |
+
์ค์๋ฒ์์ ๋ค์ ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ์ฌ `tags` ์ปฌ๋ผ ์กด์ฌ ์ฌ๋ถ๋ฅผ ํ์ธํฉ๋๋ค:
|
| 14 |
+
|
| 15 |
+
```bash
|
| 16 |
+
python check_tags_table_schema.py
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
๋๋ ๊ฐ์ํ๊ฒฝ ์ฌ์ฉ ์:
|
| 20 |
+
```bash
|
| 21 |
+
.\venv\Scripts\python.exe check_tags_table_schema.py
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
### 2๋จ๊ณ: tags ์ปฌ๋ผ ์ถ๊ฐ (ํ์ํ ๊ฒฝ์ฐ)
|
| 25 |
+
|
| 26 |
+
`tags` ์ปฌ๋ผ์ด ์๋ค๋ฉด ๋ค์ ๋ง์ด๊ทธ๋ ์ด์
์คํฌ๋ฆฝํธ๋ฅผ ์คํํฉ๋๋ค:
|
| 27 |
+
|
| 28 |
+
```bash
|
| 29 |
+
python migrate_add_tags_column.py
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
๋๋ ๊ฐ์ํ๊ฒฝ ์ฌ์ฉ ์:
|
| 33 |
+
```bash
|
| 34 |
+
.\venv\Scripts\python.exe migrate_add_tags_column.py
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
### 3๋จ๊ณ: ํ์ธ
|
| 38 |
+
|
| 39 |
+
๋ง์ด๊ทธ๋ ์ด์
ํ ๋ค์ ํ์ธ:
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
python check_tags_table_schema.py
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
`tags` ์ปฌ๋ผ์ด ์ถ๊ฐ๋์๋์ง ํ์ธํ๊ณ , ํ๊ทธ ์์ฑ ๊ธฐ๋ฅ์ ๋ค์ ํ
์คํธํฉ๋๋ค.
|
| 46 |
+
|
| 47 |
+
## ์ถ๊ฐ ํ์ธ ์ฌํญ
|
| 48 |
+
|
| 49 |
+
### 1. ์๋ฒ ๋ก๊ทธ ํ์ธ
|
| 50 |
+
ํ๊ทธ ์์ฑ ์คํ ์ ์๋ฒ ๋ก๊ทธ์์ ๋ค์ ๋ฉ์์ง๋ฅผ ํ์ธํ์ธ์:
|
| 51 |
+
|
| 52 |
+
- `[์ผ๋ฐ ํ๊ทธ ์์ฑ] DB ์ ์ฅ ์ฑ๊ณต` ๋๋ `[์์ธ ํ๊ทธ ์์ฑ] DB ์ ์ฅ ์ฑ๊ณต`
|
| 53 |
+
- `[์ผ๋ฐ ํ๊ทธ ์์ฑ] ๊ฒฝ๊ณ : DB ์ ์ฅ ํ ํ๊ทธ๊ฐ None์
๋๋ค!` (์ด ๋ฉ์์ง๊ฐ ๋์ค๋ฉด ๋ฌธ์ ์์)
|
| 54 |
+
|
| 55 |
+
### 2. DB ์ง์ ํ์ธ
|
| 56 |
+
์ค์๋ฒ DB์ ์ง์ ์ ์ํ์ฌ ํ์ธ:
|
| 57 |
+
|
| 58 |
+
```sql
|
| 59 |
+
-- ์ปฌ๋ผ ํ์ธ
|
| 60 |
+
PRAGMA table_info(uploaded_file); -- SQLite
|
| 61 |
+
-- ๋๋
|
| 62 |
+
SELECT column_name, data_type
|
| 63 |
+
FROM information_schema.columns
|
| 64 |
+
WHERE table_name = 'uploaded_file'; -- PostgreSQL
|
| 65 |
+
|
| 66 |
+
-- ํ๊ทธ ๋ฐ์ดํฐ ํ์ธ
|
| 67 |
+
SELECT id, original_filename,
|
| 68 |
+
CASE WHEN tags IS NULL THEN 'NULL'
|
| 69 |
+
WHEN tags = '' THEN 'EMPTY'
|
| 70 |
+
ELSE 'HAS DATA' END as tag_status,
|
| 71 |
+
LENGTH(tags) as tag_length
|
| 72 |
+
FROM uploaded_file
|
| 73 |
+
ORDER BY id DESC
|
| 74 |
+
LIMIT 10;
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
### 3. ์ฝ๋ ํ์ธ
|
| 78 |
+
ํ๊ทธ ์์ฑ ํจ์๋ ๋ค์ ์์น์ ์์ต๋๋ค:
|
| 79 |
+
- ์ผ๋ฐ ํ๊ทธ: `app/routes.py` - `generate_simple_tags()` ํจ์ (๋ผ์ธ 5301)
|
| 80 |
+
- ์์ธ ํ๊ทธ: `app/routes.py` - `generate_detailed_tags()` ํจ์ (๋ผ์ธ 4952)
|
| 81 |
+
|
| 82 |
+
์ ์ฅ ๋ก์ง:
|
| 83 |
+
```python
|
| 84 |
+
tags_json_str = json.dumps(tags_data_with_type, ensure_ascii=False)
|
| 85 |
+
file.tags = tags_json_str
|
| 86 |
+
db.session.commit()
|
| 87 |
+
db.session.refresh(file)
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## ์์๋๋ ๋ฌธ์ ์ ํด๊ฒฐ์ฑ
|
| 91 |
+
|
| 92 |
+
### ๋ฌธ์ 1: tags ์ปฌ๋ผ์ด ์์
|
| 93 |
+
**์ฆ์**: ํ๊ทธ ์์ฑ์ ์ฑ๊ณตํ์ง๋ง DB์ ์ ์ฅ๋์ง ์์
|
| 94 |
+
**ํด๊ฒฐ**: `migrate_add_tags_column.py` ์คํ
|
| 95 |
+
|
| 96 |
+
### ๋ฌธ์ 2: DB ์ฐ๊ฒฐ ๋ฌธ์
|
| 97 |
+
**์ฆ์**: ํ๊ทธ ์์ฑ ์ ์๋ฌ ๋ฐ์
|
| 98 |
+
**ํด๊ฒฐ**: DB ์ฐ๊ฒฐ ์ค์ ํ์ธ (`.env` ํ์ผ์ `DATABASE_URL`)
|
| 99 |
+
|
| 100 |
+
### ๋ฌธ์ 3: ํธ๋์ญ์
๋กค๋ฐฑ
|
| 101 |
+
**์ฆ์**: ์ ์ฅ์ ๋์ง๋ง ๋ฐ๋ก ์ฌ๋ผ์ง
|
| 102 |
+
**ํด๊ฒฐ**: ์๋ฒ ๋ก๊ทธ์์ ์๋ฌ ๋ฉ์์ง ํ์ธ, `db.session.rollback()` ํธ์ถ ์ฌ๋ถ ํ์ธ
|
| 103 |
+
|
| 104 |
+
### ๋ฌธ์ 4: JSON ํ์ฑ ์คํจ
|
| 105 |
+
**์ฆ์**: AI ์๋ต์ ๋ฐ์์ง๋ง ์ ์ฅ ์คํจ
|
| 106 |
+
**ํด๊ฒฐ**: ์๋ฒ ๋ก๊ทธ์์ JSON ํ์ฑ ์๋ฌ ํ์ธ, AI ๋ชจ๋ธ ์๋ต ํ์ ํ์ธ
|
| 107 |
+
|
| 108 |
+
## ์ค์๋ฒ์์ ์คํ ๋ฐฉ๋ฒ
|
| 109 |
+
|
| 110 |
+
### SSH ์ ์ ํ
|
| 111 |
+
```bash
|
| 112 |
+
# ํ๋ก์ ํธ ๋๋ ํ ๋ฆฌ๋ก ์ด๋
|
| 113 |
+
cd /path/to/project
|
| 114 |
+
|
| 115 |
+
# ๊ฐ์ํ๊ฒฝ ํ์ฑํ (์๋ ๊ฒฝ์ฐ)
|
| 116 |
+
source venv/bin/activate # Linux/Mac
|
| 117 |
+
# ๋๋
|
| 118 |
+
.\venv\Scripts\activate # Windows
|
| 119 |
+
|
| 120 |
+
# ์คํฌ๋ฆฝํธ ์คํ
|
| 121 |
+
python check_tags_table_schema.py
|
| 122 |
+
python migrate_add_tags_column.py
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
### Docker ํ๊ฒฝ์ธ ๊ฒฝ์ฐ
|
| 126 |
+
```bash
|
| 127 |
+
# ์ปจํ
์ด๋ ์ ์
|
| 128 |
+
docker exec -it <container_name> bash
|
| 129 |
+
|
| 130 |
+
# ์คํฌ๋ฆฝํธ ์คํ
|
| 131 |
+
python check_tags_table_schema.py
|
| 132 |
+
python migrate_add_tags_column.py
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
## ์ฐธ๊ณ ํ์ผ
|
| 136 |
+
- `check_tags_table_schema.py`: DB ์คํค๋ง ํ์ธ ์คํฌ๋ฆฝํธ
|
| 137 |
+
- `migrate_add_tags_column.py`: tags ์ปฌ๋ผ ์ถ๊ฐ ๋ง์ด๊ทธ๋ ์ด์
|
| 138 |
+
- `app/routes.py`: ํ๊ทธ ์์ฑ ํจ์ (๋ผ์ธ 4952, 5301)
|
| 139 |
+
- `app/database.py`: UploadedFile ๋ชจ๋ธ ์ ์ (๋ผ์ธ 39-72)
|
| 140 |
+
|