Using discord bot with railway
Anonymous
TRIALOP

2 years ago

I'm running a discord bot off a github repo, however i feel like the issue is that since it's pushing off the github repository it's only updating changes locally. so whenevever settings change via the bot in json files or things like that which would normally save i dont think its quite working the way it should, any help would be cool

120 Replies

Anonymous
TRIALOP

2 years ago

e973bf7d-52cf-4a8e-b30c-0829b7914a35


Anonymous
TRIALOP

2 years ago

when running locally this does not happen


2 years ago

you would want to store those json files in a volume
otherwise changes to those json files that are made wont persist between deployments.

or in the most ideal scenario, use a database like postgres.


Anonymous
TRIALOP

2 years ago

ahh shucklebutts 😠


Anonymous
TRIALOP

2 years ago

yea im like running an sqlite db


2 years ago

same goes for that, you would need to store that sqlite database file in a volume


Anonymous
TRIALOP

2 years ago

alright perfect ill see if that works and get back hold on


2 years ago

sounds good


Anonymous
TRIALOP

2 years ago

ok i feel like im tripping


Anonymous
TRIALOP

2 years ago

i added one for the json


Anonymous
TRIALOP

2 years ago

but now hte option is no longer popping up


Anonymous
TRIALOP

2 years ago

does that mean i can only have one vol


2 years ago

thats correct


Anonymous
TRIALOP

2 years ago

alr\


Anonymous
TRIALOP

2 years ago

@Brody


Anonymous
TRIALOP

2 years ago

i love you


Anonymous
TRIALOP

2 years ago

your a beautiful man


2 years ago

lol thanks


Anonymous
TRIALOP

2 years ago

got everything working


2 years ago

awsome, that was fast


Anonymous
TRIALOP

2 years ago

ok wait one more question


Anonymous
TRIALOP

2 years ago

if i push something from the github repo


Anonymous
TRIALOP

2 years ago

will it maintain the volume


Anonymous
TRIALOP

2 years ago

no matter what


2 years ago

yes, unless you have done something wrong, like accidently wrote code that deleted files in the volume


Anonymous
TRIALOP

2 years ago

alright perfect ty, you've been like genuinely sm help


2 years ago

happy to help 🙂


Anonymous
TRIALOP

2 years ago

@Brody hello


Anonymous
TRIALOP

2 years ago

im back


Anonymous
TRIALOP

2 years ago

i need you


Anonymous
TRIALOP

2 years ago

the bot is running, and it's checking through a script to see if a userid is in the sqlite db


Anonymous
TRIALOP

2 years ago

if it isnt it adds it


Anonymous
TRIALOP

2 years ago

if it is it resumes code that works fine


Anonymous
TRIALOP

2 years ago

however i think the issue is that since the script is checking a volume and the script isnt it the volume, its bugging out


Anonymous
TRIALOP

2 years ago

am i crazy


Anonymous
TRIALOP

2 years ago

second question can i just put everything in a volume


2 years ago

the script not being in the same location as the database would pose no real issues provided everything was done right, so please show any errors you are getting


2 years ago

not quite how it works


Anonymous
TRIALOP

2 years ago

thats the weird part


Anonymous
TRIALOP

2 years ago

its just not running


Anonymous
TRIALOP

2 years ago

like hold on


2 years ago

code issue then, but without any sort of logs there not too much I can help with


Anonymous
TRIALOP

2 years ago

It runs whenever i dont host it on here


Anonymous
TRIALOP

2 years ago

and logs properly


2 years ago

unfortunately that doesn't mean it's not a code issue


2 years ago

what's your volumes mount point


Anonymous
TRIALOP

2 years ago

a folder with everything i need volumeifieid


Anonymous
TRIALOP

2 years ago

i did a silly and i think i fucked it up


2 years ago

you aren't making much sense tbh


Anonymous
TRIALOP

2 years ago

yea i know sorry im just like


Anonymous
TRIALOP

2 years ago

running off a few hours of sleep give me like 1 sec


Anonymous
TRIALOP

2 years ago

