]> git.immae.eu Git - github/wallabag/wallabag.git/blob - app/DoctrineMigrations/Version20190601125843.php
Use hash given url to avoid duplicate
[github/wallabag/wallabag.git] / app / DoctrineMigrations / Version20190601125843.php
1 <?php
2
3 namespace Application\Migrations;
4
5 use Doctrine\DBAL\Schema\Schema;
6 use Wallabag\CoreBundle\Doctrine\WallabagMigration;
7
8 /**
9 * Added `given_url` & `hashed_given_url` field in entry table.
10 */
11 class Version20190601125843 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 if (!$entryTable->hasColumn('given_url')) {
21 $entryTable->addColumn('given_url', 'text', [
22 'notnull' => false,
23 ]);
24 }
25
26 if (!$entryTable->hasColumn('hashed_given_url')) {
27 $entryTable->addColumn('hashed_given_url', 'text', [
28 'length' => 40,
29 'notnull' => false,
30 ]);
31 }
32
33 $entryTable->dropIndex('hashed_url_user_id');
34 $entryTable->addIndex(
35 [
36 'user_id',
37 'hashed_url',
38 'hashed_given_url',
39 ],
40 'hashed_urls_user_id',
41 [],
42 [
43 // specify length for index which is required by MySQL on text field
44 'lengths' => [
45 // user_id
46 null,
47 // hashed_url
48 40,
49 // hashed_given_url
50 40,
51 ],
52 ]
53 );
54 }
55
56 /**
57 * @param Schema $schema
58 */
59 public function down(Schema $schema)
60 {
61 $entryTable = $schema->getTable($this->getTable('entry'));
62
63 if ($entryTable->hasColumn('given_url')) {
64 $entryTable->dropColumn('given_url');
65 }
66
67 if ($entryTable->hasColumn('hashed_given_url')) {
68 $entryTable->dropColumn('hashed_given_url');
69 }
70
71 $entryTable->dropIndex('hashed_urls_user_id');
72 $entryTable->addIndex(['user_id', 'hashed_url'], 'hashed_url_user_id', [], ['lengths' => [null, 40]]);
73 }
74 }