forked from lab/TPM
- Modified data_init_tw_v0.py to create database schema if tables don't exist - Updated both data_init scripts to use centralized config.py for DATABASE_URL support - Added init_railway_db.py script for one-time Railway database initialization from local machine This fixes the issue where Railway only runs Flask container, not the data_init container from docker-compose. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>master
parent
32ef5e1978
commit
ca52a05f19
3 changed files with 72 additions and 8 deletions
@ -0,0 +1,51 @@ |
||||
#!/usr/bin/env python3 |
||||
""" |
||||
One-time script to initialize Railway database from local machine. |
||||
Run this ONCE after deploying to Railway. |
||||
|
||||
Usage: |
||||
export DATABASE_URL="postgresql://user:password@host:port/database" |
||||
python3 init_railway_db.py |
||||
""" |
||||
import os |
||||
import sys |
||||
|
||||
# Check DATABASE_URL |
||||
DATABASE_URL = os.environ.get('DATABASE_URL') |
||||
if not DATABASE_URL: |
||||
print("❌ ERROR: DATABASE_URL environment variable not set") |
||||
print("\nGet your DATABASE_URL from Railway:") |
||||
print("1. Go to Railway dashboard") |
||||
print("2. Click on PostgreSQL service") |
||||
print("3. Go to 'Connect' tab") |
||||
print("4. Copy the 'Postgres Connection URL'") |
||||
print("\nThen run:") |
||||
print(' export DATABASE_URL="postgresql://..."') |
||||
print(" python3 init_railway_db.py") |
||||
sys.exit(1) |
||||
|
||||
print(f"✅ DATABASE_URL is set") |
||||
print(f"📊 Connecting to: {DATABASE_URL.split('@')[1] if '@' in DATABASE_URL else '***'}") |
||||
|
||||
# Import after checking DATABASE_URL |
||||
os.chdir('/Users/chiuyiting/Documents/GitHub/TPM') |
||||
sys.path.insert(0, '/Users/chiuyiting/Documents/GitHub/TPM/data_init') |
||||
|
||||
# Now run the initialization scripts |
||||
print("\n" + "="*60) |
||||
print("🚀 Starting Railway Database Initialization") |
||||
print("="*60 + "\n") |
||||
|
||||
print("📋 Step 1: Initializing Taiwan stock data (this will create schema)...") |
||||
import data_init.data_init_tw_v0 |
||||
print("\n✅ Taiwan data initialized\n") |
||||
|
||||
print("📋 Step 2: Initializing US stock data...") |
||||
import data_init.data_init_us_v0 |
||||
print("\n✅ US data initialized\n") |
||||
|
||||
print("\n" + "="*60) |
||||
print("🎉 Railway Database Initialization Complete!") |
||||
print("="*60) |
||||
print("\nYour Railway app should now work properly.") |
||||
print("Check https://nthutpm.up.railway.app") |
||||
Loading…
Reference in new issue