Mache Charakterentwicklungsmigration wiederholbar
All checks were successful
Deploy to production / deploy (push) Successful in 2m26s
All checks were successful
Deploy to production / deploy (push) Successful in 2m26s
This commit is contained in:
@@ -5,13 +5,13 @@ module.exports = {
|
||||
await queryInterface.sequelize.transaction(async (transaction) => {
|
||||
await queryInterface.sequelize.query(`
|
||||
ALTER TABLE falukant_data.character
|
||||
ADD COLUMN puberty_start_age SMALLINT,
|
||||
ADD COLUMN fertile_from_age SMALLINT;
|
||||
ADD COLUMN IF NOT EXISTS puberty_start_age SMALLINT,
|
||||
ADD COLUMN IF NOT EXISTS fertile_from_age SMALLINT;
|
||||
|
||||
-- Shared by Sequelize and raw daemon INSERTs, including newborns and NPCs.
|
||||
-- One real calendar day is one game year. These are game distributions,
|
||||
-- not medical predictions or reconstructed medieval population data.
|
||||
CREATE FUNCTION falukant_data.initialize_character_development()
|
||||
CREATE OR REPLACE FUNCTION falukant_data.initialize_character_development()
|
||||
RETURNS trigger LANGUAGE plpgsql AS $$
|
||||
BEGIN
|
||||
IF TG_OP = 'UPDATE' THEN
|
||||
@@ -30,21 +30,35 @@ module.exports = {
|
||||
END;
|
||||
$$;
|
||||
|
||||
DROP TRIGGER IF EXISTS initialize_character_development ON falukant_data.character;
|
||||
CREATE TRIGGER initialize_character_development
|
||||
BEFORE INSERT OR UPDATE ON falukant_data.character
|
||||
FOR EACH ROW EXECUTE FUNCTION falukant_data.initialize_character_development();
|
||||
|
||||
-- Existing pregnancies and relationships are deliberately untouched.
|
||||
UPDATE falukant_data.character SET puberty_start_age = puberty_start_age;
|
||||
UPDATE falukant_data.character SET puberty_start_age = puberty_start_age
|
||||
WHERE puberty_start_age IS NULL OR fertile_from_age IS NULL;
|
||||
|
||||
ALTER TABLE falukant_data.character
|
||||
ALTER COLUMN puberty_start_age SET NOT NULL,
|
||||
ALTER COLUMN fertile_from_age SET NOT NULL,
|
||||
ADD CONSTRAINT character_development_ages_valid CHECK (
|
||||
puberty_start_age BETWEEN 8 AND 18
|
||||
AND fertile_from_age > puberty_start_age
|
||||
AND fertile_from_age <= 21
|
||||
);
|
||||
ALTER COLUMN fertile_from_age SET NOT NULL;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint
|
||||
WHERE conrelid = 'falukant_data.character'::regclass
|
||||
AND conname = 'character_development_ages_valid'
|
||||
) THEN
|
||||
ALTER TABLE falukant_data.character
|
||||
ADD CONSTRAINT character_development_ages_valid CHECK (
|
||||
puberty_start_age BETWEEN 8 AND 18
|
||||
AND fertile_from_age > puberty_start_age
|
||||
AND fertile_from_age <= 21
|
||||
);
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
`, { transaction });
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user