1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* http://www.lockon.co.jp/ |
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\Common\Constant; |
19
|
|
|
|
20
|
|
|
class Version[datetime] extends AbstractMigration |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
protected $entities = array( |
|
|
|
|
23
|
|
|
[entityList] |
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
public function up(Schema $schema) |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$app = \Eccube\Application::getInstance(); |
29
|
|
|
$meta = $this->getMetadata($app['orm.em']); |
30
|
|
|
$tool = new SchemaTool($app['orm.em']); |
31
|
|
|
$tool->createSchema($meta); |
32
|
|
|
|
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function down(Schema $schema) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$app = \Eccube\Application::getInstance(); |
38
|
|
|
$meta = $this->getMetadata($app['orm.em']); |
39
|
|
|
|
40
|
|
|
$tool = new SchemaTool($app['orm.em']); |
41
|
|
|
$schemaFromMetadata = $tool->getSchemaFromMetadata($meta); |
42
|
|
|
|
43
|
|
|
// テーブル削除 |
44
|
|
|
foreach ($schemaFromMetadata->getTables() as $table) { |
45
|
|
|
if ($schema->hasTable($table->getName())) { |
46
|
|
|
$schema->dropTable($table->getName()); |
47
|
|
|
} |
|
|
|
|
48
|
|
|
} |
|
|
|
|
49
|
|
|
|
50
|
|
|
// シーケンス削除 |
51
|
|
|
foreach ($schemaFromMetadata->getSequences() as $sequence) { |
52
|
|
|
if ($schema->hasSequence($sequence->getName())) { |
53
|
|
|
$schema->dropSequence($sequence->getName()); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function getMetadata(EntityManager $em) |
59
|
|
|
{ |
60
|
|
|
$meta = array(); |
61
|
|
|
foreach ($this->entities as $entity) { |
62
|
|
|
$meta[] = $em->getMetadataFactory()->getMetadataFor($entity); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $meta; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|