Repository navigation
fix: refresh the data source schema whenever its configuration changes - #546
FluffyDiscord wants to merge 1 commit into
Conversation
The port changes on every ddev restart. The URL was updated, but only a newly created data source was introspected, so an existing one stayed stale until a manual refresh.
|
It's unusual for DDEV to use a new port on every restart. You might want to fix the port conflict that is causing that (the link for that is reported every time you get this behavior). It wouldn't be wrong for PhpStorm to be able to track it of course. |
Thats exactly what happens, but it happens on all 4 of my machines (2x linux, windows, mac). With this, I am marking this as a bug, rather than misconfiguration. I am alsovnot sure I have ever gotten your mysterious warning with a link to help me with ports constantly changing. I have ddev running for several projects at the same time, on those machines. If thats an issue, ddev should by itself solve this by remembering previous ports or something - that's out of scope for this PR if it does not. |
|
Please see https://docs.ddev.com/en/stable/users/usage/troubleshooting/#web-server-ports-already-occupied Again, it's not wrong for the plugin here to solve the problem you describe. But it's annoying to you to have the problem in the first place. If you manually start a new project and show the output I can help you if it's not obvious. |
DDEV does pick a random DB host port with every restart, also as stated per the docs: https://docs.ddev.com/en/stable/users/usage/developer-tools/#using-development-tools-on-the-host-machine |
|
On this PR, I'm not sure that this should be a function of the plugin. Auto-refreshing the data source because the port changed is a very coincidental logic flow. The port change isn't what makes the schema stale: the database keeps its content across a restart, and tables created outside the IDE need a refresh either way. That DDEV picks a new port on every start is documented behaviour, but it has no logical connection to resyncing the schema. For changes made outside the IDE, the Refresh action in the Database tool window is the expected way. What I could see in the plugin is a refresh after actions that change the schema themselves, like a database import or a snapshot restore. |
|
Does not make the schema stale - true, but you are not talking about the root issue. The root issue is that ddev plugin does not automatically check for ddev changes and does not reflect the current state of ddev database. If you have other ideas how we can approach this issue, I am all open for ideas. I simply want ddev plugin to pick up port change, without me manually doing anything, because that defeats the purpose of having this addon. |
What it the root issue? The DB connection behaves like any other JetBrains connection, apart from the automatically updating connection string to keep the ddev connection.
It does automatically sync the port when it changes, both if the IDE is open during a ddev start or restart, or if it is opened after. As soon as a state change is detected, the connection string of the database connection is updated.
As noted above, as well as in your PR, the port changes are constantly reflected, keeping the connection valid with as small a latency as possible. They are immediately and automatically valid in the IDE, without any need to resync anything. Where does the schema sync come into play in this all? What is the workflow pain you're trying to solve? |
|
My issue is that this ddev plugin does not trigger inspection automatically, not connecting to the ddev database automatically, leaving stale schema in IDE and requiring me to manually connect and trigger the inspection in IDE. I don't know how else can I describe it? |
The Problem/Issue/Bug:
DDEV publishes the database on a new host port at every
ddev restart. The plugin updates the URL of the existing data source, but it only introspects a data source it has just created. An existing one keeps its old schema until you press Refresh in the Database tool window, so SQL inspections can reportUnable to resolve tablefor tables that exist.How this PR Solves the Problem:
DdevDataSourceManagerImplnow introspects after every data source update, not only for new ones. The up-to-date check at the top of the method is unchanged, so nothing runs while the configuration stays the same.Two behaviours to review:
DataSourceProviderImpl.updateDataSourcealready sets Auto sync to on at every update, so unticking it doesn't opt out of this refresh.Manual Testing Instructions:
ddev exec psql -c 'create table after_restart_check (id int)'.ddev restart.Tested so far:
DdevDataSourceManagerImplTestandAutoConfigureDataSourceListenerTestpass on the 2026.1 build. The two changed tests (changed configuration, legacy data source) time out without the fix.ddev restartruns on a Postgres 18 project:ddev describeshowed the new port only oncepg_isreadypassed, so the refresh shouldn't reach a database that is still starting.DataSourceProvider, so they prove introspection is triggered, not that the schema updates.Related Issue Link(s):
None.