Update app
This commit is contained in:
@@ -77,6 +77,57 @@ def create_app():
|
||||
if settings_cols and "public_domain" not in settings_cols:
|
||||
db.session.execute(db.text("ALTER TABLE app_settings ADD COLUMN public_domain VARCHAR(255)"))
|
||||
db.session.commit()
|
||||
|
||||
# DisplayPlaylist: create association table for multi-playlist displays.
|
||||
dp_cols = [
|
||||
r[1] for r in db.session.execute(db.text("PRAGMA table_info(display_playlist)")).fetchall()
|
||||
]
|
||||
if not dp_cols:
|
||||
# Create association table for multi-playlist displays.
|
||||
# Keep schema compatible with older DBs that include an autoincrement id and position.
|
||||
db.session.execute(
|
||||
db.text(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS display_playlist (
|
||||
id INTEGER PRIMARY KEY,
|
||||
display_id INTEGER NOT NULL,
|
||||
playlist_id INTEGER NOT NULL,
|
||||
position INTEGER NOT NULL DEFAULT 1,
|
||||
created_at DATETIME NOT NULL,
|
||||
UNIQUE(display_id, playlist_id),
|
||||
FOREIGN KEY(display_id) REFERENCES display (id),
|
||||
FOREIGN KEY(playlist_id) REFERENCES playlist (id)
|
||||
)
|
||||
"""
|
||||
)
|
||||
)
|
||||
db.session.commit()
|
||||
else:
|
||||
# Best-effort column additions for older/newer variants.
|
||||
if "position" not in dp_cols:
|
||||
db.session.execute(
|
||||
db.text("ALTER TABLE display_playlist ADD COLUMN position INTEGER NOT NULL DEFAULT 1")
|
||||
)
|
||||
db.session.commit()
|
||||
if "created_at" not in dp_cols:
|
||||
# Use CURRENT_TIMESTAMP as a reasonable default for existing rows.
|
||||
db.session.execute(
|
||||
db.text(
|
||||
"ALTER TABLE display_playlist ADD COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP"
|
||||
)
|
||||
)
|
||||
db.session.commit()
|
||||
if "id" not in dp_cols:
|
||||
# Cannot add PRIMARY KEY via ALTER TABLE; keep nullable for compatibility.
|
||||
db.session.execute(db.text("ALTER TABLE display_playlist ADD COLUMN id INTEGER"))
|
||||
db.session.commit()
|
||||
# Ensure uniqueness index exists (no-op if already present)
|
||||
db.session.execute(
|
||||
db.text(
|
||||
"CREATE UNIQUE INDEX IF NOT EXISTS uq_display_playlist_display_playlist ON display_playlist (display_id, playlist_id)"
|
||||
)
|
||||
)
|
||||
db.session.commit()
|
||||
except Exception:
|
||||
db.session.rollback()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user