Skip to content

Commit

Permalink
Extend migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeniy Guseletov committed Aug 7, 2012
1 parent 82438f3 commit 37f6068
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/DoctrineMigrations/Version20120630111620.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ public function up(Schema $schema)
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");

$this->addSql("ALTER TABLE bundle ADD nbRecommenders INT NOT NULL");

$recommendersSql = <<<EOF
UPDATE bundle
JOIN (
SELECT id, name, (
SELECT COUNT(*) FROM bundles_usage WHERE bundle_id = bundle.id
) AS usages
FROM bundle AS bundle
) AS number
ON number.id = bundle.id
SET bundle.nbRecommenders = number.usages
EOF;

$this->addSql($recommendersSql);
}

public function down(Schema $schema)
Expand Down

0 comments on commit 37f6068

Please sign in to comment.