28 lines
701 B
Python
28 lines
701 B
Python
|
# scripts/init_db.py
|
||
|
import sys
|
||
|
from pathlib import Path
|
||
|
|
||
|
# Add the project root to Python path
|
||
|
project_root = Path(__file__).resolve().parent.parent
|
||
|
sys.path.append(str(project_root))
|
||
|
|
||
|
from app.utils.db.models import Base
|
||
|
from sqlalchemy import create_engine
|
||
|
|
||
|
def init_db():
|
||
|
# Create data directory if it doesn't exist
|
||
|
data_dir = project_root / 'data'
|
||
|
data_dir.mkdir(exist_ok=True)
|
||
|
|
||
|
# Create database
|
||
|
db_path = data_dir / 'vpn.db'
|
||
|
db_url = f"sqlite:///{db_path}"
|
||
|
engine = create_engine(db_url)
|
||
|
|
||
|
# Create all tables
|
||
|
Base.metadata.create_all(engine)
|
||
|
print(f"Database initialized at: {db_path}")
|
||
|
return engine
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
init_db()
|