|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Tools\Console\Command\SchemaTool; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\Tools\SchemaTool; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Command to create the database schema for a set of classes based on their mappings. |
|
15
|
|
|
*/ |
|
16
|
|
|
class CreateCommand extends AbstractCommand |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function configure() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->setName('orm:schema-tool:create') |
|
24
|
|
|
->setDescription('Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output') |
|
25
|
|
|
->addOption('dump-sql', null, InputOption::VALUE_NONE, 'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.') |
|
26
|
|
|
->setHelp(<<<'EOT' |
|
27
|
|
|
Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output. |
|
28
|
|
|
|
|
29
|
|
|
<comment>Hint:</comment> If you have a database with tables that should not be managed |
|
30
|
|
|
by the ORM, you can use a DBAL functionality to filter the tables and sequences down |
|
31
|
|
|
on a global level: |
|
32
|
|
|
|
|
33
|
|
|
$config->setFilterSchemaAssetsExpression($regexp); |
|
34
|
|
|
EOT |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui) |
|
42
|
|
|
{ |
|
43
|
|
|
$dumpSql = $input->getOption('dump-sql') === true; |
|
44
|
|
|
|
|
45
|
|
|
if ($dumpSql) { |
|
46
|
|
|
$sqls = $schemaTool->getCreateSchemaSql($metadatas); |
|
47
|
|
|
$ui->text('The following SQL statements will be executed:'); |
|
48
|
|
|
$ui->newLine(); |
|
49
|
|
|
|
|
50
|
|
|
foreach ($sqls as $sql) { |
|
51
|
|
|
$ui->text(sprintf(' %s;', $sql)); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return 0; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$ui->caution('This operation should not be executed in a production environment!'); |
|
58
|
|
|
|
|
59
|
|
|
$ui->text('Creating database schema...'); |
|
60
|
|
|
$ui->newLine(); |
|
61
|
|
|
|
|
62
|
|
|
$schemaTool->createSchema($metadatas); |
|
63
|
|
|
|
|
64
|
|
|
$ui->success('Database schema created successfully!'); |
|
65
|
|
|
|
|
66
|
|
|
return 0; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|