Page MenuHomeDevCentral

Allow to create MySQL database

Authored by dereckson on Apr 3 2018, 02:34.



How can we create a database for a new phpBB instance?

The wrapper script runs on the Docker Engine host
and can interact with the SQLite database there,
but not with the MySQL server, as it's in a container.

The wrapper script will so run a container with this
mainteannce script to create the database.

The wrapper part is implemented at D1524.

Test Plan

saas-phpbb sites:createdb foo

Diff Detail

rSAASPHPBB saas-phpbb helper command
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

dereckson requested review of this revision.Apr 3 2018, 02:34
dereckson created this revision.
dereckson retitled this revision from WIP: create MySQL database to Allow to create MySQL database.Apr 3 2018, 21:04
dereckson edited the summary of this revision. (Show Details)
dereckson edited the test plan for this revision. (Show Details)
dereckson updated this revision to Diff 4016.Apr 3 2018, 21:33

Clean, refactor

dereckson updated this revision to Diff 4017.Apr 3 2018, 22:33

Ensure identifiant is valid. Use PDO in exception mode. Database aren't a named parameter to quote.

dereckson updated this revision to Diff 4020.Apr 3 2018, 22:58

Validate identifiants in Site

dereckson updated this revision to Diff 4021.Apr 3 2018, 22:59

+Unit test

dereckson accepted this revision.Apr 4 2018, 00:03

1. Prepare a directory with the code to test

$ cd  /home/dereckson/dev/docker/phpbb
$ git clone ssh://vcs@devcentral.docker.ulubis/source/saas-phpbb.git
$ cd saas-phpbb
$ arc shell
$ arc patch D1573

2. Run a MySQL container

Same procedure and container than acquisitariat, but called phpbb_db, and without a volume mount.

3. Run a php-cli container

$ mkdir /tmp/data-saas-phpbb
$ docker run -it --rm --link phpbb_db:db -e SAAS_SITES_DB=/data/sites.db -v /tmp/data-saas-phpbb:/data -v /home/dereckson/dev/docker/phpbb/saas-phpbb:/app nasqueron/php-cli bash
$ make
$ saas-phpbb sites:bootstrap

4. Add test data in sites.db

$ sqlite /tmp/data-saas-phpbb/sites.db
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .schema
  id text,
  host text,
  db_user text,
  db_password text,
  db_prefix text,
  active boolean
sqlite> INSERT INTO sites VALUES ('acme', 'phpbb.acme.tld', 'acme', 'somepass', 'phpbb_', 1);

5. Go back to our php-cli container to test this change

$ php bin/saas-phpbb.php sites:createdb acme

6. Fire a MySQL client to check we can connect to the created database with the created account

$ docker run -it --link phpbb_db:mysql --rm nasqueron/mysql bash
$ mysql -hmysql -uacme -p acme
Enter password: somepass
Welcome to the MySQL monitor.  Commands end with ; or \g.

This revision is now accepted and ready to land.Apr 4 2018, 00:03
This revision was automatically updated to reflect the committed changes.