diff --git a/app.py b/app.py index 41dc9dd..a374c0d 100644 --- a/app.py +++ b/app.py @@ -7,6 +7,7 @@ Demoleads: python app.py demo (standaardmodellen uit demo/modellen al __version__ = '0.0.7' import csv +import fcntl import hashlib import hmac import io @@ -236,6 +237,14 @@ def migrate_documents(con): def init_db(): + """Schema en migraties; met een bestandsslot, want elke gunicorn-worker start dit bij het laden (anders voegen + twee workers dezelfde kolom toe of migreren ze dubbel).""" + with open(os.path.join(DATA, '.init.lock'), 'w') as lock: + fcntl.flock(lock, fcntl.LOCK_EX) + _init_db() + + +def _init_db(): con = sqlite3.connect(DB_PATH) with open(os.path.join(BASE, 'schema.sql')) as f: con.executescript(f.read())