Files
folkugat-web/scripts/07_add_playlist_hidden.py
2025-12-21 17:09:59 +01:00

46 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""
Migration script to add hidden column to playlists table and set all existing playlists to hidden.
"""
import sqlite3
import sys
from pathlib import Path
# Add the project root to the path so we can import project modules
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
from folkugat_web.config.db import DB_FILE
def main():
print(f"Connecting to database at: {DB_FILE}")
with sqlite3.connect(DB_FILE) as con:
cur = con.cursor()
# Check if hidden column already exists
cur.execute("PRAGMA table_info(playlists)")
columns = [column[1] for column in cur.fetchall()]
if 'hidden' not in columns:
print("Adding hidden column to playlists table...")
cur.execute("ALTER TABLE playlists ADD COLUMN hidden INTEGER NOT NULL DEFAULT 1")
print("Column added successfully.")
else:
print("Hidden column already exists.")
# Set all existing playlists to hidden (1)
print("Setting all existing playlists to hidden...")
cur.execute("UPDATE playlists SET hidden = 1")
updated_count = cur.rowcount
print(f"Updated {updated_count} playlists to hidden.")
con.commit()
print("Migration completed successfully!")
if __name__ == "__main__":
main()