R
Railway11mo ago
Lewis981

Postgres Migration

I am using a Postgres DB and the migration was successful. I did not hardcode URLS and am simply configuring them through enviroment variables. Despite this fact, I get this message: The following service is still connected to this plugin through variables. Update these variables to avoid data loss. Please note if these services are still writing data after the migration, this data will be lost when you remove the legacy service. What do I need to update before deleting the old DB?
28 Replies
Percy
Percy11mo ago
Project ID: c69d7554-5299-4bf1-8e33-58cd68ebc682
Lewis981
Lewis981OP11mo ago
c69d7554-5299-4bf1-8e33-58cd68ebc682
Brody
Brody11mo ago
what environment variables are you using in code to connect to the db?
Lewis981
Lewis981OP11mo ago
I use dj_database_url to set up the variables automatically in Django. So my DB code is simply this: DATABASES = { 'default': dj_database_url.config(conn_max_age=500) }
Now that I'm thinking about it, maybe rebuilding will reset the variables?
Brody
Brody11mo ago
well slow down there what specific environment variable does that piece of code use
Lewis981
Lewis981OP11mo ago
This is from their source code: class DBConfig(TypedDict, total=False): ATOMIC_REQUESTS: bool AUTOCOMMIT: bool CONN_MAX_AGE: Optional[int] CONN_HEALTH_CHECKS: bool DISABLE_SERVER_SIDE_CURSORS: bool ENGINE: str HOST: str NAME: str OPTIONS: Optional[Dict[str, Any]] PASSWORD: str PORT: Union[str, int] TEST: Dict[str, Any] TIME_ZONE: str USER: str def config( env: str = DEFAULT_ENV, default: Optional[str] = None, engine: Optional[str] = None, conn_max_age: Optional[int] = 0, conn_health_checks: bool = False, ssl_require: bool = False, test_options: Optional[Dict] = None, ) -> DBConfig: From my understanding, it checks the enviroment variables and loads the into the config.
Brody
Brody11mo ago
but what environment variable(s)?
Lewis981
Lewis981OP11mo ago
DATABASE_URL
Brody
Brody11mo ago
where does it say that?
Lewis981
Lewis981OP11mo ago
Not sure I understand your question. In the documentation or in my code?
Lewis981
Lewis981OP11mo ago
I picked the tool up from a Mozilla tutorial a few years back: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Deployment#dj-database-url
MDN Web Docs
Django Tutorial Part 11: Deploying Django to production - Learn web...
That's the end of this tutorial on setting up Django apps in production, and also the series of tutorials on working with Django. We hope you've found them useful. You can check out a fully worked-through version of the source code on GitHub here.
Lewis981
Lewis981OP11mo ago
From the docs: Configure your database in settings.py from DATABASE_URL: import dj_database_url DATABASES = { 'default': dj_database_url.config( conn_max_age=600, conn_health_checks=True, ), } You can provide a default, used if the DATABASE_URL setting is not defined: DATABASES = { 'default': dj_database_url.config( default='postgres://...', conn_max_age=600, conn_health_checks=True, ) } It's simply getting the enviroment variable labeled DATABASE_URL, and connecting to that DB. Wouldn't migrating to the new DB have updated this reference? or is that on me?
Brody
Brody11mo ago
very ambiguous, but hey if it works for you what is your DATABASE_URL service variable set to?
Lewis981
Lewis981OP11mo ago
Yeah, it's one of those "Its so magic that you have no idea what it's doing" kinda things. May move away from it in the future. Checking now.
Lewis981
Lewis981OP11mo ago
It looks to be set to the old URL. Do I need to manually update all the variables?
Brody
Brody11mo ago
wdym all? you are only using DATABASE_URL in code? also, could you send me a screenshot of your railway project
Lewis981
Lewis981OP11mo ago
This is the new DB created after migration. Notice the duplicate variables (Not sure if that matters). Getting the other screenshots now.
No description
Lewis981
Lewis981OP11mo ago
And by "All" I mean the User, password, ect. In my project itself, not my code.
Brody
Brody11mo ago
id like a screenshot of the project, the browsers viewport, with no services open
Lewis981
Lewis981OP11mo ago
Here you are.
No description
Brody
Brody11mo ago
so do you think you should run another migration? since your app was still using the legacy db's url, your app would have wrote any new data to the old db
Lewis981
Lewis981OP11mo ago
I haven't added any data since the migration, so I wouldn't be losing anything.
Brody
Brody11mo ago
okay sounds good, then the DATABASE_URL service variable on your app should be ${{Postgres.DATABASE_URL}}
Lewis981
Lewis981OP11mo ago
Thanks a million, I'll try this now. Would I then delete the Legacy DB?
Brody
Brody11mo ago
as long as you are sure all the needed data is in the v2 database
Lewis981
Lewis981OP11mo ago
Thanks, I'll hold off until I confirm. That did address the error aswell. Much appreciated.
Brody
Brody11mo ago
Want results from more Discord servers?
Add your server