from app import app, db, User
from flask_migrate import upgrade

def init_db():
    with app.app_context():
        # Create all tables
        db.create_all()
        # Run any pending migrations
        upgrade()
        
        # Create default admin user if it doesn't exist
        admin = User.query.filter_by(username='admin').first()
        if not admin:
            admin = User(username='admin')
            admin.set_password('admin123')  # You should change this password after first login
            db.session.add(admin)
            db.session.commit()
            print("Default admin user created!")

if __name__ == '__main__':
    init_db() 