How to convert database plugin to volume with database?

I saw plugins are being sunsetted, is there a way to easily convert a plugin database ( i have a pq database) to a volume with db?
51 Replies
Percy
Percy13mo ago
Project ID: N/A
thomasmol
thomasmol13mo ago
N/A
Brody
Brody13mo ago
- deploy a new postgres database (it will automatically deploy the new database with a volume) - use this tool that jr wrote to copy the data from the old plugin to the new service https://railway.app/template/postgres-plugin-migration - swap the variable references from the old plugin to the new database - redeploy your service - profit
thomasmol
thomasmol13mo ago
very cool, thanks! I am getting an error: ==== Dumping database from PLUGIN_URL ==== pg_dump: warning: there are circular foreign-key constraints on this table: pg_dump: detail: hypertable pg_dump: hint: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints. pg_dump: hint: Consider using a full dump instead of a --data-only dump to avoid this problem. pg_dump: warning: there are circular foreign-key constraints on this table: pg_dump: detail: chunk pg_dump: hint: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints. pg_dump: hint: Consider using a full dump instead of a --data-only dump to avoid this problem. and here the actual error:
==== Restoring database to NEW_URL ====

ERROR: relation "_timescaledb_catalog.metadata" does not exist

LINE 1: DELETE FROM _timescaledb_catalog.metadata WHERE key = 'expor...

^

An error occurred. Exiting...

ERROR: relation "_timescaledb_catalog.metadata" does not exist

LINE 1: DELETE FROM _timescaledb_catalog.metadata WHERE key = 'expor...
==== Restoring database to NEW_URL ====

ERROR: relation "_timescaledb_catalog.metadata" does not exist

LINE 1: DELETE FROM _timescaledb_catalog.metadata WHERE key = 'expor...

^

An error occurred. Exiting...

ERROR: relation "_timescaledb_catalog.metadata" does not exist

LINE 1: DELETE FROM _timescaledb_catalog.metadata WHERE key = 'expor...
Brody
Brody13mo ago
did you use timescale on your old database?
thomasmol
thomasmol13mo ago
uhm its a directus cms database, so i don't actually know the details of the structure
Brody
Brody13mo ago
thomasmol
thomasmol13mo ago
i just used that one
Brody
Brody13mo ago
you sure, the one i previously linked is different
thomasmol
thomasmol13mo ago
i am sure, i just did it a minute ago. searched for "postgres plugin migration" when i added a new service in my project
Brody
Brody13mo ago
okay then i will directly report this to jr on monday
thomasmol
thomasmol13mo ago
alright thanks! FWIW i get the same error on a different project with a db that is not a directus cms db. The redis migration script did work though
Brody
Brody13mo ago
jr would agree with me when I say this, this is very helpful information
jr
jr12mo ago
Can you please share your project id @thomasmol
thomasmol
thomasmol12mo ago
2ffb0267-37fb-4000-8d1e-e59b97ed85a8 thats for the project with a directus cms db f9724669-2787-46a8-bfcd-3dd6e9944ba6 and this one is with a generic postgres db
Brody
Brody12mo ago
you created your new database in a different project?
thomasmol
thomasmol12mo ago
No i meant i tried the migration script in two different projects Okay i saw the script was updated so tried again, seems to work! but i do get these warnings:
[ WARN ] TimescaleDB extension not found in target database. Ignoring TimescaleDB specific commands.

[ WARN ] If you are using TimescaleDB, please install the extension in the target database and run the migration again.
[ WARN ] TimescaleDB extension not found in target database. Ignoring TimescaleDB specific commands.

