moving database files
This commit is contained in:
29
db/db.py
29
db/db.py
@@ -4,7 +4,16 @@ import threading
|
|||||||
from tinydb import TinyDB
|
from tinydb import TinyDB
|
||||||
|
|
||||||
DB_ENV = os.environ.get('DB_ENV', 'prod')
|
DB_ENV = os.environ.get('DB_ENV', 'prod')
|
||||||
base_dir = os.path.dirname(__file__)
|
|
||||||
|
|
||||||
|
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
if DB_ENV == 'prod':
|
||||||
|
base_dir = os.path.join(project_root, 'data/db')
|
||||||
|
else:
|
||||||
|
base_dir = os.path.join(project_root, 'test_data/db')
|
||||||
|
|
||||||
|
os.makedirs(base_dir, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
class LockedTable:
|
class LockedTable:
|
||||||
@@ -66,19 +75,11 @@ class LockedTable:
|
|||||||
|
|
||||||
# Setup DB files next to this module
|
# Setup DB files next to this module
|
||||||
|
|
||||||
if DB_ENV == 'test':
|
child_path = os.path.join(base_dir, 'children.json')
|
||||||
child_path = os.path.join(base_dir, 'test_children.json')
|
task_path = os.path.join(base_dir, 'tasks.json')
|
||||||
task_path = os.path.join(base_dir, 'test_tasks.json')
|
reward_path = os.path.join(base_dir, 'rewards.json')
|
||||||
reward_path = os.path.join(base_dir, 'test_rewards.json')
|
image_path = os.path.join(base_dir, 'images.json')
|
||||||
image_path = os.path.join(base_dir, 'test_images.json')
|
pending_reward_path = os.path.join(base_dir, 'pending_rewards.json')
|
||||||
pending_reward_path = os.path.join(base_dir, 'test_pending_rewards.json')
|
|
||||||
|
|
||||||
else:
|
|
||||||
child_path = os.path.join(base_dir, 'children.json')
|
|
||||||
task_path = os.path.join(base_dir, 'tasks.json')
|
|
||||||
reward_path = os.path.join(base_dir, 'rewards.json')
|
|
||||||
image_path = os.path.join(base_dir, 'images.json')
|
|
||||||
pending_reward_path = os.path.join(base_dir, 'pending_rewards.json')
|
|
||||||
|
|
||||||
# Use separate TinyDB instances/files for each collection
|
# Use separate TinyDB instances/files for each collection
|
||||||
_child_db = TinyDB(child_path, indent=2)
|
_child_db = TinyDB(child_path, indent=2)
|
||||||
|
|||||||
Reference in New Issue
Block a user