Ergänze individuelle Charakterentwicklung und klare Hochzeitshinweise
Some checks failed
Deploy to production / deploy (push) Failing after 1m18s
Some checks failed
Deploy to production / deploy (push) Failing after 1m18s
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface) {
|
||||
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;
|
||||
|
||||
-- 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()
|
||||
RETURNS trigger LANGUAGE plpgsql AS $$
|
||||
BEGIN
|
||||
IF TG_OP = 'UPDATE' THEN
|
||||
NEW.puberty_start_age := COALESCE(NEW.puberty_start_age, OLD.puberty_start_age);
|
||||
NEW.fertile_from_age := COALESCE(NEW.fertile_from_age, OLD.fertile_from_age);
|
||||
END IF;
|
||||
IF NEW.puberty_start_age IS NULL THEN
|
||||
NEW.puberty_start_age :=
|
||||
CASE WHEN lower(NEW.gender) IN ('female', 'f') THEN 8 ELSE 9 END
|
||||
+ floor((random() + random()) * 3)::int;
|
||||
END IF;
|
||||
IF NEW.fertile_from_age IS NULL THEN
|
||||
NEW.fertile_from_age := NEW.puberty_start_age + 2 + floor(random() * 2)::int;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
);
|
||||
`, { transaction });
|
||||
});
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
await queryInterface.sequelize.transaction(async (transaction) => {
|
||||
await queryInterface.sequelize.query(`
|
||||
DROP TRIGGER initialize_character_development ON falukant_data.character;
|
||||
DROP FUNCTION falukant_data.initialize_character_development();
|
||||
ALTER TABLE falukant_data.character
|
||||
DROP CONSTRAINT character_development_ages_valid,
|
||||
DROP COLUMN puberty_start_age,
|
||||
DROP COLUMN fertile_from_age;
|
||||
`, { transaction });
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user