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
thomasmolOP13mo 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
thomasmolOP13mo 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
thomasmolOP13mo ago
uhm its a directus cms database, so i don't actually know the details of the structure
Brody
Brody13mo ago
thomasmol
thomasmolOP13mo ago
i just used that one
Brody
Brody13mo ago
you sure, the one i previously linked is different
thomasmol
thomasmolOP13mo 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
thomasmolOP13mo 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
jr13mo ago
Can you please share your project id @thomasmol
thomasmol
thomasmolOP13mo 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
Brody13mo ago
you created your new database in a different project?
thomasmol
thomasmolOP13mo 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
Brody13mo ago
where you using the TimescaleDB extension?
thomasmol
thomasmolOP13mo ago
tbh not that i know off i am wondering why it was installed in the first place haha
Brody
Brody13mo ago
the legacy plugins had the timescale extension installed by default does the service (directus?) use timescale?
thomasmol
thomasmolOP13mo ago
ah okay. just googled, directus does not use timescale so should be fine then
Brody
Brody13mo 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
thomasmolOP13mo ago
can i enable that after the db is already deployed?
Brody
Brody13mo ago
no since its not installed by default like it used to be
thomasmol
thomasmolOP13mo ago
can't seem to deploy that template in my project
Brody
Brody13mo ago
please explain why
thomasmol
thomasmolOP13mo ago
the "save config" button and "deploy" button are disabled
Brody
Brody13mo ago
leave beta from the account page the new ghost template ui seems to be a bit broken right now
thomasmol
thomasmolOP13mo ago
ah okay, got it working now all thanks for the help
Brody
Brody13mo ago
you got directus switched over to using a new database? are you using the private network to communicate with the database?
thomasmol
thomasmolOP13mo ago
yes i switched the directus db and another one as well i am not using the private network currently
Brody
Brody13mo ago
you'd want to use the private network, otherwise you will incur egress fees on the database
thomasmol
thomasmolOP13mo ago
okay, so i just use the database_private_url then?
Brody
Brody13mo ago
should do the job yeah
thomasmol
thomasmolOP13mo 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
Brody13mo ago
what is the type of app that's not working with it?
thomasmol
thomasmolOP13mo ago
sveltekit + prisma, running on nodejs the non private db url works fine though
Brody
Brody13mo ago
built with nixpacks?
thomasmol
thomasmolOP13mo ago
yes
Brody
Brody13mo ago
at what point in the apps lifecycle do you connect to the database?
thomasmol
thomasmolOP13mo ago
it fails building, so it tries to connect at build time
Brody
Brody13mo ago
ah, the private network is not available during build
thomasmol
thomasmolOP13mo ago
okay interesting
Brody
Brody13mo 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
thomasmolOP13mo ago
i think this is prisma trying to connect so i am not sure if i have control over this
Brody
Brody13mo ago
you have more control than you think I assume your build script runs prisma migrations?
thomasmol
thomasmolOP13mo ago
yes it does
Brody
Brody13mo ago
so just don't run the migrations during build run them before your app starts instead
thomasmol
thomasmolOP13mo 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
Brody13mo ago
haha yeah that's exactly what I said to do 🙂 but happy everything is working now!
jr
jr13mo 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