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
Project ID:
c69d7554-5299-4bf1-8e33-58cd68ebc682
c69d7554-5299-4bf1-8e33-58cd68ebc682
what environment variables are you using in code to connect to the db?
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?
Now that I'm thinking about it, maybe rebuilding will reset the variables?
well slow down there
what specific environment variable does that piece of code use
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.
but what environment variable(s)?
DATABASE_URL
where does it say that?
Not sure I understand your question. In the documentation or in my code?
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.
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?
very ambiguous, but hey if it works for you
what is your DATABASE_URL service variable set to?
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.
It looks to be set to the old URL.
Do I need to manually update all the variables?
wdym all? you are only using
DATABASE_URL
in code?
also, could you send me a screenshot of your railway projectThis is the new DB created after migration. Notice the duplicate variables (Not sure if that matters). Getting the other screenshots now.
And by "All" I mean the User, password, ect.
In my project itself, not my code.
id like a screenshot of the project, the browsers viewport, with no services open
Here you are.
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
I haven't added any data since the migration, so I wouldn't be losing anything.
okay sounds good, then the
DATABASE_URL
service variable on your app should be ${{Postgres.DATABASE_URL}}
Thanks a million, I'll try this now. Would I then delete the Legacy DB?
as long as you are sure all the needed data is in the v2 database
Thanks, I'll hold off until I confirm. That did address the error aswell. Much appreciated.
read more on reference variables here https://docs.railway.app/guides/variables#reference-variables