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
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.
2 years ago
same goes for that, you would need to store that sqlite database file in a volume
2 years ago
sounds good
2 years ago
thats correct
2 years ago
lol thanks
2 years ago
awsome, that was fast
2 years ago
yes, unless you have done something wrong, like accidently wrote code that deleted files in the volume
2 years ago
happy to help 🙂
the bot is running, and it's checking through a script to see if a userid is in the sqlite db
however i think the issue is that since the script is checking a volume and the script isnt it the volume, its bugging out
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
2 years ago
code issue then, but without any sort of logs there not too much I can help with
2 years ago
unfortunately that doesn't mean it's not a code issue
2 years ago
what's your volumes mount point
2 years ago
you aren't making much sense tbh
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
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
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?
2 years ago
how are you doing "the changes"
2 years ago
anything, how do you think you are making changes to the database
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
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
its /assets which is where the db, the functions that assist the db and anything else that needs to be in a volume is
whenever a id that is already in the sqlite db is pulled it works perfectly
2 years ago
what is the volumes mount point
2 years ago
show me the code that opens the sqlite database
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
2 years ago
nixpacks or dockerfile?
2 years ago
then your mount point is wrong
2 years ago
it should be /app/assets
2 years ago
please read
2 years ago
your mount point is wrong, please read the docs I linked
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
2 years ago
mount the volume somewhere else like /app/data
then access the database from data/data.sqlite
so every time i call something from the original folder i have to add /app infront of it
2 years ago
no
2 years ago
what else do you think is in the volume?
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
2 years ago
do this please
2 years ago
yes because it's an empty database
2 years ago
empty volume, empty database
2 years ago
it would be must simpler to just use postgres
so with volumes to be sure, when i put it in a volume its gonna start off empty no matter
2 years ago
yes, empty volume, empty database
2 years ago
you can pre load stuff into the volume but it's not straightforward
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

