Add revision history log and music files ZIP backup
This commit is contained in:
parent
8246f641a2
commit
cda4d57859
4 changed files with 127 additions and 14 deletions
37
models.py
37
models.py
|
|
@ -55,6 +55,21 @@ CREATE TABLE IF NOT EXISTS requests (
|
|||
|
||||
CREATE INDEX IF NOT EXISTS idx_requests_status ON requests(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_requests_token ON requests(player_token);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS revision_history (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
request_id INTEGER NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
revision_count INTEGER NOT NULL,
|
||||
note TEXT,
|
||||
old_song_a_path TEXT,
|
||||
old_song_b_path TEXT,
|
||||
new_song_a_path TEXT,
|
||||
new_song_b_path TEXT,
|
||||
FOREIGN KEY (request_id) REFERENCES requests(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_revision_history_request ON revision_history(request_id);
|
||||
"""
|
||||
|
||||
|
||||
|
|
@ -168,6 +183,28 @@ def delete_request(request_id):
|
|||
db.commit()
|
||||
|
||||
|
||||
def log_revision(request_id, revision_count, note, old_a=None, old_b=None, new_a=None, new_b=None):
|
||||
"""Record a revision event in the revision_history table."""
|
||||
db = get_db()
|
||||
db.execute(
|
||||
"""INSERT INTO revision_history
|
||||
(request_id, revision_count, note, old_song_a_path, old_song_b_path, new_song_a_path, new_song_b_path)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)""",
|
||||
(request_id, revision_count, note, old_a, old_b, new_a, new_b)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
|
||||
def list_revision_history(request_id):
|
||||
"""Return all revision history rows for a request, oldest first."""
|
||||
db = get_db()
|
||||
rows = db.execute(
|
||||
'SELECT * FROM revision_history WHERE request_id = ? ORDER BY created_at ASC',
|
||||
(request_id,)
|
||||
).fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
def reset_all_requests():
|
||||
"""Delete every row in the requests table and reset id auto-increment."""
|
||||
db = get_db()
|
||||
|
|
|
|||
Reference in a new issue