premier fix pour le discord bot qui envoie des reminders sur des versions de matchs qui n'existent plus
CI - Security, Lint & Tests / validate (push) Failing after 1m5s
CI - Security, Lint & Tests / validate (push) Failing after 1m5s
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"""Migration: Create indexes on date columns used by the 18:00 daily reminder.
|
||||
|
||||
Run this script to add indexes on the date columns that the Discord bot's
|
||||
daily reminder queries (Match.date, TeamMatch.date, Tryout.date,
|
||||
OneOnOneRequest.date). The app uses create_all() for new tables, but existing
|
||||
production databases need these added explicitly.
|
||||
|
||||
Usage: python migrations/add_reminder_date_indexes.py
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from app.app import create_app
|
||||
from app.extensions import db
|
||||
from sqlalchemy import text
|
||||
|
||||
app = create_app()
|
||||
|
||||
with app.app_context():
|
||||
indexes = [
|
||||
('ix_matches_date', 'matches', 'date'),
|
||||
('ix_team_matches_date', 'team_matches', 'date'),
|
||||
('ix_tryouts_date', 'tryouts', 'date'),
|
||||
('ix_one_on_one_requests_date', 'one_on_one_requests', 'date'),
|
||||
]
|
||||
|
||||
for index_name, table, column in indexes:
|
||||
db.session.execute(text(
|
||||
f'CREATE INDEX IF NOT EXISTS {index_name} ON {table} ({column})'
|
||||
))
|
||||
print(f'Index {index_name} on {table}({column}) ensured.')
|
||||
|
||||
db.session.commit()
|
||||
print('Migration complete.')
|
||||
Reference in New Issue
Block a user