Skip to content

Commit a093a96

Browse files
authored
Append sqlite suffix to name on info output (#2307)
1 parent cbcd067 commit a093a96

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/Phinx/Console/Command/AbstractCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Phinx\Config\Config;
1313
use Phinx\Config\ConfigInterface;
1414
use Phinx\Db\Adapter\AdapterInterface;
15+
use Phinx\Db\Adapter\SQLiteAdapter;
1516
use Phinx\Migration\Manager;
1617
use Phinx\Util\Util;
1718
use RuntimeException;
@@ -465,7 +466,11 @@ protected function writeInformationOutput(?string &$environment, OutputInterface
465466
}
466467

467468
if (isset($envOptions['name'])) {
468-
$output->writeln('<info>using database</info> ' . $envOptions['name'], $this->verbosityLevel);
469+
$name = $envOptions['name'];
470+
if ($envOptions['adapter'] === 'sqlite') {
471+
$name .= SQLiteAdapter::getSuffix($envOptions);
472+
}
473+
$output->writeln('<info>using database</info> ' . $name, $this->verbosityLevel);
469474
} else {
470475
$output->writeln('<error>Could not determine database name! Please specify a database name in your config file.</error>');
471476

src/Phinx/Db/Adapter/SQLiteAdapter.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class SQLiteAdapter extends PdoAdapter
3131
{
3232
public const MEMORY = ':memory:';
3333

34+
public const DEFAULT_SUFFIX = '.sqlite3';
35+
3436
/**
3537
* List of supported Phinx column types with their SQL equivalents
3638
* some types have an affinity appended to ensure they do not receive NUMERIC affinity
@@ -121,7 +123,7 @@ class SQLiteAdapter extends PdoAdapter
121123
/**
122124
* @var string
123125
*/
124-
protected string $suffix = '.sqlite3';
126+
protected string $suffix = self::DEFAULT_SUFFIX;
125127

126128
/**
127129
* Indicates whether the database library version is at least the specified version
@@ -195,21 +197,38 @@ public function connect(): void
195197
}
196198

197199
/**
198-
* @inheritDoc
200+
* Get the suffix to use for the SQLite database file.
201+
*
202+
* @param array $options Environment options
203+
* @return string
199204
*/
200-
public function setOptions(array $options): AdapterInterface
205+
public static function getSuffix(array $options): string
201206
{
202-
parent::setOptions($options);
207+
if ($options['name'] === self::MEMORY) {
208+
return '';
209+
}
203210

211+
$suffix = self::DEFAULT_SUFFIX;
204212
if (isset($options['suffix'])) {
205-
$this->suffix = $options['suffix'];
213+
$suffix = $options['suffix'];
206214
}
207215
//don't "fix" the file extension if it is blank, some people
208216
//might want a SQLITE db file with absolutely no extension.
209-
if ($this->suffix !== '' && strpos($this->suffix, '.') !== 0) {
210-
$this->suffix = '.' . $this->suffix;
217+
if ($suffix !== '' && strpos($suffix, '.') !== 0) {
218+
$suffix = '.' . $suffix;
211219
}
212220

221+
return $suffix;
222+
}
223+
224+
/**
225+
* @inheritDoc
226+
*/
227+
public function setOptions(array $options): AdapterInterface
228+
{
229+
parent::setOptions($options);
230+
$this->suffix = self::getSuffix($options);
231+
213232
return $this;
214233
}
215234

0 commit comments

Comments
 (0)