-
Notifications
You must be signed in to change notification settings - Fork 23
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
Use a unique set of definitions to initialize the database #834
Conversation
Nice work, this looks promising. I do have a few comments. I think you should use the connection settings provided in the configuration as much as possible, the database can be on a different host or port, this should be handled. Also I think the user creation should be optional. Maybe only use the superuser to create the local user and grant privileges if required, but then use the new user to create the tables; this can even be done using the database handler in perl. What do you think? |
@blacksponge good remarks. I tried to only do some refactoring and keep the old behavior as much as possible. If we agree on this PR, I see few updates here and there (as well as your remarks). |
Is it really easier to maintain one script that should handle all database engines instead three different script? For the user it will be the same. |
share/create_db.pl
Outdated
print "\n"; | ||
print "Automatically initialize the Zonemaster database based on the Zonemaster Backend config\n"; | ||
print "file. Use the values to create the database and a user with enough privileges to\n"; | ||
print "access this database. Also create all the Zonemaster tables inside this database.\n"; |
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.
For FreeBSD this depends on #835 to find the configuration file.
To be consistent: "Zonemaster Backend" --> "Zonemaster-Backend" or "Zonemaster::Backend".
Maybe not. TBH I am still not completely satisfied with this PR. I need to think about it a little more. |
I took a 180 degrees shift. I choose to remove the I also updated the installation process with notes to update the "backend_config.ini" file based on the database name chosen, and its user/password. The new installation procedure needs to be tested on FreeBSD. The way I see it in the near future is to remove the call to |
Tested with postgres 12 and mariadb 10, it is working well. I think it is cleaner this way. |
I realized that the |
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.
I do not see the gain of this change. For the user (installation instructions) it will require more steps to create the database, especially for MariaDB/MySQL, but also for PostgreSQL and SQLite. We should try to make the installation step easy.
I agree on this. And I think this might help go that way even if this PR adds more steps to the installation process. When you install the Backend, you only need to create a database and a user (for MySQL and PostgreSQL). You also need to set these values into the This PR is about splitting the process in two. One part creates the database and the user (if applicable). The other part is about creating the tables. Currently everything has to be made by hand during installation, but a future work I am planning is to let the Backend automatically create the tables on startup (if they don't exist). This would then remove the "Database configuration" section for each engine. * Finally I think that having the commands to create the database (and user if applicable) inside the installation instruction makes it easier for a user to tweak the installation process to its needs (for instance use a different database name, user, password, or even the database's host or port). * I didn't add the tables' creation by the Backend to this PR to avoid overloading this PR |
If the second step can be done before the next release I am fine with this PR, but if we risk having such complex installation instructions at next release I am not fine with it.
That is a good ambition. |
This second step is done in #846 |
if #846 is the end result, then the end result gives a installation instruction that is too complex. I cannot see why it should be more complex than today. Command line commands (shell) is simpler than having to give SQL commands directly to the server or editing the configuration file. |
Yes #846 is the end result. |
I really like that you put the database definitions in the adapter modules! I agree with @matsduf that it's nicer to have only shell commands in the installation instruction, rather than jumping in and out of special purpose shells (e.g. mysql). I can see four ways forward:
The fourth option has the advantage that it automatically coordinates the database name, user name and password between the SQL statements and the configuration file. |
Oh, I think I now understand what was meant by "too complex", thanks for the light. The thing with the 4th option is that you cannot reuse the About the 3rd option, this will be slightly harder to tweak the parameters to someone needs. So I'll go with option 2 to address your remarks. |
I realized that this might leak the password.
Should I make such update in the installation document? |
Move database and user creations to the installation documentation instead of within the initial-postgres.sql file.
* Remove each script per database engine * Update MANIFEST
* Database initialization is now performed via create_db.pl * Update MANIFEST
* Call to create_db script for each database * Refactor SQLite initialization
I've rebased the branch on top of develop and fixed the conflicts within the Installation file. |
Create a new section to document database configuration once per OS.
@blacksponge, @mattias-p, @matsduf could you re-review? |
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.
Nice work! Just a small comment
@@ -95,6 +95,92 @@ sub dbh { | |||
return $self->dbhandle; | |||
} | |||
|
|||
sub create_db { |
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.
Maybe include the create_db
method in the requires
of DB.pm ?
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.
done
```sh | ||
cd `perl -MFile::ShareDir -le 'print File::ShareDir::dist_dir("Zonemaster-Backend")'` | ||
su -m zonemaster -c "perl create_db.pl" | ||
``` |
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.
Suggestion to make it easier to just copy and paste:
- Make
create_db.pl
executable - Make the command a one-liner:
su -m zonemaster -c "$(perl -MFile::ShareDir -le 'print File::ShareDir::dist_dir("Zonemaster-Backend")')/create_db.pl"
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.
done
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.
I'm sorry, for FreeBSD it was a bad suggestion from me. Default shell for FreeBSD root is C shell (or tcsh), and that does not support "$( )". Bourne shell (or sh) is the default shell for other users, and that supports "$( )". Back ticks have to be used, and that affects <"> too.
su -m zonemaster -c "`perl -MFile::ShareDir -le 'print File::ShareDir::dist_dir(qw(Zonemaster-Backend))'`/create_db.pl"
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.
This should be fixed (and I realized that I forgot to remove the call to perl since the script is now executable).
```sh | ||
cd `perl -MFile::ShareDir -le 'print File::ShareDir::dist_dir("Zonemaster-Backend")'` | ||
su -m zonemaster -c "perl create_db.pl" | ||
``` |
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.
I'm sorry, for FreeBSD it was a bad suggestion from me. Default shell for FreeBSD root is C shell (or tcsh), and that does not support "$( )". Bourne shell (or sh) is the default shell for other users, and that supports "$( )". Back ticks have to be used, and that affects <"> too.
su -m zonemaster -c "`perl -MFile::ShareDir -le 'print File::ShareDir::dist_dir(qw(Zonemaster-Backend))'`/create_db.pl"
Purpose
This PR is about removing duplicate in database initialization as expressed in #689.
Context
Fixes #689.
Partially addresses #805
Changes
Database and user creations are done manually on Backend installation (as documented in the installation document)
Creates a new script
share/create_db.pl
that can be used to create the tables for any database engine.Removes files
share/initial-mysql.sql
,share/initial-postgres.sql
,script/create_db_mysql.pl
,script/create_db_postgresql_9.3.pl
andshare/create_db_sqlite.pl
. The SQL commands are now part of acreate_db()
routine in the MySQL.pm and PostgreSQL.pm files respectively.Do not drop the tables before creating them anymore.
I left the whole commit history. Some commits were only needed to make the code easier to refactor later in the PR.
How to test this PR
Follow the installation instructions (develop) and make sure you have a running Backend.