37 lines
No EOL
1.4 KiB
Python
37 lines
No EOL
1.4 KiB
Python
"""
|
|
Migration script to add calendar-related fields to the settings table.
|
|
"""
|
|
import sqlite3
|
|
from flask import current_app
|
|
|
|
def run_migration():
|
|
"""
|
|
Run the migration to add calendar-related fields to the settings table.
|
|
"""
|
|
# Get the database path from the app config
|
|
db_path = current_app.config['SQLALCHEMY_DATABASE_URI'].replace('sqlite:///', '')
|
|
|
|
# Connect to the database
|
|
conn = sqlite3.connect(db_path)
|
|
cursor = conn.cursor()
|
|
|
|
# Check if the columns already exist in the settings table
|
|
cursor.execute("PRAGMA table_info(settings)")
|
|
columns = [column[1] for column in cursor.fetchall()]
|
|
|
|
# Add the calendar_first_day column if it doesn't exist
|
|
if 'calendar_first_day' not in columns:
|
|
print("Adding 'calendar_first_day' column to settings table...")
|
|
cursor.execute("ALTER TABLE settings ADD COLUMN calendar_first_day TEXT DEFAULT 'Monday'")
|
|
|
|
# Add the calendar_show_monitored_only column if it doesn't exist
|
|
if 'calendar_show_monitored_only' not in columns:
|
|
print("Adding 'calendar_show_monitored_only' column to settings table...")
|
|
cursor.execute("ALTER TABLE settings ADD COLUMN calendar_show_monitored_only BOOLEAN DEFAULT 0")
|
|
|
|
# Commit the changes and close the connection
|
|
conn.commit()
|
|
conn.close()
|
|
|
|
print("Calendar settings migration completed successfully!")
|
|
return True |