Skip to content

Commit 7de6f74

Browse files
author
xiaodong.li
committed
support database charset
1 parent 7dc6fd3 commit 7de6f74

3 files changed

Lines changed: 7 additions & 0 deletions

File tree

Migrate/Command/AbstractEnvCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ protected function init(InputInterface $input, OutputInterface $output, $env = n
8080
$dbname = ArrayUtil::get($conf['connection'], 'database');
8181
$username = ArrayUtil::get($conf['connection'], 'username');
8282
$password = ArrayUtil::get($conf['connection'], 'password');
83+
$charset = ArrayUtil::get($conf['charset'], 'charset');
8384

8485
$uri = $driver;
8586

@@ -89,6 +90,7 @@ protected function init(InputInterface $input, OutputInterface $output, $env = n
8990
$uri .= ($dbname === null) ? '' : ":dbname=$dbname";
9091
$uri .= ($host === null) ? '' : ";host=$host";
9192
$uri .= ($port === null) ? '' : ";port=$port";
93+
$uri .= ($charset === null) ? '' : ";charset=$charset";
9294
}
9395
$this->db = new \PDO(
9496
$uri,

Migrate/Command/AddEnvCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
6969
$dbUserPasswordQuestion = new Question("Please enter the database user password (if needed): ", "~");
7070
$dbUserPassword = $questions->ask($input, $output, $dbUserPasswordQuestion);
7171

72+
$dbCharsetQuestion = new Question("Please enter the database charset (if needed): ", "~");
73+
$dbCharset = $questions->ask($input, $output, $dbCharsetQuestion);
74+
7275
$changelogTableQuestion = new Question("Please enter the changelog table <info>(default changelog)</info>: ", "changelog");
7376
$changelogTable = $questions->ask($input, $output, $changelogTableQuestion);
7477

@@ -82,6 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8285
$confTemplate = str_replace('{USERNAME}', $dbUserName, $confTemplate);
8386
$confTemplate = str_replace('{PASSWORD}', $dbUserPassword, $confTemplate);
8487
$confTemplate = str_replace('{DATABASE}', $dbName, $confTemplate);
88+
$confTemplate = str_replace('{CHARSET}', $dbCharset, $confTemplate);
8589
$confTemplate = str_replace('{CHANGELOG}', $changelogTable, $confTemplate);
8690
$confTemplate = str_replace('{EDITOR}', $defaultEditor, $confTemplate);
8791

templates/env.yml.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ connection:
55
username: {USERNAME}
66
password: {PASSWORD}
77
database: {DATABASE}
8+
charset: {CHARSET}
89

910
changelog: {CHANGELOG}
1011
default_editor: {EDITOR}

0 commit comments

Comments
 (0)