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
13 public function up(Schema
$schema)
15 $this->skipIf('sqlite' === $this->connection
->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
17 // Find tags which need to be merged
18 $dupTags = $this->connection
->query('
19 SELECT LOWER(label) AS lower_label
20 FROM ' . $this->getTable('tag') . '
26 foreach ($dupTags->fetchAll() as $duplicates) {
27 $label = $duplicates['lower_label'];
29 // Retrieve all duplicate tags for a given tag
30 $tags = $this->connection
->executeQuery('
32 FROM ' . $this->getTable('tag') . '
33 WHERE LOWER(label) = :label
44 foreach ($tags->fetchAll() as $tag) {
45 // Ignore the first tag as we use it as the new reference tag
55 if (\
count($ids) > 0) {
58 UPDATE ' . $this->getTable('entry_tag') . '
59 SET tag_id = ' . $newId . '
60 WHERE tag_id IN (' . implode(',', $ids) . ')
63 FROM (SELECT * FROM ' . $this->getTable('entry_tag') . ') AS _entry_tag
64 WHERE tag_id = ' . $newId . '
68 // Delete links to unused tags
70 DELETE FROM ' . $this->getTable('entry_tag') . '
71 WHERE tag_id IN (' . implode(',', $ids) . ')'
76 DELETE FROM ' . $this->getTable('tag') . '
77 WHERE id IN (' . implode(',', $ids) . ')'
82 // Iterate over all tags to lowercase them
84 UPDATE ' . $this->getTable('tag') . '
85 SET label = LOWER(label)'
89 public function down(Schema
$schema)
91 throw new SkipMigrationException('Too complex ...');