40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
from application import create_app
|
|
from app.models.database import db
|
|
from app.models.settings import Settings
|
|
import importlib
|
|
import os
|
|
|
|
app = create_app()
|
|
|
|
with app.app_context():
|
|
# Create all tables
|
|
db.create_all()
|
|
|
|
# Check if settings exist, create default if not
|
|
if not Settings.query.first():
|
|
default_settings = Settings(
|
|
download_path=app.config['DOWNLOAD_PATH'],
|
|
naming_format="{podcast_title}/{episode_title}",
|
|
auto_download=False,
|
|
max_downloads=5,
|
|
delete_after_days=30
|
|
)
|
|
db.session.add(default_settings)
|
|
db.session.commit()
|
|
print("Created default settings")
|
|
|
|
# Run all migration scripts
|
|
print("Running migrations...")
|
|
migrations_dir = os.path.join(os.path.dirname(__file__), 'migrations')
|
|
for filename in os.listdir(migrations_dir):
|
|
if filename.endswith('.py') and filename != '__init__.py':
|
|
module_name = f"migrations.{filename[:-3]}"
|
|
try:
|
|
migration_module = importlib.import_module(module_name)
|
|
if hasattr(migration_module, 'run_migration'):
|
|
print(f"Running migration: {filename}")
|
|
migration_module.run_migration()
|
|
except Exception as e:
|
|
print(f"Error running migration {filename}: {str(e)}")
|
|
|
|
print("Database initialized successfully!")
|