Skip to content

Commit 77f7d51

Browse files
committed
Better error message in console.
1 parent 4370cd1 commit 77f7d51

File tree

7 files changed

+107
-71
lines changed

7 files changed

+107
-71
lines changed

src/Console/ConsoleCommand.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
8989
}
9090
}
9191

92+
protected function handleError($ex, OutputInterface $output)
93+
{
94+
$output->writeln('-- Error migrating tables --');
95+
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
96+
$output->writeln(get_class($ex));
97+
$output->writeln($ex->getMessage());
98+
}
99+
}
100+
92101

93102
}

src/Console/DatabaseVersionCommand.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ protected function configure()
2525
protected function execute(InputInterface $input, OutputInterface $output)
2626
{
2727
parent::execute($input, $output);
28-
$versionInfo = $this->migration->getCurrentVersion();
29-
$output->writeln('version: ' . $versionInfo['version']);
30-
$output->writeln('status.: ' . $versionInfo['status']);
28+
try {
29+
$versionInfo = $this->migration->getCurrentVersion();
30+
$output->writeln('version: ' . $versionInfo['version']);
31+
$output->writeln('status.: ' . $versionInfo['status']);
32+
} catch (\Exception $ex) {
33+
$this->handleError($ex, $output);
34+
}
3135
}
3236
}

src/Console/DownCommand.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,27 @@ protected function configure()
2525

2626
protected function execute(InputInterface $input, OutputInterface $output)
2727
{
28-
$versionInfo = $this->migration->getCurrentVersion();
29-
if (strpos($versionInfo['status'], 'partial') !== false) {
30-
$helper = $this->getHelper('question');
31-
$question = new ConfirmationQuestion(
32-
'The database was not fully updated and maybe be unstable. Did you really want migrate the version? (y/N)',
33-
false
34-
);
35-
36-
if (!$helper->ask($input, $output, $question)) {
37-
$output->writeln('Aborted.');
38-
39-
return;
28+
try {
29+
$versionInfo = $this->migration->getCurrentVersion();
30+
if (strpos($versionInfo['status'], 'partial') !== false) {
31+
$helper = $this->getHelper('question');
32+
$question = new ConfirmationQuestion(
33+
'The database was not fully updated and maybe be unstable. Did you really want migrate the version? (y/N)',
34+
false
35+
);
36+
37+
if (!$helper->ask($input, $output, $question)) {
38+
$output->writeln('Aborted.');
39+
40+
return;
41+
}
4042
}
41-
}
4243

43-
parent::execute($input, $output);
44-
$this->migration->down($this->upTo, true);
44+
parent::execute($input, $output);
45+
$this->migration->down($this->upTo, true);
46+
} catch (\Exception $ex) {
47+
$this->handleError($ex, $output);
48+
}
4549
}
4650

4751
}

src/Console/InstallCommand.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,26 @@ protected function configure()
2626

2727
protected function execute(InputInterface $input, OutputInterface $output)
2828
{
29-
parent::execute($input, $output);
30-
31-
$action = 'Database is already versioned. ';
3229
try {
33-
$this->migration->getCurrentVersion();
34-
} catch (DatabaseNotVersionedException $ex) {
35-
$action = 'Created the version table';
36-
$this->migration->createVersion();
37-
} catch (OldVersionSchemaException $ex) {
38-
$action = 'Updated the version table';
39-
$this->migration->updateTableVersion();
40-
}
30+
parent::execute($input, $output);
4131

42-
$version = $this->migration->getCurrentVersion();
43-
$output->writeln($action);
44-
$output->writeln('current version: ' . $version['version']);
45-
$output->writeln('current status.: ' . $version['status']);
32+
$action = 'Database is already versioned. ';
33+
try {
34+
$this->migration->getCurrentVersion();
35+
} catch (DatabaseNotVersionedException $ex) {
36+
$action = 'Created the version table';
37+
$this->migration->createVersion();
38+
} catch (OldVersionSchemaException $ex) {
39+
$action = 'Updated the version table';
40+
$this->migration->updateTableVersion();
41+
}
42+
43+
$version = $this->migration->getCurrentVersion();
44+
$output->writeln($action);
45+
$output->writeln('current version: ' . $version['version']);
46+
$output->writeln('current status.: ' . $version['status']);
47+
} catch (\Exception $ex) {
48+
$this->handleError($ex, $output);
49+
}
4650
}
4751
}

