38 lines
1000 B
Python
38 lines
1000 B
Python
|
|
import sqlite3
|
|
import os
|
|
|
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
DB_PATH = os.path.join(os.path.dirname(BASE_DIR), 'kis_stock.db')
|
|
|
|
def migrate():
|
|
print(f"Migrating database at {DB_PATH}...")
|
|
conn = sqlite3.connect(DB_PATH)
|
|
cursor = conn.cursor()
|
|
|
|
# Check if columns exist, if not add them
|
|
try:
|
|
cursor.execute("ALTER TABLE stocks ADD COLUMN name_eng VARCHAR")
|
|
print("Added name_eng")
|
|
except Exception as e:
|
|
print(f"Skipping name_eng: {e}")
|
|
|
|
try:
|
|
cursor.execute("ALTER TABLE stocks ADD COLUMN industry VARCHAR")
|
|
print("Added industry")
|
|
except Exception as e:
|
|
print(f"Skipping industry: {e}")
|
|
|
|
try:
|
|
cursor.execute("ALTER TABLE stocks ADD COLUMN type VARCHAR DEFAULT 'DOMESTIC'")
|
|
print("Added type")
|
|
except Exception as e:
|
|
print(f"Skipping type: {e}")
|
|
|
|
conn.commit()
|
|
conn.close()
|
|
print("Migration complete.")
|
|
|
|
if __name__ == "__main__":
|
|
migrate()
|