Skip to content

Commit

Permalink
Merge d8eadf2 into e51cf49
Browse files Browse the repository at this point in the history
  • Loading branch information
howyi committed Jan 23, 2019
2 parents e51cf49 + d8eadf2 commit 106c75f
Show file tree
Hide file tree
Showing 121 changed files with 1,822 additions and 2,914 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ language: php
php:
- 7.1
before_script:
- composer install --dev
- composer install
script:
- make heat
- vendor/bin/phpunit --coverage-clover=build/log/clover.xml
- vendor/bin/phpstan analyse -l 7 -c phpstan.neon src
- composer stan
- composer cs
after_success:
- travis_retry php vendor/bin/coveralls -v
- travis_retry php vendor/bin/php-coveralls -v
notifications:
slack:
secure: YnDFdn2JQIgz9XNrmhmM3drDNUpJ+H1rWdtnC+1+2JP1Ahv4XhBcYBCBQVZbBJtYICaqR4xwbWEgqRpwumVRfBJsxNPfndYHEQ9F6ZaZBoVPcp+peOdXHv7mparkH4Z8RLQSsdsXeL1CIkaWs+blKtWmZ7utSbqpNkhgDoJxUZKLGyhmpNj1anfXAYzxomv0Mx7Vrhu6tokWk8l1Mde3vd2ZT/Bd46sXAknk7KariwqGHAVpoFczYdtXd+e7EiNxSAw6freU6DQ+cOShqAxTqKL0X/h1xW6utQZXvLBHxh0mNRd/w3HTgbc1e7HqEPi2q5sBJRXtIFdCEdjvkPnW9aHLXuvnHjrXGfFA88RdJMf4YzG/9Pnr5jXwpP/M5LovMJ6X2N0pKAjFTWK1++baIXRJ5cHe5wJSVk/aKK85J9nFZsXeB1cUTxqFzyXfozAIAbNlXp9kpwzbjREfFuK7Dz4TUMi7DgrW18Jc8W9Ms9fjtYvcxgvf/D3CEenfSNGzWMniOKWdcop5AalzwEurEDGF41Lq7hEef3VE2CG0QLO9LEhhPYWs09Uzho0qYB/maiAwY8J+J5hxHwD8G47XGRwwPwc08PLfzI1NfKW2SMjfkkIFBDCwVeVj5rJkN+PR9vAFSf/kN/gC6pdawzZz09OpR/rY29aVI+ptLiN3eqE=
10 changes: 0 additions & 10 deletions Makefile

This file was deleted.

