diff --git a/backend/app/__init__.py b/backend/app/__init__.py index 4002ef0..9ce677b 100644 --- a/backend/app/__init__.py +++ b/backend/app/__init__.py @@ -1,5 +1,6 @@ import os from flask import Flask, send_from_directory +from sqlalchemy import text from .extensions import db, migrate, cors from config import config @@ -21,6 +22,7 @@ def create_app(config_name=None): with app.app_context(): db.create_all() + _run_migrations() @app.route('/', defaults={'path': ''}) @app.route('/') @@ -31,3 +33,22 @@ def create_app(config_name=None): return send_from_directory(static_folder, 'index.html') return app + + +def _run_migrations(): + """ + Safe idempotent migrations for existing databases. + ALTER TABLE is a no-op if the column already exists (exception silently caught). + Add new columns here as the schema evolves. + """ + migrations = [ + 'ALTER TABLE projects ADD COLUMN drive_url VARCHAR(500)', + ] + with db.engine.connect() as conn: + for stmt in migrations: + try: + conn.execute(text(stmt)) + conn.commit() + except Exception: + # Column already exists — safe to ignore + pass