-
Notifications
You must be signed in to change notification settings - Fork 36
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
create a new user after creating a fresh db #672
Conversation
Signed-off-by: Ahmad <ahmedwahid16101@gmail.com>
This looks good! However, it got me thinking that a) I believe I was partly wrong and an existing user will survive a db drop and b) we have never (also not in documentation/host/data.rst ) told developers who should own the database. If it's okay for the database to be owned by the postgres user and that every user on the server can connect to the databse, then leaving away the user is fine. I am sorry I didn't know this exactly earlier. I would:
Another thought : |
I have already used Is it a good idea, if we provide a user then only this user will have access to the new DB? see this https://medium.com/@mohammedhammoud/postgresql-create-user-create-database-grant-privileges-access-aabb2507c0aa |
Yes, please.
That looks good. What is the difference to making that user the owner of the new database in the createdb call? |
well, we create databases by using the default |
Signed-off-by: Ahmad <ahmedwahid16101@gmail.com>
I haven't actually said this anywhere in this PR, true. My idea is to make the user the owner of the database like described here:
But just adding privileges for this new user is fine as well. Maybe we can not do all, but keep it to the ones needed for using it (e.g. read, update, enter, delete ...), but not the privilege to drop the database. |
After creating DB and the user, I would take these steps.
Let me know, if something is missing. @nhoening |
Makes sense. |
I thought, user can |
Signed-off-by: Ahmad <ahmedwahid16101@gmail.com>
@nhoening Please review these new changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, after I tested a bit I have some more ideas to make this work well.
Signed-off-by: Ahmad <ahmedwahid16101@gmail.com>
Signed-off-by: Ahmad <ahmedwahid16101@gmail.com>
Right now, the extensions are created by the default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great step forward.
I tried it out and ran into a small issue that should be easy to fix.
I don't think that matters. |
Signed-off-by: Ahmad <ahmedwahid16101@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks really good, but I ran into a small problem. The database was dropped, but not created. Only when I ran the script once more. See trace below, but I already indicated the potential cause in the code.
(fm-3.10) nicolas at pop-os in ~/workspace/seita/flexmeasures on docs-tutorial-improvement (2 untracked)
± make clean-db db_name=flexmeasures_test db_user=flexmeasures_test
./flexmeasures/data/scripts/clean_database.sh flexmeasures_test flexmeasures_test
[sudo] password for nicolas:
flexmeasures_test database exists
Make a backup first? [y/N]
This will drop your database and re-create a clean one. Continue?[y/N] y
Dropping database ...
flexmeasures_test database is dropped
(fm-3.10) nicolas at pop-os in ~/workspace/seita/flexmeasures on docs-tutorial-improvement (2 untracked)
± make clean-db db_name=flexmeasures_test db_user=flexmeasures_test
./flexmeasures/data/scripts/clean_database.sh flexmeasures_test flexmeasures_test
flexmeasures_test database does not exist
Creating a new database ...
flexmeasures_test database is created
User flexmeasures_test is already available.
Connect flexmeasures_test to flexmeasures_test
GRANT
Grant required privileges
GRANT
Creating cube extension in flexmeasures_test ...
You are now connected to database "flexmeasures_test" as user "postgres".
CREATE EXTENSION
Creating earthdistance extension in flexmeasures_test ...
You are now connected to database "flexmeasures_test" as user "postgres".
CREATE EXTENSION
Updating database structure ...
Signed-off-by: Ahmad <ahmedwahid16101@gmail.com>
Signed-off-by: Ahmad <ahmedwahid16101@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
I think this is a good example for bash scripting, which we can look at if we write more of them - very structured :)
…676) * docs: improve developer tutorial on how to run tests, incl. coverage * add a docker command for running a database to test against * exclude jinja templates from coverage, see nedbat/coveragepy#1553 * use the new make command from PR #672 * correct syntax type for docker call * add dollar signs * small text improvements
Changes proposed
make clean-db db_name=flexmeasures-db db_user=flexmeasures
.db_name
is required, whiledb_user
is optional.db_user
is provided then after creating this user will be connected to thedb
for granting basic privileges.