forked from lab/TPM
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
51 lines
1.6 KiB
#!/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")
|
|
|