Okay sorry, so essentially i'm running a currency manager bot of railway. Whenever you want to add/give currency, it checks an sqlite db thats in the vol to see if the userid is there, if not it'll add the userid + the currency. however when i run it on railway, it just does nothing if it detects the user isnt in the sqlite db i was wondering if this has anything to do with volumes or is just a code issue


2 years ago

how do you know that the user is in the database? you created an empty volume and then your code would have created an empty database because one didn't exist


Anonymous
TRIALOP

2 years ago

it turns the the target's @ into a userid and checks the entire thingy to see if it matches anything in the userid column


2 years ago

I'm not quite sure if that answers my question


2 years ago

if you are expecting the sqlite database in the volume to be the same as the one in github you are mistaken


Anonymous
TRIALOP

2 years ago

yea no i get that fs


2 years ago

so the database in the volume would be a fresh empty database, unless your app is capable of importing data to it?


Anonymous
TRIALOP

2 years ago

well yes, but it should persist the changes i do to it


2 years ago

how are you doing "the changes"


Anonymous
TRIALOP

2 years ago

as in adding/removing


Anonymous
TRIALOP

2 years ago

?


2 years ago

anything, how do you think you are making changes to the database


Anonymous
TRIALOP

2 years ago

datas = await func.DataFetch(self.bot, 'all', 'points', msg.guild.id)
            if len(datas) != 0:
                for data in datas:
                    if data[1] == msg.author.id:
                        AuthorData = data
                        break
                    else:
                        AuthorData = None
                if AuthorData:
                    await func.DataUpdate(self.bot, f"UPDATE points SET points = {AuthorData[2]+POINTS_TO_BE_GIVEN_PER_MESSAGE} WHERE guild_id = {AuthorData[0]} and user_id = {AuthorData[1]}")
                else:
                    await func.DataUpdate(self.bot, f"INSERT INTO points(guild_id, user_id, points) VALUES(?,?,?)", msg.guild.id, msg.author.id, POINTS_TO_BE_GIVEN_PER_MESSAGE)
            else:
                await func.DataUpdate(self.bot, f"INSERT INTO points(guild_id, user_id, points) VALUES(?,?,?)", msg.guild.id, msg.author.id, POINTS_TO_BE_GIVEN_PER_MESSAGE)
        except:
            print(traceback.format_exc())

if thats what your asking for


2 years ago

not really, I'm asking for a more broad overview, because right now it seems like you're just interacting with an empty database


Anonymous
TRIALOP

2 years ago

i probably am sounding very slow rn but i am so lost


2 years ago

or you aren't interacting with a database on the volume at all, because you have gotten your paths incorrect


2 years ago

what is the volumes mount point


Anonymous
TRIALOP

2 years ago

well no


Anonymous
TRIALOP

2 years ago

its /assets which is where the db, the functions that assist the db and anything else that needs to be in a volume is


Anonymous
TRIALOP

2 years ago

whenever a id that is already in the sqlite db is pulled it works perfectly


2 years ago

what is the volumes mount point


Anonymous
TRIALOP

2 years ago

1216109299890389200


2 years ago

show me the code that opens the sqlite database


Anonymous
TRIALOP

2 years ago

ok


Anonymous
TRIALOP

2 years ago

            datas = await func.DataFetch(self.bot, 'all', 'points', msg.guild.id)
            if len(datas) != 0:
                for data in datas:
                    if data[1] == msg.author.id:
                        AuthorData = data
                        break
                    else:
                        AuthorData = None
                if AuthorData:
                    await func.DataUpdate(self.bot, f"UPDATE points SET points = {AuthorData[2]+POINTS_TO_BE_GIVEN_PER_MESSAGE} WHERE guild_id = {AuthorData[0]} and user_id = {AuthorData[1]}")
                else:
                    await func.DataUpdate(self.bot, f"INSERT INTO points(guild_id, user_id, points) VALUES(?,?,?)", msg.guild.id, msg.author.id, POINTS_TO_BE_GIVEN_PER_MESSAGE)
            else:
                await func.DataUpdate(self.bot, f"INSERT INTO points(guild_id, user_id, points) VALUES(?,?,?)", msg.guild.id, msg.author.id, POINTS_TO_BE_GIVEN_PER_MESSAGE)
        except:
            print(traceback.format_exc())
