3 namespace Application\Migrations
;
5 use Doctrine\DBAL\Schema\Schema
;
6 use Wallabag\CoreBundle\Doctrine\WallabagMigration
;
9 * Changed tags to lowercase.
11 class Version20170719231144
extends WallabagMigration
14 * @param Schema $schema
16 public function up(Schema
$schema)
18 $this->skipIf('sqlite' === $this->connection
->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
20 // Find tags which need to be merged
21 $dupTags = $this->connection
->query('
22 SELECT LOWER(label) AS lower_label
23 FROM ' . $this->getTable('tag') . '
29 foreach ($dupTags->fetchAll() as $duplicates) {
30 $label = $duplicates['lower_label'];
32 // Retrieve all duplicate tags for a given tag
33 $tags = $this->connection
->executeQuery('
35 FROM ' . $this->getTable('tag') . '
36 WHERE LOWER(label) = :label
47 foreach ($tags->fetchAll() as $tag) {
48 // Ignore the first tag as we use it as the new reference tag
58 if (\
count($ids) > 0) {
61 UPDATE ' . $this->getTable('entry_tag') . '
62 SET tag_id = ' . $newId . '
63 WHERE tag_id IN (' . implode(',', $ids) . ')
66 FROM (SELECT * FROM ' . $this->getTable('entry_tag') . ') AS _entry_tag
67 WHERE tag_id = ' . $newId . '
71 // Delete links to unused tags
73 DELETE FROM ' . $this->getTable('entry_tag') . '
74 WHERE tag_id IN (' . implode(',', $ids) . ')'
79 DELETE FROM ' . $this->getTable('tag') . '
80 WHERE id IN (' . implode(',', $ids) . ')'
85 // Iterate over all tags to lowercase them
87 UPDATE ' . $this->getTable('tag') . '
88 SET label = LOWER(label)'
93 * @param Schema $schema
95 public function down(Schema
$schema)
97 throw new SkipMigrationException('Too complex ...');