06/05 Optimize app: add email notification
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""
|
||||
Migration: add budget alert columns.
|
||||
|
||||
Run once after deploying the budget alerts feature:
|
||||
python scripts/add_budget_alert_columns.py
|
||||
|
||||
Adds to `budgets`:
|
||||
alert_sent_80 BOOLEAN NOT NULL DEFAULT FALSE
|
||||
alert_sent_100 BOOLEAN NOT NULL DEFAULT FALSE
|
||||
|
||||
Adds to `users`:
|
||||
budget_alerts_enabled BOOLEAN NOT NULL DEFAULT FALSE
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from app import create_app
|
||||
from app.extensions import db
|
||||
|
||||
app = create_app()
|
||||
|
||||
with app.app_context():
|
||||
with db.engine.connect() as conn:
|
||||
# budgets table
|
||||
for col, default in [('alert_sent_80', '0'), ('alert_sent_100', '0')]:
|
||||
try:
|
||||
conn.execute(db.text(
|
||||
f"ALTER TABLE budgets ADD COLUMN {col} TINYINT(1) NOT NULL DEFAULT {default}"
|
||||
))
|
||||
print(f"Added budgets.{col}")
|
||||
except Exception as e:
|
||||
if 'Duplicate column' in str(e) or '1060' in str(e):
|
||||
print(f"budgets.{col} already exists — skipping")
|
||||
else:
|
||||
raise
|
||||
|
||||
# users table
|
||||
try:
|
||||
conn.execute(db.text(
|
||||
"ALTER TABLE users ADD COLUMN budget_alerts_enabled TINYINT(1) NOT NULL DEFAULT 0"
|
||||
))
|
||||
print("Added users.budget_alerts_enabled")
|
||||
except Exception as e:
|
||||
if 'Duplicate column' in str(e) or '1060' in str(e):
|
||||
print("users.budget_alerts_enabled already exists — skipping")
|
||||
else:
|
||||
raise
|
||||
|
||||
conn.commit()
|
||||
|
||||
print("Done.")
|
||||
Reference in New Issue
Block a user