Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch database upgrade #162

Open
effjot opened this issue Feb 23, 2024 · 4 comments
Open

Batch database upgrade #162

effjot opened this issue Feb 23, 2024 · 4 comments

Comments

@effjot
Copy link
Contributor

effjot commented Feb 23, 2024

Is there a possibility for run the database upgrade as a batch process for all databases? If I select “Execute as batch process”, I would have to select the database connections by hand, because there is no auto-fill select from list as with batch processes for layers.

@Gustry
Copy link
Member

Gustry commented Feb 23, 2024

If the GUI is not enough, then it can be possible with Python ?

Open your clock in Processing panel, and copy/paste the Python line. You can add a Python loop.

@effjot
Copy link
Contributor Author

effjot commented Feb 23, 2024

Thanks for your suggestion to take the Python processing.run() command from the processing log!

My main problem, however, was getting the list of all database connections configured in Qgis. With this list, I can write a small Python script or fill the fields in the batch processing GUI.

For the batch processiong interface, I wrote a “custom expression” Python function:

@qgsfunction(args='auto', group='Custom')
def postgresql_connections(feature, parent):
    md = QgsProviderRegistry.instance().providerMetadata('postgres')
    return list(md.connections())

Then I could call the expression in “Autofill → Add values by expression”.

This function (without the decorator) can also be used for the loop in the Python console that you suggested:

for db in postgresql_connections():
    print(db)
    processing.run("pg_metadata:upgrade_database_structure",
    {'CONNECTION_NAME': db,
    'RUN_MIGRATIONS': True})

@Gustry
Copy link
Member

Gustry commented Feb 23, 2024

Yes, I think is an helper in the plugin.
You can also use the PgMetadata Python API :

from pg_metadata.connection_manager import connections_list, 
connections, _ = connections_list()

# or check_pgmetadata_is_installed as well ?

I didn't try.

@effjot
Copy link
Contributor Author

effjot commented Feb 26, 2024

Ah yes, that should work, too, in a Python script. For the batch GUI I still need the decorated function.

But maybe a toolbox algorithm “Upgrade all [connected] databases” would be a nice addition.

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

No branches or pull requests

2 participants