78 changes: 12 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
[![Build Status](https://travis-ci.org/howyi/conv.svg?branch=master)](https://travis-ci.org/howyi/conv)
[![Coverage Status](https://coveralls.io/repos/github/howyi/conv/badge.svg?branch=master#konbu)](https://coveralls.io/github/howyi/conv?branch=master)
# conv
MySQL migration query auto generate from schema
Generate MySQL migration queries from actual DB and DDL

```
composer require howyi/conv --dev
```

- document: https://howyi.gitbooks.io/conv/content/ja/

### 概要
指定したPDOのテーブルとYAMLのスキーマ差分からMySQLのクエリを生成する
実DBとCREATE文のディレクトリからMySQLのマイグレーションクエリを生成する

#### YAML sample
tbl_user.yml
```yaml
comment: 'User management table'
column:
user_id:
type: int(11)
comment: 'User ID'
age:
type: tinyint(3)
comment: 'User age'
attribute: [nullable, unsigned]
primary_key:
- user_id
index:
id_age:
is_unique: false
column: [user_id, age]
#### Query sample
tbl_user.sql
```sql
CREATE TABLE `tbl_user` (
`user_id` int(11) NOT NULL COMMENT 'User ID',
`age` tinyint(3) UNSIGNED COMMENT 'User age',
PRIMARY KEY (`user_id`),
KEY `id_age` (`user_id`, `age`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='User management table';
```
#### Generated migration
UP
Expand All @@ -44,47 +33,4 @@ CREATE TABLE `tbl_user` (
DOWN
```sql
DROP TABLE `tbl_user`;
```

#### Migrated and Modified
```yaml
comment: 'All user management table'
column:
user_id:
type: bigint(20)
comment: 'User ID'
attribute: [auto_increment, unsigned]
name:
type: varchar(255)
comment: 'User name'
age:
type: tinyint(3)
comment: 'User age'
attribute: [nullable, unsigned]
primary_key:
- user_id
index:
id_age:
is_unique: true
column: [user_id, age]
```

#### And regenerated migration
UP
```sql
ALTER TABLE `tbl_user`
COMMENT 'All user management table',
DROP INDEX `id_age`,
CHANGE `user_id` `user_id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'User ID',
ADD COLUMN `name` varchar(255) NOT NULL COMMENT 'User name' AFTER `user_id`,
ADD UNIQUE `id_age` (`user_id`, `age`);
```
DOWN
```sql
ALTER TABLE `tbl_user`
DROP INDEX `id_age`,
DROP COLUMN `name`,
CHANGE `user_id` `user_id` int(11) NOT NULL COMMENT 'User ID',
ADD INDEX `id_age` (`user_id`, `age`),
COMMENT 'User management table';
```
```
11 changes: 0 additions & 11 deletions book.json

This file was deleted.

Empty file removed clover.xml
Empty file.
56 changes: 42 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "howyi/conv",
"description": "MySQL migration query auto generate from schema",
"description": "Generate MySQL migration queries from actual DB and DDL",
"type": "library",
"license": "MIT",
"authors": [
Expand All @@ -9,26 +9,54 @@
"email": "qrbys@outlook.com"
}
],
"scripts": {
"test": "phpunit",
"stan": "phpstan analyse -l 7 src",
"cs": "phpcs --standard=PSR12 src tests",
"cbf": "phpcbf --standard=PSR12 src tests",
"check-fix": [
"composer stan",
"composer test",
"composer cbf"
],
"check": [
"composer stan",
"composer test",
"composer cs"
]
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/laminaria/conv-test-suite.git",
"no-api": true
}
],
"minimum-stability": "stable",
"require": {
"php": ">=7.1",
"symfony/console": ">=2.0",
"symfony/yaml": ">=2.0",
"howyi/evi": "~1.0.0"
"php": ">=7.1",
"ext-PDO": "*",
"symfony/console": ">=2.0",
"composer/semver": "^1.4"
},
"autoload": {
"psr-0": {
"Conv": "src/"
"psr-4": {
"Laminaria\\Conv\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Laminaria\\Conv\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^6.2",
"symfony/var-dumper": "^3.3",
"satooshi/php-coveralls": "^1.0",
"phpspec/prophecy": "^1.7",
"phpstan/phpstan": "^0.8.0",
"squizlabs/php_codesniffer": "^3.0",
"howyi/retort": "~1.0.0"
"phpunit/phpunit": "^6.2",
"symfony/var-dumper": "^3.3",
"php-coveralls/php-coveralls": "^2.1",
"phpspec/prophecy": "^1.7",
"phpstan/phpstan": "^0.8.0",
"squizlabs/php_codesniffer": "^3.0",
"laminaria/conv-test-suite": "dev-master"
},
"bin": ["bin/conv"]
}
4 changes: 0 additions & 4 deletions conv.yml

This file was deleted.

19 changes: 3 additions & 16 deletions debug
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,7 @@ $dir = current(current($composerData->autoload));

$app = new Application();

$s = DIRECTORY_SEPARATOR;
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator("$dir$name{$s}DebugCommand")
);

foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile() and 'php' === strtolower($fileinfo->getExtension())) {
$path = $fileinfo->getPathName();
$className = str_replace([$dir, '.php', '/'], ['', '', '\\'], $path);
$class = (new \ReflectionClass($className));
if ($class->isAbstract() or $class->isInterface()) {
continue;
}
$app->add(new $className());
}
}
$app->add(new \Laminaria\Conv\DebugCommand\CheckAlterCommand());
$app->add(new \Laminaria\Conv\DebugCommand\ReflectCommand());
$app->add(new \Laminaria\Conv\DebugCommand\SetupCommand());
$app->run();
39 changes: 39 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: '3'
services:
php-71:
build: ./docker
working_dir: /usr/src/app
environment:
DB_HOST: mysql-56:3306,mysql-57:3306,mysql-80:3306
command: ./docker/wait-for-it.sh -t 0 mysql-80:3306 -- vendor/bin/phpunit
volumes:
- .:/usr/src/app
depends_on:
- mysql-56
- mysql-57
- mysql-80

mysql-56:
image: mysql:5.6
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_ROOT_PASSWORD: ''

mysql-57:
image: mysql:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_ROOT_PASSWORD: ''
depends_on:
- mysql-56

mysql-80:
image: mysql:8.0
command: mysqld --default-authentication-plugin=mysql_native_password
security_opt:
- seccomp:unconfined
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_ROOT_PASSWORD: ''
depends_on:
- mysql-57
3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM php:7.1
RUN yes "" | pecl install xdebug && docker-php-ext-enable xdebug
RUN docker-php-ext-install pdo_mysql

0 comments on commit 106c75f

Please sign in to comment.