Pomm2 feature hightlight: the CLI

Posted 4 years ago.

Yes, there is a Command Line Interface with the coming Pomm2. Installing it is a matter of seconds. Just add the following composer.json file in an empty directory:

{
    "minimum-stability": "dev",
        "require": {
            "pomm-project/cli": "dev-master"
        }
}

and launch the well known composer.phar install. Once done, the CLI expects to find a Pomm instance pre-loaded with database configuration in .pomm_cli_bootstrap.php. Here is a sample code you might configure to add correct configuration and credentials:

<?php // .pomm_cli_bootstrap.php

$loader = require __DIR__.'/vendor/autoload.php';

return new \PommProject\Foundation\Pomm(
    [
        'my_db' =>
        [
            'dsn' => 'pgsql://user:pass@host:port/db_name'
        ]
    ]
);

This way, the autoloader is triggered and the database configuration is set. It is now time to play with Pomm's CLI tool.

This tool makes developers able to quickly inspect the database structure (schemas, tables, fields):

$ php vendor/bin/pomm.php inspect:database my_db
Found 5 schemas in database.
+-----------+--------+-----------+------------------------+
| name      | oid    | relations | comment                |
+-----------+--------+-----------+------------------------+
| elcaro    | 123773 | 2         | ElCaro tutorial schema |
| phparchi  | 82738  | 1         |                        |
| pika      | 116120 | 1         |                        |
| public    | 2200   | 9         | standard public schema |
| templates | 116119 | 1         |                        |
+-----------+--------+-----------+------------------------+

Of course the goal is not to replace the brilliant Postgresql command line utility but to give developers a convenient tool to quickly inspect database objects. An important place has been made to database comments. Designing a database often requires concentration from several brains. It is important to be able to quickly find notes about every design choice later. Showing database comments is a nice way to impregnate developers with the database structure so they know each detail by earth the time of the project.

$ php vendor/bin/pomm.php inspect:schema my_db elcaro
Found 2 relations in schema 'elcaro'.
+------------+-------+--------+-------------------------------------------------------------------------+
| name       | type  | oid    | comment                                                                 |
+------------+-------+--------+-------------------------------------------------------------------------+
| department | table | 123776 | Department is a recursive structure. A department may belong to another |
|            |       |        | department. Employees belong to a tree of departments.                  |
| employee   | table | 123792 | Employee main structure. Each employee must belong to a department.     |
+------------+-------+--------+-------------------------------------------------------------------------+

The CLI tool can also generate model classes for Pomm's model manager. A more in depth article about this part will be published soon.