src/Console/ResetCommand.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,23 @@ protected function configure()
2525

2626
protected function execute(InputInterface $input, OutputInterface $output)
2727
{
28-
$helper = $this->getHelper('question');
29-
$question = new ConfirmationQuestion('This will ERASE all of data in your data. Continue with this action? (y/N) ', false);
30-
31-
if (!$helper->ask($input, $output, $question)) {
32-
$output->writeln('Aborted.');
33-
return;
28+
try {
29+
$helper = $this->getHelper('question');
30+
$question = new ConfirmationQuestion('This will ERASE all of data in your data. Continue with this action? (y/N) ',
31+
false);
32+
33+
if (!$helper->ask($input, $output, $question)) {
34+
$output->writeln('Aborted.');
35+
36+
return;
37+
}
38+
39+
parent::execute($input, $output);
40+
$this->migration->prepareEnvironment();
41+
$this->migration->reset($this->upTo);
42+
} catch (\Exception $ex) {
43+
$this->handleError($ex, $output);
3444
}
35-
36-
parent::execute($input, $output);
37-
$this->migration->prepareEnvironment();
38-
$this->migration->reset($this->upTo);
3945
}
4046

4147
}

src/Console/UpCommand.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,26 @@ protected function configure()
2525

2626
protected function execute(InputInterface $input, OutputInterface $output)
2727
{
28-
$versionInfo = $this->migration->getCurrentVersion();
29-
if (strpos($versionInfo['status'], 'partial') !== false) {
30-
$helper = $this->getHelper('question');
31-
$question = new ConfirmationQuestion(
32-
'The database was not fully updated and maybe be unstable. Did you really want migrate the version? (y/N) ',
33-
false
34-
);
35-
36-
if (!$helper->ask($input, $output, $question)) {
37-
$output->writeln('Aborted.');
38-
39-
return;
28+
try {
29+
$versionInfo = $this->migration->getCurrentVersion();
30+
if (strpos($versionInfo['status'], 'partial') !== false) {
31+
$helper = $this->getHelper('question');
32+
$question = new ConfirmationQuestion(
33+
'The database was not fully updated and maybe be unstable. Did you really want migrate the version? (y/N) ',
34+
false
35+
);
36+
37+
if (!$helper->ask($input, $output, $question)) {
38+
$output->writeln('Aborted.');
39+
40+
return;
41+
}
4042
}
41-
}
4243

43-
parent::execute($input, $output);
44-
$this->migration->up($this->upTo, true);
44+
parent::execute($input, $output);
45+
$this->migration->up($this->upTo, true);
46+
} catch (\Exception $ex) {
47+
$this->handleError($ex, $output);
48+
}
4549
}
4650
}

src/Console/UpdateCommand.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,26 @@ protected function configure()
2727

2828
protected function execute(InputInterface $input, OutputInterface $output)
2929
{
30-
$versionInfo = $this->migration->getCurrentVersion();
31-
if (strpos($versionInfo['status'], 'partial') !== false) {
32-
$helper = $this->getHelper('question');
33-
$question = new ConfirmationQuestion(
34-
'The database was not fully updated and maybe be unstable. Did you really want migrate the version? (y/N) ',
35-
false
36-
);
30+
try {
31+
$versionInfo = $this->migration->getCurrentVersion();
32+
if (strpos($versionInfo['status'], 'partial') !== false) {
33+
$helper = $this->getHelper('question');
34+
$question = new ConfirmationQuestion(
35+
'The database was not fully updated and maybe be unstable. Did you really want migrate the version? (y/N) ',
36+
false
37+
);
38+
39+
if (!$helper->ask($input, $output, $question)) {
40+
$output->writeln('Aborted.');
3741

38-
if (!$helper->ask($input, $output, $question)) {
39-
$output->writeln('Aborted.');
40-
return;
42+
return;
43+
}
4144
}
42-
}
4345

44-
parent::execute($input, $output);
45-
$this->migration->update($this->upTo, true);
46+
parent::execute($input, $output);
47+
$this->migration->update($this->upTo, true);
48+
} catch (\Exception $ex) {
49+
$this->handleError($ex, $output);
50+
}
4651
}
4752
}

0 commit comments

Comments
 (0)