Skip to content

Commit

Permalink
Convert to a Symfony application. (#45)
Browse files Browse the repository at this point in the history
* Add symfony/console

* Pin version of mysql used in test database.

* Convert diff into a Symfony console command

* Convert dump into a Symfony console command

* Fix return type annotation

* Convert extract into a Symfony console command

* Convert lint into a Symfony console command

* Add console application

* Remove old morphism scripts

* Remove custom command line parsing code

* Create directories with less permissive permissions
  • Loading branch information
biggianteye authored Jun 10, 2018
1 parent 42a542f commit 6d81cd4
Show file tree
Hide file tree
Showing 20 changed files with 568 additions and 530 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ $ composer require graze/morphism

All commands support the `--help` parameter which give more information on usage.

* **morphism-extract**: Extract schema definitions from a mysqldump file.
* **morphism-dump**: Dump database schema for a named database connection.
* **morphism-lint**: Check database schema files for correctness.
* **morphism-diff**: Show necessary DDL statements to make a given database match the schema files. Optionally apply the changes too.
* **morphism extract**: Extract schema definitions from a mysqldump file.
* **morphism dump**: Dump database schema for a named database connection.
* **morphism lint**: Check database schema files for correctness.
* **morphism diff**: Show necessary DDL statements to make a given database match the schema files. Optionally apply the changes too.

## Config File

Expand All @@ -66,7 +66,7 @@ databases:
unix_socket: '/var/lib/mysql/catalog.sock'
# morphism specific options
morphism:
# morphism-diff only operates on connections with 'enable: true'
# morphism diff only operates on connections with 'enable: true'
enable: true
# Path where schema files live.
# Defaults to "schema/<connection-name>"
Expand All @@ -89,30 +89,30 @@ databases:

## Example Usage

This example uses `morphism-dump` to generate schema files from a database, `morphism-lint` for checking the files and `morphism-diff` to apply changes both interactively and automatically.
This example uses `morphism dump` to generate schema files from a database, `morphism lint` for checking the files and `morphism diff` to apply changes both interactively and automatically.

```
(master) $ # create a baseline for the schema
(master) $ mkdir schema
(master) $ bin/morphism-dump --write config.yml catalog
(master) $ bin/morphism dump --write config.yml catalog
(master) $ git add schema/catalog
(master) $ git commit -m "initial checkin of catalog schema"
(master) $
(master) $ # start work on changes to the catalog...
(master) $ git checkout -b catalog-fixes
(catalog-fixes) $ vi schema/catalog/product.sql # edit table definition
(catalog-fixes) $ vi schema/catalog/product_dimensions.sql # add new table
(catalog-fixes) $ bin/morphism-lint schema/catalog # check syntax
(catalog-fixes) $ bin/morphism lint schema/catalog # check syntax
ERROR schema/catalog/product_dimensions.sql, line 2: unknown datatype 'intt'
1: CREATE TABLE product_dimensions (
2: `pd_id` intt<<HERE>>(10) unsigned NOT NULL AUTO_INCREMENT,
(catalog-fixes) $ vi schema/catalog/product_dimensions.sql # fix table definition
(catalog-fixes) $ bin/morphism-lint schema/catalog # check syntax
(catalog-fixes) $ bin/morphism lint schema/catalog # check syntax
(catalog-fixes) $ git add schema/catalog
(catalog-fixes) $ git rm schema/catalog/discontinued.sql # delete a table
(catalog-fixes) $ git commit -m "various changes to catalog schema"
(catalog-fixes) $ # alter the database to match the schema files
(catalog-fixes) $ bin/morphism-diff --apply-changes=confirm config.yml catalog
(catalog-fixes) $ bin/morphism diff --apply-changes=confirm config.yml catalog
-- --------------------------------
-- Connection: catalog
-- --------------------------------
Expand Down Expand Up @@ -158,7 +158,7 @@ CREATE TABLE `product_dimensions` (
(catalog-fixes) $ # do some work back on master...
(catalog-fixes) $ git checkout master
(master) $ # restore schema to previous state
(master) $ bin/morphism-diff --apply-changes=yes config.yml catalog
(master) $ bin/morphism diff --apply-changes=yes config.yml catalog
```

## Testing
Expand Down
13 changes: 13 additions & 0 deletions bin/morphism
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env php
<?php

require __DIR__ . '/../vendor/autoload.php';

$console = new Symfony\Component\Console\Application();

$console->add(new Graze\Morphism\Command\Diff());
$console->add(new Graze\Morphism\Command\Fastdump());
$console->add(new Graze\Morphism\Command\Extract());
$console->add(new Graze\Morphism\Command\Lint());

$console->run();
14 changes: 0 additions & 14 deletions bin/morphism-diff

This file was deleted.

14 changes: 0 additions & 14 deletions bin/morphism-dump

This file was deleted.

14 changes: 0 additions & 14 deletions bin/morphism-extract

This file was deleted.

15 changes: 0 additions & 15 deletions bin/morphism-lint

This file was deleted.

15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
],
"require": {
"php": ">=5.5",
"symfony/yaml": "~2.6",
"doctrine/dbal": "~2.5"

"doctrine/dbal": "~2.5",
"symfony/console": "^2.8",
"symfony/yaml": "~2.6"
},
"require-dev": {
"graze/standards": "^1.0",
"phpunit/phpunit": "~4.5",
"squizlabs/php_codesniffer": "^2.5",
"graze/standards": "^1.0"
"squizlabs/php_codesniffer": "^2.5"
},
"autoload": {
"psr-4": {
Expand All @@ -53,9 +55,6 @@
}
},
"bin": [
"./bin/morphism-diff",
"./bin/morphism-dump",
"./bin/morphism-extract",
"./bin/morphism-lint"
"./bin/morphism"
]
}
Loading

0 comments on commit 6d81cd4

Please sign in to comment.