feat: add Docker Compose setup with bind-mount appdata directory
- Dockerfile builds image with app source in /app_src - docker-entrypoint.sh syncs code from image on each start, inits DB - docker-compose.yml mounts ./appdata:/app for easy backup - backend/init_db.py for safe DB init (no drop_all) - backend/database.py supports DATABASE_URL env var - .dockerignore excludes venv, __pycache__, *.db, .git Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
27
backend/init_db.py
Normal file
27
backend/init_db.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from backend.models import Base, User
|
||||
from backend.database import engine
|
||||
from backend.security import get_password_hash
|
||||
|
||||
|
||||
def init_db():
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
Session = sessionmaker(bind=engine)
|
||||
db = Session()
|
||||
try:
|
||||
if not db.query(User).filter(User.username == 'admin').first():
|
||||
db.add(User(
|
||||
username='admin',
|
||||
password_hash=get_password_hash('admin'),
|
||||
role='admin',
|
||||
))
|
||||
db.commit()
|
||||
print("Created default admin user (login: admin / password: admin)")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
init_db()
|
||||
Reference in New Issue
Block a user