Skip to content

Fix repo #31

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Migrate/Command/AbstractEnvCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ protected function init(InputInterface $input, OutputInterface $output, $env = n
$username = ArrayUtil::get($conf['connection'], 'username');
$password = ArrayUtil::get($conf['connection'], 'password');
$charset = ArrayUtil::get($conf['connection'], 'charset');
$sslCaCert = ArrayUtil::get($conf['connection'], 'ssl-ca-cert');
$sslCert = ArrayUtil::get($conf['connection'], 'ssl-cert');
$sslKey = ArrayUtil::get($conf['connection'], 'ssl-key');

$uri = $driver;
$opt = array();

if ($driver == 'sqlite') {
$uri .= ":$dbname";
Expand All @@ -89,12 +93,28 @@ protected function init(InputInterface $input, OutputInterface $output, $env = n
$uri .= ($host === null) ? '' : ";host=$host";
$uri .= ($port === null) ? '' : ";port=$port";
$uri .= ($charset === null) ? '' : ";charset=$charset";

// add an ssl ca cert
if (!empty($sslCaCert)) {
$opt[\PDO::MYSQL_ATTR_SSL_CA] = $sslCaCert;
}

// add an ssl cert
if (!empty($sslCert)) {
$opt[\PDO::MYSQL_ATTR_SSL_CERT] = $sslCert;
}

// add an ssl key
if (!empty($sslKey)) {
$opt[\PDO::MYSQL_ATTR_SSL_KEY] = $sslKey;
}
}

$this->db = new \PDO(
$uri,
$username,
$password,
array()
$opt
);

$output->writeln('<info>connected</info>');
Expand Down
21 changes: 21 additions & 0 deletions Migrate/Command/AddEnvCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
);
$defaultEditor = $questions->ask($input, $output, $defaultEditorQuestion);

$sslCaCertQuestion = new Question(
"Please enter the path and name of the SSL certificate authority certificate to use (if any): ",
"vim"
);
$sslCaCert = $questions->ask($input, $output, $sslCaCertQuestion);

$sslCertQuestion = new Question(
"Please enter the path and name of the SSL certificate to use (if any): ",
""
);
$sslCert = $questions->ask($input, $output, $sslCertQuestion);

$sslKeyQuestion = new Question(
"Please enter the path and name of the SSL certificate key to use (if any): ",
""
);
$sslKey = $questions->ask($input, $output, $sslKeyQuestion);

$confTemplate = file_get_contents(__DIR__ . '/../../templates/env.' . $format . '.tpl');
$confTemplate = str_replace('{DRIVER}', $driver, $confTemplate);
$confTemplate = str_replace('{HOST}', $dbHost, $confTemplate);
Expand All @@ -111,6 +129,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$confTemplate = str_replace('{CHARSET}', $dbCharset, $confTemplate);
$confTemplate = str_replace('{CHANGELOG}', $changelogTable, $confTemplate);
$confTemplate = str_replace('{EDITOR}', $defaultEditor, $confTemplate);
$confTemplate = str_replace('{SSLCACERT}', $sslCaCert, $confTemplate);
$confTemplate = str_replace('{SSLCERT}', $sslCert, $confTemplate);
$confTemplate = str_replace('{SSLKEY}', $sslKey, $confTemplate);

file_put_contents($envConfigFile, $confTemplate);
}
Expand Down
22 changes: 17 additions & 5 deletions Migrate/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,23 @@ public function toArray()

public function load($migrationDir)
{
$content = file_get_contents($migrationDir . '/' . $this->getFile());
if ($content && strpos($content, '@UNDO') > 0) {
$sql = explode('-- @UNDO', $content);
$this->setSqlUp($sql[0]);
$this->setSqlDown($sql[1]);
// construct migration file's path
$file = $migrationDir . '/' . $this->getFile();

// does the migration file exists?
if (file_exists($file)) {
// get the contents of the file ...
$content = file_get_contents($migrationDir . '/' . $this->getFile());
// ... and split it into the UP and DOWN migration sections
if ($content && strpos($content, '@UNDO') > 0) {
$sql = explode('-- @UNDO', $content);
$this->setSqlUp($sql[0]);
$this->setSqlDown($sql[1]);
}
// the migration is missing
} else {
// output the file name so the user can do some cleanup
echo "Missing migration file: $file\n";
}
}
}
88 changes: 44 additions & 44 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
{
"name": "alwex/php-database-migration",
"description": "rake and mybatis SQL migration tool",
"homepage": "https://github.com/alwex/php-database-migration",
"keywords": [
"rake",
"mybatis",
"migration",
"sql"
],
"type": "library",
"license": "MIT",
"authors": [
{
"name": "GUIDET Alexandre",
"email": "alwex@free.fr"
"name": "sovrn/php-database-migration",
"description": "rake and mybatis SQL migration tool",
"homepage": "https://github.com/sovrn/php-database-migration",
"keywords": [
"rake",
"mybatis",
"migration",
"sql"
],
"type": "library",
"license": "MIT",
"authors": [
{
"name": "GUIDET Alexandre",
"email": "alwex@free.fr"
}
],
"require": {
"php": ">=5.3.0",
"symfony/console": "^4.4",
"symfony/process": "^4.4",
"symfony/config": "^4.4",
"cocur/slugify": "~1.0",
"symfony/yaml": "^4.4"
},
"require-dev": {
"phpunit/phpunit": "*",
"squizlabs/php_codesniffer": "*"
},
"bin": [
"bin/migrate"
],
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-4": {
"Migrate\\": "Migrate/"
}
},
"autoload-dev": {
"psr-4": {
"Migrate\\Test\\": "tests/"
}
}
],
"require": {
"php": ">=5.3.0",
"symfony/console": "~2.6|~3.0",
"symfony/process": "~2.6|~3.0",
"symfony/config": "~2.6|~3.0",
"cocur/slugify": "~1.0",
"symfony/yaml": "~2.6|~3.0"
},
"require-dev": {
"phpunit/phpunit": "*",
"squizlabs/php_codesniffer": "*"
},
"bin": [
"bin/migrate"
],
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-4": {
"Migrate\\": "Migrate/"
}
},
"autoload-dev": {
"psr-4": {
"Migrate\\Test\\": "tests/"
}
}
}
Loading