1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the [code] |
5
|
|
|
* |
6
|
|
|
* Copyright (C) [year] [author] |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DoctrineMigrations; |
13
|
|
|
|
14
|
|
|
use Doctrine\DBAL\Migrations\AbstractMigration; |
15
|
|
|
use Doctrine\DBAL\Schema\Schema; |
16
|
|
|
use Doctrine\ORM\EntityManager; |
17
|
|
|
use Doctrine\ORM\Tools\SchemaTool; |
18
|
|
|
use Eccube\Application; |
19
|
|
|
|
20
|
|
|
class Version[datetime] extends AbstractMigration |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
protected $entities = array( |
|
|
|
|
23
|
|
|
[entityList] |
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param Schema $schema |
28
|
|
|
*/ |
29
|
|
|
public function up(Schema $schema) |
30
|
|
|
{ |
31
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
32
|
|
|
|
33
|
|
|
$app = Application::getInstance(); |
34
|
|
|
$meta = $this->getMetadata($app['orm.em']); |
35
|
|
|
$tool = new SchemaTool($app['orm.em']); |
36
|
|
|
$tool->createSchema($meta); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param Schema $schema |
41
|
|
|
*/ |
42
|
|
|
public function down(Schema $schema) |
43
|
|
|
{ |
44
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
45
|
|
|
|
46
|
|
|
$app = Application::getInstance(); |
47
|
|
|
$meta = $this->getMetadata($app['orm.em']); |
48
|
|
|
|
49
|
|
|
$tool = new SchemaTool($app['orm.em']); |
50
|
|
|
$schemaFromMetadata = $tool->getSchemaFromMetadata($meta); |
51
|
|
|
|
52
|
|
|
// テーブル削除 |
53
|
|
|
foreach ($schemaFromMetadata->getTables() as $table) { |
54
|
|
|
if ($schema->hasTable($table->getName())) { |
55
|
|
|
$schema->dropTable($table->getName()); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// シーケンス削除 |
60
|
|
|
foreach ($schemaFromMetadata->getSequences() as $sequence) { |
61
|
|
|
if ($schema->hasSequence($sequence->getName())) { |
62
|
|
|
$schema->dropSequence($sequence->getName()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param EntityManager $em |
69
|
|
|
* @return array |
70
|
|
|
* @throws \Doctrine\Common\Persistence\Mapping\MappingException |
71
|
|
|
*/ |
72
|
|
|
protected function getMetadata(EntityManager $em) |
73
|
|
|
{ |
74
|
|
|
$meta = array(); |
75
|
|
|
foreach ($this->entities as $entity) { |
76
|
|
|
$meta[] = $em->getMetadataFactory()->getMetadataFor($entity); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $meta; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|