2 months ago
When creating a table with the integrated system on railway i Am running into issues with data being duplicated into other colums and then not being able to edit or delete the existing data on the table. I receive the notification something was saved,deleted,etc. But the change never shows up. I've tried redeploying the database, refreshing the page, refreshing the entire bot, deleting and re-adding the database... Each time its the same issues. Is there something im missing - is the table integration just unusable? Previously for my code i used a config.json and everything in my bot worked fine locally. I cant seem to get my config.json to work with the bot so i figured i would switch it to database. But this has really stumped me. Any suggestions for a noobie?
For background the database will be monitored by a discord and twitch bot and updated and read in real time by both. Hopefully. The goal is to integrate it so twitch interactions will be turned into points per the user who enrolls into the system via discord. The concept isnt wholly new, i have seen it done before. so far i only have parts of the discord side programmed and running locally. Thanks for reading! And again any advice for a noobie is welcome here! - just don't tell me to quit trying xP
3 Replies
2 months ago
This thread has been opened as a bounty so the community can help solve it.
Status changed to Open Railway • 2 months ago
2 months ago
Is this happening in the Railway table editor or in your app? If it's the table editor, it sounds more like a UI issue than a database problem. I'd also check the data with a SQL client (psql, DBeaver, TablePlus, etc.) to see if the rows are actually changing there. That should help narrow down whether it's the editor or your code.
2 months ago
Ensure your CREATE TABLE statement includes an id column set as a serial primary key.
You can also run a SQL command via the Railway query interface to add a primary key to your current setup
a month ago
This is very unlikely to be fixed by redeploying the database. The key is to separate “is the data wrong in Postgres?” from “is the table editor/app showing stale data?”
First, query the database directly (Railway Query tab, psql, or any Postgres client). If direct SQL shows the edit/delete worked but the editor does not, that is an editor/UI issue. If SQL also shows duplicate rows, the bot schema/write pattern needs fixing.
For Discord + Twitch points, use one stable key per enrolled user and make the increment atomic. Do not read a points value in each bot, add to it in code, then write it back — two simultaneous events can overwrite each other.
Example schema:
CREATE TABLE user_points (
user_id TEXT PRIMARY KEY,
points BIGINT NOT NULL DEFAULT 0,
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);Then award points with an UPSERT:
INSERT INTO user_points (user_id, points)
VALUES ($1, $2)
ON CONFLICT (user_id) DO UPDATE
SET points = user_points.points + EXCLUDED.points,
updated_at = now()
RETURNING user_id, points;Before changing anything, check for duplicates:
SELECT user_id, COUNT(*)
FROM user_points
GROUP BY user_id
HAVING COUNT(*) > 1;If that returns rows, merge/delete duplicates before adding the unique key; otherwise ON CONFLICT cannot protect you.
Also, config.json works locally because it is a file. Railway deployments have ephemeral filesystem storage, so configuration should move to environment variables and permanent user/points data should live in Postgres via DATABASE_URL. The database itself is persistent; redeploying it will not repair a missing primary key or a non-atomic write pattern.
If you paste your current CREATE TABLE statement and the code that adds points, I can turn this into the exact migration and query for your bot.