Sqlite DB
Is there a way I can add an sqlite database to a project in railway and have its data persist across deployments in my project?
Solution:Jump to solution
database.LoadAndMigrate("db/altera.db")
then mount the volume to /app/db
...37 Replies
Project ID:
dfc8d88b-459f-4ec8-9e35-824c0bc7fbc0
dfc8d88b-459f-4ec8-9e35-824c0bc7fbc0
currently I have a volume added to a deployment in my project, but when the deployment is redeployed, the volume is reset. Maybe I am not adding the sqlite db to the volume correctly?
the mount path for the volume is set as
/db
, and in my code, I store the sqlite database file as /db/sqlite.db
volumes are mounted to the root of your container and your app is in the
/app
directory in your container, to make /db
persist, you'll want to mount the volume to /app/db
ahh ok
crap didnt mean to delete
does the project ID allow you to see that about my project?
Conductors can't see anything inside your project, only team members can
when your app is built via nixpacks then your app is deployed into the
/app
directory by defaultmy app is deployed via docker
ooh i see, just make sure the volume is mounted on the global path of your db then
so in my dockerfile, if I set the WORKDIR to
/app
the volume should mount to /app/db
like you suggestedexactly right
sorry im kinda new to this.
no worries š
ok thanks for your help! I will go and try this out
happy to help
doesn't seem like it is working. When I set the mount path to
/app
, I get errors saying that /app/backend
is not found. When I set it to /app/server
the error disappears, but the database is not persistent as this directory is overwritten on each deployment.
Do you have any idea what is causing this?
Here is my dockerfile:
fragly asked me to take over, it was already very late for him.
please show me the code that opens the sqlite database
here is the code:
Solution
database.LoadAndMigrate("db/altera.db")
then mount the volume to /app/db
I'll give it a try
It cant create the file db file in the directory
if the file doesnt exist your code needs to create it, its an empty volume after all
In my github repo, there is an empty folder called db
so it should make it in there
maybe I need to add a
chmod -R 777 /db
to my dockerfileI'm talking about the database file itself
my code dos create it
when I run it locally at least. I think that its a linux permission issue, where the program doesnt have permission to create the file.
show me the updated code please
The code didn't change. The
LoadAndMigrate
function creates the file (or the gorm.Open
function inside that function does:
I had suggested code changes though
ohh ye I did these
my bad i just wasnt thinking
please show me the updated code
removed the prints, changed the volume mount location and string in LoadAndMigrate function to "db/altera.db" as you suggested
I removed the environment variable stuff since it wasn't really serving any use
I believe you said to change the string passed to
LoadAndMigrate
which is what I did and that removed the necessity to have the previous codeI'd have to do some testing myself
currently making dinner though
ok take ur time. Imma just mess around with stuff on my side and see if smth makes it work
got it to work. I misstyped smth in railways
š
what did you miss type
db
was dv
just wondering, is there a way to retrieve (or download) data from inside volumes (via ssh or smth)? or is that not supported?
that sure would do it
theres noting native, but there are these two templates
https://railway.app/template/guiCBv
https://railway.app/template/Nan7Bs