-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_db.py
More file actions
33 lines (22 loc) · 965 Bytes
/
Copy pathupdate_db.py
File metadata and controls
33 lines (22 loc) · 965 Bytes
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
"""
Curatarr — idempotent schema migration helper.
Runs ``Base.metadata.create_all`` against the live SQLite DB so any tables
newly declared in ``src/database/models.py`` are added. Existing tables
and data are left untouched (``create_all`` only emits ``CREATE TABLE IF
NOT EXISTS``). Safe to run as many times as you want.
Use after pulling a release that adds new tables, or after editing models
locally and wanting your dev DB to catch up without dropping data.
Usage::
python update_db.py
"""
import logging
from src.database.connection import engine
from src.database.models import Base
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("DB-Update")
def update_database():
logger.info("Checking the database for newly-declared tables...")
Base.metadata.create_all(bind=engine)
logger.info("Done. Any missing tables have been created; existing data is untouched.")
if __name__ == "__main__":
update_database()