|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Application\Migrations; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Migrations\AbstractMigration; |
|
6
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Auto-generated Migration: Please modify to your needs! |
|
10
|
|
|
*/ |
|
11
|
|
|
class Version20140324104524 extends AbstractMigration |
|
12
|
|
|
{ |
|
13
|
|
|
public function up(Schema $schema) |
|
14
|
|
|
{ |
|
15
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
|
16
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'."); |
|
17
|
|
|
|
|
18
|
|
|
$this->addSql("CREATE TABLE event__promo_code (id INT AUTO_INCREMENT NOT NULL, event_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, discountAmount INT NOT NULL, code VARCHAR(255) NOT NULL, endDate DATETIME NOT NULL, INDEX IDX_F54EB06671F7E88B (event_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); |
|
19
|
|
|
$this->addSql("ALTER TABLE event__promo_code ADD CONSTRAINT FK_F54EB06671F7E88B FOREIGN KEY (event_id) REFERENCES event__events (id) ON DELETE CASCADE"); |
|
20
|
|
|
$this->addSql("ALTER TABLE event__tickets ADD promo_code_id INT DEFAULT NULL, ADD amount NUMERIC(10, 2) NOT NULL, ADD amount_without_discount NUMERIC(10, 2) NOT NULL, ADD has_discount TINYINT(1) NOT NULL"); |
|
21
|
|
|
$this->addSql("ALTER TABLE event__tickets ADD CONSTRAINT FK_66E295592FAE4625 FOREIGN KEY (promo_code_id) REFERENCES event__promo_code (id) ON DELETE SET NULL"); |
|
22
|
|
|
$this->addSql("CREATE INDEX IDX_66E295592FAE4625 ON event__tickets (promo_code_id)"); |
|
23
|
|
|
$statament = $this->connection->prepare('SELECT * FROM payments'); |
|
24
|
|
|
$statament->execute(); |
|
25
|
|
|
while ($row = $statament->fetch()) { |
|
26
|
|
|
$this->addSql('UPDATE event__tickets SET amount = ' . $row['amount'] . |
|
27
|
|
|
', amount_without_discount = ' . $row['amount_without_discount'] . |
|
28
|
|
|
', has_discount = ' . $row['has_discount'] . |
|
29
|
|
|
' WHERE payment_id = ' . $row['id']); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$this->addSql("ALTER TABLE payments DROP has_discount, DROP amount_without_discount"); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function down(Schema $schema) |
|
36
|
|
|
{ |
|
37
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
|
38
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'."); |
|
39
|
|
|
|
|
40
|
|
|
$this->addSql("ALTER TABLE event__tickets DROP FOREIGN KEY FK_66E295592FAE4625"); |
|
41
|
|
|
$this->addSql("DROP TABLE event__promo_code"); |
|
42
|
|
|
$this->addSql("DROP INDEX IDX_66E295592FAE4625 ON event__tickets"); |
|
43
|
|
|
$this->addSql("ALTER TABLE event__tickets DROP promo_code_id, DROP amount, DROP amount_without_discount, DROP has_discount"); |
|
44
|
|
|
$this->addSql("ALTER TABLE payments ADD has_discount TINYINT(1) NOT NULL, ADD amount_without_discount NUMERIC(10, 2) NOT NULL"); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|