[ WARN ] If you are using TimescaleDB, please install the extension in the target database and run the migration again.
can i ignore these?
Brody
Brody12mo ago
where you using the TimescaleDB extension?
thomasmol
thomasmol12mo ago
tbh not that i know off i am wondering why it was installed in the first place haha
Brody
Brody12mo ago
the legacy plugins had the timescale extension installed by default does the service (directus?) use timescale?
thomasmol
thomasmol12mo ago
ah okay. just googled, directus does not use timescale so should be fine then
Brody
Brody12mo ago
but they do need postgis as ive just realized, the new database you migrate to must be postgis https://railway.app/template/postgis
thomasmol
thomasmol12mo ago
can i enable that after the db is already deployed?
Brody
Brody12mo ago
no since its not installed by default like it used to be
thomasmol
thomasmol12mo ago
can't seem to deploy that template in my project
Brody
Brody12mo ago
please explain why
thomasmol
thomasmol12mo ago
the "save config" button and "deploy" button are disabled
Brody
Brody12mo ago
leave beta from the account page the new ghost template ui seems to be a bit broken right now
thomasmol
thomasmol12mo ago
ah okay, got it working now all thanks for the help
Brody
Brody12mo ago
you got directus switched over to using a new database? are you using the private network to communicate with the database?
thomasmol
thomasmol12mo ago
yes i switched the directus db and another one as well i am not using the private network currently
Brody
Brody12mo ago
you'd want to use the private network, otherwise you will incur egress fees on the database
thomasmol
thomasmol12mo ago
okay, so i just use the database_private_url then?
Brody
Brody12mo ago
should do the job yeah
thomasmol
thomasmol12mo ago
Mmm it works fine for the directus db but for my other one it does not, i get an P1001 error "can't reach database server"
Datasource "db": PostgreSQL database "railway", schema "public" at "timescale-postgis.railway.internal:5432"

Error: P1001: Can't reach database server at `timescale-postgis.railway.internal`:`5432`

Please make sure your database server is running at `timescale-postgis.railway.internal`:`5432`.
Datasource "db": PostgreSQL database "railway", schema "public" at "timescale-postgis.railway.internal:5432"

Error: P1001: Can't reach database server at `timescale-postgis.railway.internal`:`5432`

Please make sure your database server is running at `timescale-postgis.railway.internal`:`5432`.
Brody
Brody12mo ago
what is the type of app that's not working with it?
thomasmol
thomasmol12mo ago
sveltekit + prisma, running on nodejs the non private db url works fine though
Brody
Brody12mo ago
built with nixpacks?
thomasmol
thomasmol12mo ago
yes
Brody
Brody12mo ago
at what point in the apps lifecycle do you connect to the database?
thomasmol
thomasmol12mo ago
it fails building, so it tries to connect at build time
Brody
Brody12mo ago
ah, the private network is not available during build
thomasmol
thomasmol12mo ago
okay interesting
Brody
Brody12mo ago
you could run whatever it is before your app starts at runtime, but if you do that make sure you use a healthcheck so railway knows when your app has actually started
thomasmol
thomasmol12mo ago
i think this is prisma trying to connect so i am not sure if i have control over this
Brody
Brody12mo ago
you have more control than you think I assume your build script runs prisma migrations?
thomasmol
thomasmol12mo ago
yes it does
Brody
Brody12mo ago
so just don't run the migrations during build run them before your app starts instead
thomasmol
thomasmol12mo ago
right, and then i use the health check in railway to notify when its done wait could i just move the migration command to the start script?
"build": "vite build && prisma generate && prisma migrate deploy",
"preview": "vite preview",
"start": "node -r dotenv/config build",
"build": "vite build && prisma generate && prisma migrate deploy",
"preview": "vite preview",
"start": "node -r dotenv/config build",
is what i have now fwiw, this worked so i got it running now with the private db url also, the reason i wanted to migrate is because of the new deployment region select, as most of my users are in europe. So now i migrated all services to EU, and load times are now super fast 👍
Brody
Brody12mo ago
haha yeah that's exactly what I said to do 🙂 but happy everything is working now!
jr
jr12mo ago
Glad it is working! You can safely ignored the timescale message if you are not using it. Most projects will not being using Timescale
Want results from more Discord servers?
Add your server