From 9c2b2aae70b06411336e6eb6ac43b3ebd30dc38c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 1 Apr 2019 11:50:33 +0200 Subject: Keep url in exists endpoint - Add migration - Use md5 instead of sha512 (we don't need security here, just a hash) - Update tests --- app/DoctrineMigrations/Version20190401105353.php | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/DoctrineMigrations/Version20190401105353.php (limited to 'app/DoctrineMigrations/Version20190401105353.php') diff --git a/app/DoctrineMigrations/Version20190401105353.php b/app/DoctrineMigrations/Version20190401105353.php new file mode 100644 index 00000000..4afc8b15 --- /dev/null +++ b/app/DoctrineMigrations/Version20190401105353.php @@ -0,0 +1,44 @@ +getTable($this->getTable('entry')); + + $this->skipIf($entryTable->hasColumn('hashed_url'), 'It seems that you already played this migration.'); + + $entryTable->addColumn('hashed_url', 'text', [ + 'length' => 32, + 'notnull' => false, + ]); + + // sqlite doesn't have the MD5 function by default + if ('sqlite' !== $this->connection->getDatabasePlatform()->getName()) { + $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET hashed_url = MD5(url)'); + } + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + $entryTable = $schema->getTable($this->getTable('entry')); + + $this->skipIf(!$entryTable->hasColumn('hashed_url'), 'It seems that you already played this migration.'); + + $entryTable->dropColumn('hashed_url'); + } +} -- cgit v1.2.3 From 8a6456629814039cfc623cdb279bcba06dacff50 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 1 Apr 2019 13:51:57 +0200 Subject: Use a better index for hashed_url It'll most often be used in addition to the `user_id`. Also, automatically generate the hash when saving the url. Switch from `md5` to `sha1`. --- app/DoctrineMigrations/Version20190401105353.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/DoctrineMigrations/Version20190401105353.php') diff --git a/app/DoctrineMigrations/Version20190401105353.php b/app/DoctrineMigrations/Version20190401105353.php index 4afc8b15..c1c22053 100644 --- a/app/DoctrineMigrations/Version20190401105353.php +++ b/app/DoctrineMigrations/Version20190401105353.php @@ -20,7 +20,7 @@ class Version20190401105353 extends WallabagMigration $this->skipIf($entryTable->hasColumn('hashed_url'), 'It seems that you already played this migration.'); $entryTable->addColumn('hashed_url', 'text', [ - 'length' => 32, + 'length' => 40, 'notnull' => false, ]); @@ -28,6 +28,8 @@ class Version20190401105353 extends WallabagMigration if ('sqlite' !== $this->connection->getDatabasePlatform()->getName()) { $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET hashed_url = MD5(url)'); } + + $entryTable->addIndex(['user_id', 'hashed_url'], 'hashed_url_user_id'); } /** @@ -39,6 +41,7 @@ class Version20190401105353 extends WallabagMigration $this->skipIf(!$entryTable->hasColumn('hashed_url'), 'It seems that you already played this migration.'); + $entryTable->dropIndex('hashed_url_user_id'); $entryTable->dropColumn('hashed_url'); } } -- cgit v1.2.3 From c579ce2306297674c56376a2ab5c8ba66a272253 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 1 Apr 2019 14:34:20 +0200 Subject: Some cleanup Also, do not run the hashed_url migration into a Doctrine migration --- app/DoctrineMigrations/Version20190401105353.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'app/DoctrineMigrations/Version20190401105353.php') diff --git a/app/DoctrineMigrations/Version20190401105353.php b/app/DoctrineMigrations/Version20190401105353.php index c1c22053..94ebb1ab 100644 --- a/app/DoctrineMigrations/Version20190401105353.php +++ b/app/DoctrineMigrations/Version20190401105353.php @@ -24,11 +24,6 @@ class Version20190401105353 extends WallabagMigration 'notnull' => false, ]); - // sqlite doesn't have the MD5 function by default - if ('sqlite' !== $this->connection->getDatabasePlatform()->getName()) { - $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET hashed_url = MD5(url)'); - } - $entryTable->addIndex(['user_id', 'hashed_url'], 'hashed_url_user_id'); } -- cgit v1.2.3 From 5cc0646e66f52448f83a7a458e0b60b4580e83e5 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 1 Apr 2019 15:45:17 +0200 Subject: Fix index on MySQL --- app/DoctrineMigrations/Version20190401105353.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/DoctrineMigrations/Version20190401105353.php') diff --git a/app/DoctrineMigrations/Version20190401105353.php b/app/DoctrineMigrations/Version20190401105353.php index 94ebb1ab..d27962db 100644 --- a/app/DoctrineMigrations/Version20190401105353.php +++ b/app/DoctrineMigrations/Version20190401105353.php @@ -24,7 +24,7 @@ class Version20190401105353 extends WallabagMigration 'notnull' => false, ]); - $entryTable->addIndex(['user_id', 'hashed_url'], 'hashed_url_user_id'); + $entryTable->addIndex(['user_id', 'hashed_url'], 'hashed_url_user_id', [], ['lengths' => [null, 40]]); } /** -- cgit v1.2.3