Skip to content

fix: refresh the data source schema whenever its configuration changes - #546

Open
FluffyDiscord wants to merge 1 commit into
ddev:mainfrom
FluffyDiscord:refresh-data-source-on-change
Open

FluffyDiscord wants to merge 1 commit into
ddev:mainfrom
FluffyDiscord:refresh-data-source-on-change

Conversation

@FluffyDiscord

Copy link
Copy Markdown

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 report Unable to resolve table for tables that exist.

How this PR Solves the Problem:

DdevDataSourceManagerImpl now 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.updateDataSource already sets Auto sync to on at every update, so unticking it doesn't opt out of this refresh.
  • A data source that reads many databases takes longer. I measured about 39 s for 35 databases when refreshing by hand; it runs in the background.

Manual Testing Instructions:

  1. Open a DDEV project with its data source already introspected.
  2. Run ddev exec psql -c 'create table after_restart_check (id int)'.
  3. Run ddev restart.
  4. Within about 10 s of the restart (the status poll interval), the table appears in the Database tool window without pressing Refresh.

Tested so far:

  • DdevDataSourceManagerImplTest and AutoConfigureDataSourceListenerTest pass on the 2026.1 build. The two changed tests (changed configuration, legacy data source) time out without the fix.
  • Three ddev restart runs on a Postgres 18 project: ddev describe showed the new port only once pg_isready passed, so the refresh shouldn't reach a database that is still starting.
  • Not yet run through the steps above in a real IDE. The tests mock DataSourceProvider, so they prove introspection is triggered, not that the schema updates.

Related Issue Link(s):

None.

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.
@rfay

rfay commented Nov 9, 2026

Copy link
Copy Markdown
Member

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.

@FluffyDiscord

Copy link
Copy Markdown
Author

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.

@rfay

rfay commented Nov 9, 2026

Copy link
Copy Markdown
Member

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.

@AkibaAT AkibaAT self-assigned this Nov 9, 2026
@AkibaAT

AkibaAT commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

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.

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

@AkibaAT

AkibaAT commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

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.

@FluffyDiscord

FluffyDiscord commented Nov 9, 2026 •

Copy link
Copy Markdown
Author

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.

@AkibaAT

AkibaAT commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Does not make the schema stale - true, but you are not talking about the root issue.

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.

The root issue is that ddev plugin does not automatically check for ddev changes and does not reflect the current state of ddev database.

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.

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.

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?

@FluffyDiscord

Copy link
Copy Markdown
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants