main: move db to data/ such that docker does not create a directory

This commit is contained in:
lemoer 2024-12-29 00:33:42 +01:00
parent f3c0e0c363
commit 05bbf2f8d1
5 changed files with 9 additions and 6 deletions

View File

@ -57,4 +57,9 @@ vi config.json
Rebuild containers: Rebuild containers:
``` ```
docker compose up --build -d docker compose up --build -d
``` ```
Change the ownership of the db, such that the host user 1000 can write it:
```
sudo chown -R 1000 data/
```

View File

@ -5,6 +5,7 @@ from result import Err, Ok, Result
from models import Task from models import Task
import argparse import argparse
from sqlmodel import Session, SQLModel, create_engine from sqlmodel import Session, SQLModel, create_engine
from main import *
import sys import sys
import dateparser import dateparser
@ -55,9 +56,6 @@ if __name__ == "__main__":
print("Invalid due date.", file=sys.stderr) print("Invalid due date.", file=sys.stderr)
exit(1) exit(1)
engine = create_engine("sqlite:///data.db")
SQLModel.metadata.create_all(engine)
with Session(engine) as session: with Session(engine) as session:
task = Task( task = Task(
name=args.name, name=args.name,

0
data/.keep Normal file
View File

View File

@ -12,4 +12,4 @@ services:
build: . build: .
volumes: volumes:
- "./config.json:/app/config.json" - "./config.json:/app/config.json"
- "./data.db:/app/data.db" - "./data:/app/data"

View File

@ -546,7 +546,7 @@ async def main(config: Config, session: Session):
with open("config.json", "r") as f: with open("config.json", "r") as f:
config = Config.model_validate(json.load(f)) config = Config.model_validate(json.load(f))
engine = create_engine("sqlite:///data.db") engine = create_engine("sqlite:///data/data.db")
SQLModel.metadata.create_all(engine) SQLModel.metadata.create_all(engine)
if __name__ == "__main__": if __name__ == "__main__":