-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit_db.py
More file actions
44 lines (37 loc) · 1.33 KB
/
Copy pathinit_db.py
File metadata and controls
44 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
init_db.py — Creates a clean, empty database with a default admin user.
Run this ONCE before first use, or to reset to factory defaults:
python init_db.py
Default credentials: admin / admin (change after first login!)
"""
import os
import sqlite3
from models import Base, engine, SessionLocal, User, Config, init_db
from auth import get_password_hash
print("Initializing NovaBak database...")
# Create all tables
init_db()
# Create clean admin user
db = SessionLocal()
try:
existing = db.query(User).filter(User.username == "admin").first()
if not existing:
hashed = get_password_hash("admin")
admin_user = User(username="admin", hashed_password=hashed, is_mfa_enabled=False)
db.add(admin_user)
db.commit()
print("[OK] Created default user: admin / admin")
else:
print("[INFO] Admin user already exists, skipping.")
# Ensure a config row exists
from models import Config
if not db.query(Config).first():
db.add(Config())
db.commit()
print("[OK] Created default config row.")
print("\n[OK] Database initialized successfully.")
print(" DB location:", os.path.abspath(os.path.join("data", "backup_system.db")))
print(" Login with: admin / admin")
print(" [!] Change your password after first login!")
finally:
db.close()