fix: standardize exchange database path to use centralized data directory with environment variable
All checks were successful
API Endpoint Tests / test-api-endpoints (push) Successful in 38s
Documentation Validation / validate-docs (push) Successful in 10s
Integration Tests / test-service-integration (push) Successful in 57s
Python Tests / test-python (push) Successful in 1m32s
Security Scanning / security-scan (push) Successful in 1m7s
All checks were successful
API Endpoint Tests / test-api-endpoints (push) Successful in 38s
Documentation Validation / validate-docs (push) Successful in 10s
Integration Tests / test-service-integration (push) Successful in 57s
Python Tests / test-python (push) Successful in 1m32s
Security Scanning / security-scan (push) Successful in 1m7s
🔧 Database Path Standardization:
• Change DATABASE_URL environment variable to EXCHANGE_DATABASE_URL
• Update default database path from ./exchange.db to /var/lib/aitbc/data/exchange/exchange.db
• Apply consistent path resolution across all exchange database connections
• Update database.py, seed_market.py, and simple_exchange_api.py with new path
• Maintain backward compatibility through
This commit is contained in:
@@ -10,7 +10,7 @@ from sqlalchemy.pool import StaticPool
|
||||
from models import Base
|
||||
|
||||
# Database configuration
|
||||
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./exchange.db")
|
||||
DATABASE_URL = os.getenv("EXCHANGE_DATABASE_URL", "sqlite:////var/lib/aitbc/data/exchange/exchange.db")
|
||||
|
||||
# Create engine
|
||||
if DATABASE_URL.startswith("sqlite"):
|
||||
|
||||
@@ -7,7 +7,9 @@ from datetime import datetime
|
||||
def seed_initial_price():
|
||||
"""Create initial trades to establish market price"""
|
||||
|
||||
conn = sqlite3.connect('exchange.db')
|
||||
import os
|
||||
db_path = os.getenv("EXCHANGE_DATABASE_URL", "sqlite:////var/lib/aitbc/data/exchange/exchange.db").replace("sqlite:///", "")
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Create some initial trades at different price points
|
||||
|
||||
@@ -13,7 +13,9 @@ import random
|
||||
# Database setup
|
||||
def init_db():
|
||||
"""Initialize SQLite database"""
|
||||
conn = sqlite3.connect('exchange.db')
|
||||
import os
|
||||
db_path = os.getenv("EXCHANGE_DATABASE_URL", "sqlite:////var/lib/aitbc/data/exchange/exchange.db").replace("sqlite:///", "")
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Create tables
|
||||
@@ -59,7 +61,9 @@ def init_db():
|
||||
|
||||
def create_mock_trades():
|
||||
"""Create some mock trades"""
|
||||
conn = sqlite3.connect('exchange.db')
|
||||
import os
|
||||
db_path = os.getenv("EXCHANGE_DATABASE_URL", "sqlite:////var/lib/aitbc/data/exchange/exchange.db").replace("sqlite:///", "")
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Check if we have trades
|
||||
@@ -117,7 +121,9 @@ class ExchangeAPIHandler(BaseHTTPRequestHandler):
|
||||
query = urllib.parse.parse_qs(parsed.query)
|
||||
limit = int(query.get('limit', [20])[0])
|
||||
|
||||
conn = sqlite3.connect('exchange.db')
|
||||
import os
|
||||
db_path = os.getenv("EXCHANGE_DATABASE_URL", "sqlite:////var/lib/aitbc/data/exchange/exchange.db").replace("sqlite:///", "")
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
@@ -143,7 +149,9 @@ class ExchangeAPIHandler(BaseHTTPRequestHandler):
|
||||
|
||||
def get_orderbook(self):
|
||||
"""Get order book"""
|
||||
conn = sqlite3.connect('exchange.db')
|
||||
import os
|
||||
db_path = os.getenv("EXCHANGE_DATABASE_URL", "sqlite:////var/lib/aitbc/data/exchange/exchange.db").replace("sqlite:///", "")
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Get sell orders
|
||||
@@ -246,7 +254,10 @@ class ExchangeAPIHandler(BaseHTTPRequestHandler):
|
||||
|
||||
# Store order in local database for orderbook
|
||||
total = amount * price
|
||||
conn = sqlite3.connect('exchange.db')
|
||||
|
||||
import os
|
||||
db_path = os.getenv("EXCHANGE_DATABASE_URL", "sqlite:////var/lib/aitbc/data/exchange/exchange.db").replace("sqlite:///", "")
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
@@ -286,7 +297,9 @@ class ExchangeAPIHandler(BaseHTTPRequestHandler):
|
||||
# Fallback to database-only if blockchain is down
|
||||
total = amount * price
|
||||
|
||||
conn = sqlite3.connect('exchange.db')
|
||||
import os
|
||||
db_path = os.getenv("EXCHANGE_DATABASE_URL", "sqlite:////var/lib/aitbc/data/exchange/exchange.db").replace("sqlite:///", "")
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
|
||||
Reference in New Issue
Block a user