Skip to content

Commit 52741d1

Browse files
chore: Add missing links indexes on fetched columns
1 parent 80494c0 commit 52741d1

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\migrations;
4+
5+
class Migration202511300001AddMissingIndexesOnLinks
6+
{
7+
public function migrate(): bool
8+
{
9+
$database = \Minz\Database::get();
10+
11+
$database->exec(<<<'SQL'
12+
CREATE INDEX idx_links_fetched_at ON links(fetched_at) WHERE fetched_at IS NULL;
13+
CREATE INDEX idx_links_fetched_retry_at ON links(fetched_retry_at) WHERE fetched_retry_at IS NOT NULL;
14+
SQL);
15+
16+
return true;
17+
}
18+
19+
public function rollback(): bool
20+
{
21+
$database = \Minz\Database::get();
22+
23+
$database->exec(<<<'SQL'
24+
DROP INDEX idx_links_fetched_at;
25+
DROP INDEX idx_links_fetched_retry_at;
26+
SQL);
27+
28+
return true;
29+
}
30+
}

src/schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ CREATE INDEX idx_links_user_id_url_hash ON links USING btree(user_id, url_hash);
182182
CREATE INDEX idx_links_url_hash ON links USING hash(url_hash);
183183
CREATE INDEX idx_links_url ON links USING gin (url gin_trgm_ops);
184184
CREATE INDEX idx_links_to_be_fetched ON links(to_be_fetched) WHERE to_be_fetched = true;
185+
CREATE INDEX idx_links_fetched_at ON links(fetched_at) WHERE fetched_at IS NULL;
185186
CREATE INDEX idx_links_fetched_retry_at ON links(fetched_retry_at) WHERE fetched_retry_at IS NOT NULL;
186187
CREATE INDEX idx_links_image_filename ON links(image_filename) WHERE image_filename IS NOT NULL;
187188
CREATE INDEX idx_links_search ON links USING GIN (search_index);

0 commit comments

Comments
 (0)