-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
website/db/migrations/20240525132335_empty_waypoint_to_null.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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
final class EmptyWaypointToNull extends AbstractMigration { | ||
public function up(): void { | ||
$this->execute(<<<'EOL' | ||
CREATE OR REPLACE FUNCTION geokrety.moves_waypoint_uppercase() | ||
RETURNS trigger | ||
LANGUAGE 'plpgsql' | ||
VOLATILE | ||
COST 100 | ||
AS $BODY$ | ||
BEGIN | ||
IF NEW.waypoint = '' THEN | ||
NEW.waypoint = NULL; | ||
END IF; | ||
NEW.waypoint = UPPER(NEW.waypoint); | ||
RETURN NEW; | ||
END; | ||
$BODY$; | ||
EOL); | ||
} | ||
|
||
public function down(): void { | ||
$this->execute(<<<'EOL' | ||
CREATE OR REPLACE FUNCTION geokrety.moves_waypoint_uppercase() | ||
RETURNS trigger | ||
LANGUAGE 'plpgsql' | ||
VOLATILE | ||
COST 100 | ||
AS $BODY$ | ||
BEGIN | ||
NEW.waypoint = UPPER(NEW.waypoint); | ||
RETURN NEW; | ||
END; | ||
$BODY$; | ||
EOL); | ||
} | ||
} |
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