Squashed commit of the following:
commit cb82580f868b629902ba96c7f09f885b7d9c24dc Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 22:42:49 2025 +0200 Fix for postgres db migration. #5 commit 6a4505e2db1cdb2cec65e630b63535ba08c02fc4 Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 22:39:58 2025 +0200 Fix for postgres db migration. #4 commit 7d9a5bb12c591182e67d7d52f90d6b1a45260d9f Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 22:38:02 2025 +0200 Fix for postgres db migration. #3 commit 29dbb8b62d873dfbc4901b21e637a7181d545ec7 Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 22:35:08 2025 +0200 Fix for postgres db migration. #2 commit d5afc56290d05f53e06a77366214c605d0989c1d Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 22:33:09 2025 +0200 Fix for postgres db migration. commit 936008fe1c56b6e699c4a45b503507b6423e15eb Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 21:46:32 2025 +0200 Add changes for gunicorn. commit 464c71e5102117f35d05e1504165299ffa50c70c Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 20:30:29 2025 +0200 Add changes for Postgres migration.
This commit is contained in:
42
app.py
42
app.py
@@ -29,14 +29,14 @@ logging.basicConfig(level=logging.DEBUG)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////data/timetrack.db'
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', 'sqlite:////data/timetrack.db')
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'dev_key_for_timetrack')
|
||||
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=7) # Session lasts for 7 days
|
||||
|
||||
# Configure Flask-Mail
|
||||
app.config['MAIL_SERVER'] = os.environ.get('MAIL_SERVER', 'smtp.example.com')
|
||||
app.config['MAIL_PORT'] = int(os.environ.get('MAIL_PORT', 587))
|
||||
app.config['MAIL_PORT'] = int(os.environ.get('MAIL_PORT') or 587)
|
||||
app.config['MAIL_USE_TLS'] = os.environ.get('MAIL_USE_TLS', 'true').lower() in ['true', 'on', '1']
|
||||
app.config['MAIL_USERNAME'] = os.environ.get('MAIL_USERNAME', 'your-email@example.com')
|
||||
app.config['MAIL_PASSWORD'] = os.environ.get('MAIL_PASSWORD', 'your-password')
|
||||
@@ -57,19 +57,37 @@ db.init_app(app)
|
||||
# Consolidated migration using migrate_db module
|
||||
def run_migrations():
|
||||
"""Run all database migrations using the consolidated migrate_db module."""
|
||||
try:
|
||||
from migrate_db import run_all_migrations
|
||||
run_all_migrations()
|
||||
print("Database migrations completed successfully!")
|
||||
except ImportError as e:
|
||||
print(f"Error importing migrate_db: {e}")
|
||||
print("Falling back to basic table creation...")
|
||||
# Check if we're using PostgreSQL or SQLite
|
||||
database_url = app.config['SQLALCHEMY_DATABASE_URI']
|
||||
print(f"DEBUG: Database URL: {database_url}")
|
||||
|
||||
is_postgresql = 'postgresql://' in database_url or 'postgres://' in database_url
|
||||
print(f"DEBUG: Is PostgreSQL: {is_postgresql}")
|
||||
|
||||
if is_postgresql:
|
||||
print("Using PostgreSQL - skipping SQLite migrations, ensuring tables exist...")
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
init_system_settings()
|
||||
except Exception as e:
|
||||
print(f"Error during database migration: {e}")
|
||||
raise
|
||||
print("PostgreSQL setup completed successfully!")
|
||||
else:
|
||||
print("Using SQLite - running SQLite migrations...")
|
||||
try:
|
||||
from migrate_db import run_all_migrations
|
||||
run_all_migrations()
|
||||
print("SQLite database migrations completed successfully!")
|
||||
except ImportError as e:
|
||||
print(f"Error importing migrate_db: {e}")
|
||||
print("Falling back to basic table creation...")
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
init_system_settings()
|
||||
except Exception as e:
|
||||
print(f"Error during SQLite migration: {e}")
|
||||
print("Falling back to basic table creation...")
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
init_system_settings()
|
||||
|
||||
def migrate_to_company_model():
|
||||
"""Migrate existing data to support company model (stub - handled by migrate_db)"""
|
||||
|
||||
Reference in New Issue
Block a user