-
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.
feat: Add support for new GK Types: pebble, car, playing card, dog
- Loading branch information
Showing
10 changed files
with
359 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
final class NewGkTypes extends AbstractMigration { | ||
public function up(): void { | ||
$this->execute(<<<'EOL' | ||
ALTER TABLE IF EXISTS geokrety.gk_geokrety | ||
DROP CONSTRAINT validate_type; | ||
ALTER TABLE IF EXISTS geokrety.gk_geokrety | ||
ADD CONSTRAINT validate_type CHECK (type = ANY (ARRAY[0, 1, 2, 3, 4, 5, 6, 7, 8, 9])); | ||
EOL); | ||
|
||
$this->execute(<<<'EOL' | ||
CREATE FUNCTION geokrety.geokret_manage_type() | ||
RETURNS trigger | ||
LANGUAGE 'plpgsql' | ||
AS $BODY$ | ||
BEGIN | ||
IF NEW.type IN (2, 6, 8) THEN | ||
IF NEW.non_collectible IS NULL THEN | ||
NEW.non_collectible := NOW(); | ||
END IF; | ||
ELSIF OLD.type IN (2, 6, 8) THEN | ||
NEW.non_collectible := NULL; | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$BODY$; | ||
EOL); | ||
|
||
$this->execute(<<<'EOL' | ||
CREATE OR REPLACE TRIGGER before_45_manage_type | ||
BEFORE INSERT OR UPDATE OF type, non_collectible | ||
ON geokrety.gk_geokrety | ||
FOR EACH ROW | ||
EXECUTE FUNCTION geokrety.geokret_manage_type(); | ||
EOL); | ||
} | ||
|
||
public function down(): void { | ||
$this->execute(<<<'EOL' | ||
ALTER TABLE IF EXISTS geokrety.gk_geokrety | ||
DROP CONSTRAINT validate_type; | ||
ALTER TABLE IF EXISTS geokrety.gk_geokrety | ||
ADD CONSTRAINT validate_type CHECK (type = ANY (ARRAY[0, 1, 2, 3, 4])); | ||
EOL); | ||
$this->execute('DROP TRIGGER IF EXISTS before_45_manage_type ON geokrety.gk_geokrety'); | ||
|
||
$this->execute(<<<'EOL' | ||
DROP FUNCTION IF EXISTS geokrety.geokret_manage_type(); | ||
EOL); | ||
} | ||
} |
Oops, something went wrong.