aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/DoctrineMigrations/Version20190601125843.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2019-05-29 14:18:04 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2019-05-29 15:56:20 +0200
commitf3bfb875e94021a93e24a41fbc0f8d86d4dee378 (patch)
tree34f7efd0f3dc5326f68364e2fb2544619518c371 /app/DoctrineMigrations/Version20190601125843.php
parentb7fa51ae7dd5fef2d9459100c88479413ddd3fb3 (diff)
downloadwallabag-f3bfb875e94021a93e24a41fbc0f8d86d4dee378.tar.gz
wallabag-f3bfb875e94021a93e24a41fbc0f8d86d4dee378.tar.zst
wallabag-f3bfb875e94021a93e24a41fbc0f8d86d4dee378.zip
Use hash given url to avoid duplicate
Using hashed url we can ensure an index on them to ensure it's fast.
Diffstat (limited to 'app/DoctrineMigrations/Version20190601125843.php')
-rw-r--r--app/DoctrineMigrations/Version20190601125843.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/app/DoctrineMigrations/Version20190601125843.php b/app/DoctrineMigrations/Version20190601125843.php
new file mode 100644
index 00000000..341d64dc
--- /dev/null
+++ b/app/DoctrineMigrations/Version20190601125843.php
@@ -0,0 +1,74 @@
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Schema\Schema;
6use Wallabag\CoreBundle\Doctrine\WallabagMigration;
7
8/**
9 * Added `given_url` & `hashed_given_url` field in entry table.
10 */
11class 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}