You currently have alembic_version and users because those are managed by the Auth service (which uses SQLAlchemy and Alembic migrations, relying on the DATABASE_URL Railway provides).
The missing tables belong to the Notification service:
subscriberssubscriber_sitessent_log
Why are they missing on Railway?
- The Notification service uses its own connection variables (
NOTIFICATION_PG_HOST,NOTIFICATION_PG_PORT, etc.) instead of the standardDATABASE_URLthat Railway provides. - In
services/notification/config.py, if you don't have HelloSMS or SMTP2GO credentials set up, it activatesNOTIFICATION_MOCK_MODE. - When
NOTIFICATION_MOCK_MODEis active, the database connection is entirely skipped, and subscriptions are saved in server memory (which resets every time Railway deploys or goes to sleep).
To fix this so it works perfectly on Railway, we need to:
- Use
DATABASE_URL: Update the notification database logic to use the same connection string (DATABASE_URL) that the rest of the application uses. - Decouple DB from Mock Mode: Ensure that the database always connects to PostgreSQL if the URL is provided, even if you are using Mock Mode for sending SMS/emails. This ensures subscriptions are permanently saved even if you don't have real SMS credentials configured.
- Auto-creation: Ensure the
init_db()function runs successfully on Railway and auto-creates the tables.
We will fetch DATABASE_URL to be used by the notification DB.
Add DATABASE_URL parsing alongside the existing Postgres variables.
We will change _connect() to use DATABASE_URL if it's available, and separate _use_mock_storage so it only activates if DATABASE_URL is entirely missing or the connection fails.
Change the logic so that the database is always initialized when the server starts if there is a DATABASE_URL.
Once we make these code changes and push them to Railway:
- Railway already injects a
DATABASE_URLenvironment variable automatically if you provisioned a PostgreSQL database. - When the app starts, it will see
DATABASE_URL, connect to PostgreSQL, and runCREATE TABLE IF NOT EXISTSfor the three missing notification tables. - Your subscribers will now be saved permanently in the database!
Does this approach sound good? If you approve, I will write the code to fix config.py and db.py to seamlessly use the Railway database connection.