async def DataFetch(bot, command, table, *vals):
    try:
        # There is no use for bot parameter in Sqlite3 but on migration to cloud database like postgresql, you will need it.
        query = f"SELECT * FROM {table}"
        if len(vals) == 1:
            query += f' WHERE guild_id = {vals[0]}'
        elif len(vals) == 2:
            query += f' WHERE guild_id = {vals[0]} and user_id = {vals[1]}'
        else:
            pass
        cursor.execute(query)
        if command == 'all':
            return cursor.fetchall()
        else:
            return cursor.fetchone()
    except:
        print(traceback.format_exc())

async def DataUpdate(bot, query, *vals):
    if len(vals) == 0:
        cursor.execute(query)
    else:
        cursor.execute(query, vals)
    db.commit()

2 years ago

sorry but that's not at all what I asked for


Anonymous
TRIALOP

2 years ago

oh my god yea sorry hold on


Anonymous
TRIALOP

2 years ago

db = sqlite3.connect('assets/data.sqlite') cursor = db.cursor()


2 years ago

nixpacks or dockerfile?


Anonymous
TRIALOP

2 years ago

nixpacks


2 years ago

then your mount point is wrong


2 years ago

it should be /app/assets


Anonymous
TRIALOP

2 years ago

uh okay hold on ill try that


2 years ago

please read


Anonymous
TRIALOP

2 years ago

uhh


Anonymous
TRIALOP

2 years ago

idk i dont think so


2 years ago

your mount point is wrong, please read the docs I linked


Anonymous
TRIALOP

2 years ago

it's not locating anything in the volume when i call it using the updated mountpoint


2 years ago

the volume is empty, therefore the assets folder is now going to be empty


2 years ago

your database being stored in the assets folder is not ideal anyway, it should be stored in a separate more applicably named folder


Anonymous
TRIALOP

2 years ago

so.. what do i do? how do i make the assets folder.. not empty 😭


2 years ago

mount the volume somewhere else like /app/data
then access the database from data/data.sqlite


Anonymous
TRIALOP

2 years ago

so every time i call something from the original folder i have to add /app infront of it


2 years ago

no


Anonymous
TRIALOP

2 years ago

because the db is not the only thing in a volume, so im confused


2 years ago

what else do you think is in the volume?


Anonymous
TRIALOP

2 years ago

all of these is what i have persisting in the volume

1216113768850002200


Anonymous
TRIALOP

2 years ago

i want*


2 years ago

none of those files are in the volume, what makes you say that


2 years ago

i think you may be misunderstanding the concept of a volume


Anonymous
TRIALOP

2 years ago

i am 😭


2 years ago

do this please


Anonymous
TRIALOP

2 years ago

ok


Anonymous
TRIALOP

2 years ago

now im getting errors about no tables


Anonymous
TRIALOP

2 years ago

in the sqlite db


2 years ago

yes because it's an empty database


2 years ago

empty volume, empty database


Anonymous
TRIALOP

2 years ago

ok


2 years ago

it would be must simpler to just use postgres


Anonymous
TRIALOP

2 years ago

im not sure how to use that


Anonymous
TRIALOP

2 years ago

so with volumes to be sure, when i put it in a volume its gonna start off empty no matter


Anonymous
TRIALOP

2 years ago

what


2 years ago

yes, empty volume, empty database


2 years ago

you can pre load stuff into the volume but it's not straightforward


Anonymous
TRIALOP

2 years ago

ok, is there documentation for that


2 years ago

no it's more so I tell you how to do it, but I would like to avoid that if possible, and instead ask you to abandon sqlite and use postgres or mysql


Anonymous
TRIALOP

2 years ago

ah


Anonymous
TRIALOP

2 years ago

ok


Anonymous
TRIALOP

2 years ago

ill come back in a bit i need a nap tysm


Loading...