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

Added --no-superuser flag #3204

Closed

Conversation

robbe-haesendonck
Copy link
Contributor

@robbe-haesendonck robbe-haesendonck commented Sep 19, 2023

Adding the --no-superuser flag to allow imports into already existing databases.
Fixes: #2719

@robbe-haesendonck robbe-haesendonck marked this pull request as ready for review September 21, 2023 14:26
@robbe-haesendonck
Copy link
Contributor Author

Normally I implemented everything as described in the linked ticket.
If I forgot anything please let me know!

Thanks in advance
~ Robbe

Copy link

@Xiretza Xiretza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! I've yet to try this out, but the main use case for me would be running the preparation using the postgres superuser, then running the import as the unprivileged nominatim user. AFAICT this isn't possible yet without changing the config file inbetween, ideally the preparation step would accept different postgresql connection settings on the commandline.

.github/workflows/ci-tests.yml Outdated Show resolved Hide resolved
nominatim/clicmd/setup.py Outdated Show resolved Hide resolved
@robbe-haesendonck
Copy link
Contributor Author

@Xiretza Thanks for taking a look! I'll implement the changes as soon as possible. Splitting it up into different commands altogether will break compatibility I presume, so I'll first look at renaming the flags hoping that will clear the logic up (which indeed the logic for is kinda messy at the moment).

Preparing database should work without osm-file
@lonvia
Copy link
Member

lonvia commented Sep 25, 2023

I find the options still confusing, especially as they now in competition with continue. I would prefer:

nominatim import --prepare-database
nominatim import --continue import-from-file --osm-file planet.pbf

The first command can be prefixed with NOMINATIM_DATABASE_DSN=whatever to modify the user if necessary.

This should make much of the logic easier.

.github/workflows/ci-tests.yml Outdated Show resolved Hide resolved
nominatim/tools/database_import.py Outdated Show resolved Hide resolved
@robbe-haesendonck
Copy link
Contributor Author

@lonvia I Implemented the options using continue, but I kept the legacy option also.
Do I remove the legacy import command altogether (as in the user needs to run the 2 commands)?

I wasn't sure so I opted to do it like this first.

Fixed small oversight in mutually exclusiveness of arguments
@robbe-haesendonck robbe-haesendonck marked this pull request as draft September 26, 2023 12:49
nominatim/clicmd/setup.py Outdated Show resolved Hide resolved
nominatim/clicmd/setup.py Outdated Show resolved Hide resolved
nominatim/db/connection.py Outdated Show resolved Hide resolved
@lonvia
Copy link
Member

lonvia commented Sep 26, 2023

Do I remove the legacy import command altogether (as in the user needs to run the 2 commands)?

No. The logic right now is what I had in mind. Makes it a reasonably simple change.

Regarding github actions, I think you are almost there. Simply work from a copy of the install action of these lines: https://github.com/osm-search/Nominatim/blob/master/.github/workflows/ci-tests.yml#L222-L291 instead of modifying the existing one. Once you add the code lines you already have, that should already be it. Maybe at the call to check-database for paranoia. Also, it is enough to run this in Ubuntu-22. You can delete Ubuntu-20 from the matrix names.

@robbe-haesendonck robbe-haesendonck marked this pull request as ready for review September 27, 2023 07:37
Added nominatim_database_webuser (www-data).
Set non-superuser password for importing
@robbe-haesendonck
Copy link
Contributor Author

@lonvia So, the CI tests are failing. I fixed the create import user (-P option doesn't accept a string which was a wrong assumption on my end).

However there are also some fails on the linting, but I simply do not know how to reduce the branching any further. Do I disable that test? Could also probably create a function which does some of the sanity checks (first three if statements).

@lonvia
Copy link
Member

lonvia commented Sep 27, 2023

However there are also some fails on the linting, but I simply do not know how to reduce the branching any further. Do I disable that test?

Yes, for this particular case you can simply add another exception in line 74 for the 'too-many-branches' check. That entire function will need some refactoring eventually but that is something for a different PR.

@robbe-haesendonck
Copy link
Contributor Author

I looked at the errors in the CI log, the failing postgres login is probably because it doesn't have a password set yet, which can be fixed easily.
The other issue is with the static type checker, but AFAIK I did not touch that part at all. I guess it should work when I change line 110 in database_import.py to make the 2 signatures match.

I've tested a non-superuser import on Nomad, and everything seems to work just fine. So I assume changing the signature could be ok?

I'll take a more in-depth look tomorrow, today I was preoccupied with some other work.

nominatim/clicmd/setup.py Outdated Show resolved Hide resolved
nominatim/clicmd/setup.py Show resolved Hide resolved
@robbe-haesendonck
Copy link
Contributor Author

@lonvia My apologies for the really slow implementation of the change requests.

@robbe-haesendonck
Copy link
Contributor Author

Static type checking seems to pass, only thing left is getting the import user correct in the CI tests.

@lonvia
Copy link
Member

lonvia commented Nov 24, 2023

Almost good to go. Could I kindly ask you to rebase your code on master and force push to the branch? If you prefer to squash your commits, you are welcome to do so as well.

@lonvia
Copy link
Member

lonvia commented Dec 7, 2023

The failing check should be fixed on master. I've manually merged this now doing a rebase. Thank you for your work and for patiently addressing all comments.

It would be good to have some documentation for this new feature in https://nominatim.org/release-docs/latest/admin/Advanced-Installations/. If you like doing a follow-up commit, it would mean adding a section in https://github.com/osm-search/Nominatim/blob/master/docs/admin/Advanced-Installations.md

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.

Allow creating postgresql database ahead of time
3 participants