]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/DoctrineMigrations/Version20190401105353.php
Use a better index for hashed_url
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20190401105353.php
CommitLineData
9c2b2aae
JB
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Schema\Schema;
6use Wallabag\CoreBundle\Doctrine\WallabagMigration;
7
8/**
9 * Add hashed_url in entry.
10 */
11class Version20190401105353 extends WallabagMigration
12{
13 /**
14 * @param Schema $schema
15 */
16 public function up(Schema $schema)
17 {
18 $entryTable = $schema->getTable($this->getTable('entry'));
19
20 $this->skipIf($entryTable->hasColumn('hashed_url'), 'It seems that you already played this migration.');
21
22 $entryTable->addColumn('hashed_url', 'text', [
8a645662 23 'length' => 40,
9c2b2aae
JB
24 'notnull' => false,
25 ]);
26
27 // sqlite doesn't have the MD5 function by default
28 if ('sqlite' !== $this->connection->getDatabasePlatform()->getName()) {
29 $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET hashed_url = MD5(url)');
30 }
8a645662
JB
31
32 $entryTable->addIndex(['user_id', 'hashed_url'], 'hashed_url_user_id');
9c2b2aae
JB
33 }
34
35 /**
36 * @param Schema $schema
37 */
38 public function down(Schema $schema)
39 {
40 $entryTable = $schema->getTable($this->getTable('entry'));
41
42 $this->skipIf(!$entryTable->hasColumn('hashed_url'), 'It seems that you already played this migration.');
43
8a645662 44 $entryTable->dropIndex('hashed_url_user_id');
9c2b2aae
JB
45 $entryTable->dropColumn('hashed_url');
46 }
47}