-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp: Ignore case when searching for tags
- Loading branch information
1 parent
4faef23
commit b8e5554
Showing
8 changed files
with
100 additions
and
13 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/migrations/Migration202410310002ChangeLinksTagsStorageFormat.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace App\migrations; | ||
|
||
use App\models; | ||
|
||
class Migration202410310002ChangeLinksTagsStorageFormat | ||
{ | ||
public function migrate(): bool | ||
{ | ||
$database = \Minz\Database::get(); | ||
|
||
$statement = $database->query(<<<'SQL' | ||
SELECT l.* FROM links l | ||
WHERE jsonb_typeof(l.tags) = 'array' | ||
AND jsonb_array_length(l.tags) > 0; | ||
SQL); | ||
$db_links = $statement->fetchAll(); | ||
$links = models\Link::fromDatabaseRows($db_links); | ||
|
||
$database->beginTransaction(); | ||
|
||
foreach ($links as $link) { | ||
$tags = $link->tags; | ||
$link->setTags($tags); | ||
$link->save(); | ||
} | ||
|
||
$database->commit(); | ||
|
||
return true; | ||
} | ||
|
||
public function rollback(): bool | ||
{ | ||
$database = \Minz\Database::get(); | ||
|
||
$statement = $database->query(<<<'SQL' | ||
SELECT l.* FROM links l | ||
WHERE jsonb_typeof(l.tags) = 'object'; | ||
SQL); | ||
$db_links = $statement->fetchAll(); | ||
$links = models\Link::fromDatabaseRows($db_links); | ||
|
||
$database->beginTransaction(); | ||
|
||
foreach ($links as $link) { | ||
$link->tags = array_values($link->tags); | ||
$link->save(); | ||
} | ||
|
||
$database->commit(); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters