diff --git a/database/main/attribute.sql b/database/main/attribute.sql new file mode 100644 index 0000000..0f57ba5 --- /dev/null +++ b/database/main/attribute.sql @@ -0,0 +1,9 @@ +create table attribute +( + id INTEGER + primary key, + code TEXT + unique, + name TEXT +); + diff --git a/database/main/book.sql b/database/main/book.sql new file mode 100644 index 0000000..46f79aa --- /dev/null +++ b/database/main/book.sql @@ -0,0 +1,20 @@ +create table book +( + id INTEGER + primary key, + code TEXT not null + unique, + title TEXT not null, + subtitle TEXT, + series TEXT, + volume TEXT, + edition TEXT, + isbn13 TEXT + unique, + publisher TEXT, + language TEXT, + published_at TEXT, + url TEXT, + license TEXT +); + diff --git a/database/main/citation.sql b/database/main/citation.sql new file mode 100644 index 0000000..bde3989 --- /dev/null +++ b/database/main/citation.sql @@ -0,0 +1,17 @@ +create table citation +( + id INTEGER + primary key, + book_id INTEGER not null + references book + on delete cascade, + page_start INTEGER not null, + page_end INTEGER, + section TEXT, + anchor TEXT, + note TEXT +); + +create index idx_citation_book + on citation (book_id, page_start); + diff --git a/database/main/culture.sql b/database/main/culture.sql new file mode 100644 index 0000000..aed6ada --- /dev/null +++ b/database/main/culture.sql @@ -0,0 +1,12 @@ +create table culture +( + id INTEGER + primary key, + optolith_key TEXT not null + unique, + name TEXT not null +); + +create index idx_culture_name + on culture (name); + diff --git a/database/main/culture_citation.sql b/database/main/culture_citation.sql new file mode 100644 index 0000000..1eb7fb8 --- /dev/null +++ b/database/main/culture_citation.sql @@ -0,0 +1,14 @@ +create table culture_citation +( + culture_id INTEGER not null + references culture + on delete cascade, + citation_id INTEGER not null + references citation + on delete cascade, + primary key (culture_id, citation_id) +); + +create index idx_culture_citation_cit + on culture_citation (citation_id); + diff --git a/database/main/culture_language.sql b/database/main/culture_language.sql new file mode 100644 index 0000000..49d8241 --- /dev/null +++ b/database/main/culture_language.sql @@ -0,0 +1,15 @@ +create table culture_language +( + culture_id INTEGER not null + references culture + on delete cascade, + language_id INTEGER not null + references language + on delete restrict, + level TEXT, + primary key (culture_id, language_id) +); + +create index idx_culture_language_lang + on culture_language (language_id); + diff --git a/database/main/culture_profession.sql b/database/main/culture_profession.sql new file mode 100644 index 0000000..0700b07 --- /dev/null +++ b/database/main/culture_profession.sql @@ -0,0 +1,14 @@ +create table culture_profession +( + culture_id INTEGER not null + references culture + on delete cascade, + profession_id INTEGER not null + references profession + on delete restrict, + primary key (culture_id, profession_id) +); + +create index idx_culture_profession_prof + on culture_profession (profession_id); + diff --git a/database/main/culture_script.sql b/database/main/culture_script.sql new file mode 100644 index 0000000..b764783 --- /dev/null +++ b/database/main/culture_script.sql @@ -0,0 +1,14 @@ +create table culture_script +( + culture_id INTEGER not null + references culture + on delete cascade, + script_id INTEGER not null + references script + on delete restrict, + primary key (culture_id, script_id) +); + +create index idx_culture_script_script + on culture_script (script_id); + diff --git a/database/main/culture_trait.sql b/database/main/culture_trait.sql new file mode 100644 index 0000000..63e4df8 --- /dev/null +++ b/database/main/culture_trait.sql @@ -0,0 +1,21 @@ +create table culture_trait +( + culture_id INTEGER not null + references culture + on delete cascade, + trait_id INTEGER not null + references trait + on delete restrict, + tag TEXT not null, + level INTEGER, + param_value TEXT, + primary key (culture_id, trait_id, tag), + check (tag IN ('TYPISCH', 'EMPFOHLEN')) +); + +create index idx_culture_trait_trait + on culture_trait (trait_id); + +create index idx_culture_trait_trait2 + on culture_trait (trait_id); + diff --git a/database/main/exclusive_group.sql b/database/main/exclusive_group.sql new file mode 100644 index 0000000..39c32d8 --- /dev/null +++ b/database/main/exclusive_group.sql @@ -0,0 +1,9 @@ +create table exclusive_group +( + id INTEGER + primary key, + name TEXT not null, + scope TEXT not null, + check (scope IN ('TRAIT', 'SF', 'TALENT', 'SPELL', 'LITURGY')) +); + diff --git a/database/main/exclusive_group_member.sql b/database/main/exclusive_group_member.sql new file mode 100644 index 0000000..7841df3 --- /dev/null +++ b/database/main/exclusive_group_member.sql @@ -0,0 +1,9 @@ +create table exclusive_group_member +( + group_id INTEGER not null + references exclusive_group + on delete cascade, + owner_id INTEGER not null, + primary key (group_id, owner_id) +); + diff --git a/database/main/kampftechnik.sql b/database/main/kampftechnik.sql new file mode 100644 index 0000000..96b52dd --- /dev/null +++ b/database/main/kampftechnik.sql @@ -0,0 +1,17 @@ +create table kampftechnik +( + id INTEGER + primary key, + optolith_key TEXT not null + unique, + name TEXT not null, + grundwert INTEGER default 6 not null, + probe_attr1_id INTEGER + references attribute, + probe_attr2_id INTEGER + references attribute, + probe_attr3_id INTEGER + references attribute, + beschreibung TEXT +); + diff --git a/database/main/language.sql b/database/main/language.sql new file mode 100644 index 0000000..fa9d674 --- /dev/null +++ b/database/main/language.sql @@ -0,0 +1,10 @@ +create table language +( + id INTEGER + primary key, + code TEXT + unique, + name TEXT not null + unique +); + diff --git a/database/main/liturgy.sql b/database/main/liturgy.sql new file mode 100644 index 0000000..079d9b1 --- /dev/null +++ b/database/main/liturgy.sql @@ -0,0 +1,22 @@ +create table liturgy +( + id INTEGER + primary key, + optolith_key TEXT not null + unique, + name TEXT not null, + probe_attr1_id INTEGER not null + references attribute, + probe_attr2_id INTEGER not null + references attribute, + probe_attr3_id INTEGER not null + references attribute, + wirkung TEXT, + dauer TEXT, + kap_kosten TEXT, + reichweite TEXT, + wirkungsdauer TEXT, + steig_faktor TEXT not null, + check (steig_faktor IN ('A', 'B', 'C', 'D')) +); + diff --git a/database/main/liturgy_citation.sql b/database/main/liturgy_citation.sql new file mode 100644 index 0000000..da6a772 --- /dev/null +++ b/database/main/liturgy_citation.sql @@ -0,0 +1,14 @@ +create table liturgy_citation +( + liturgy_id INTEGER not null + references liturgy + on delete cascade, + citation_id INTEGER not null + references citation + on delete cascade, + primary key (liturgy_id, citation_id) +); + +create index idx_liturgy_citation_cit + on liturgy_citation (citation_id); + diff --git a/database/main/liturgy_tradition.sql b/database/main/liturgy_tradition.sql new file mode 100644 index 0000000..04bb411 --- /dev/null +++ b/database/main/liturgy_tradition.sql @@ -0,0 +1,14 @@ +create table liturgy_tradition +( + liturgy_id INTEGER not null + references liturgy + on delete cascade, + tradition_id INTEGER not null + references tradition + on delete restrict, + primary key (liturgy_id, tradition_id) +); + +create index idx_liturgy_tradition_t + on liturgy_tradition (tradition_id); + diff --git a/database/main/liturgy_zielkategorie.sql b/database/main/liturgy_zielkategorie.sql new file mode 100644 index 0000000..1d02acf --- /dev/null +++ b/database/main/liturgy_zielkategorie.sql @@ -0,0 +1,14 @@ +create table liturgy_zielkategorie +( + liturgy_id INTEGER not null + references liturgy + on delete cascade, + zielkategorie_id INTEGER not null + references zielkategorie + on delete restrict, + primary key (liturgy_id, zielkategorie_id) +); + +create index idx_liturgy_zielkat_z + on liturgy_zielkategorie (zielkategorie_id); + diff --git a/database/main/merkmal.sql b/database/main/merkmal.sql new file mode 100644 index 0000000..3c0adf7 --- /dev/null +++ b/database/main/merkmal.sql @@ -0,0 +1,8 @@ +create table merkmal +( + id INTEGER + primary key, + name TEXT not null + unique +); + diff --git a/database/main/profession.sql b/database/main/profession.sql new file mode 100644 index 0000000..b7a75ee --- /dev/null +++ b/database/main/profession.sql @@ -0,0 +1,14 @@ +create table profession +( + id INTEGER + primary key, + optolith_key TEXT not null + unique, + name TEXT not null, + typ TEXT, + beschreibung TEXT +); + +create index idx_profession_name + on profession (name); + diff --git a/database/main/profession_citation.sql b/database/main/profession_citation.sql new file mode 100644 index 0000000..9c3a266 --- /dev/null +++ b/database/main/profession_citation.sql @@ -0,0 +1,14 @@ +create table profession_citation +( + profession_id INTEGER not null + references profession + on delete cascade, + citation_id INTEGER not null + references citation + on delete cascade, + primary key (profession_id, citation_id) +); + +create index idx_profession_citation_cit + on profession_citation (citation_id); + diff --git a/database/main/profession_special_ability.sql b/database/main/profession_special_ability.sql new file mode 100644 index 0000000..f509a17 --- /dev/null +++ b/database/main/profession_special_ability.sql @@ -0,0 +1,14 @@ +create table profession_special_ability +( + profession_id INTEGER not null + references profession + on delete cascade, + special_ability_id INTEGER not null + references special_ability + on delete restrict, + primary key (profession_id, special_ability_id) +); + +create index idx_profession_sa_sa + on profession_special_ability (special_ability_id); + diff --git a/database/main/profession_trait.sql b/database/main/profession_trait.sql new file mode 100644 index 0000000..90f7f78 --- /dev/null +++ b/database/main/profession_trait.sql @@ -0,0 +1,19 @@ +create table profession_trait +( + profession_id INTEGER not null + references profession + on delete cascade, + trait_id INTEGER not null + references trait + on delete restrict, + level INTEGER, + param_value TEXT, + primary key (profession_id, trait_id) +); + +create index idx_profession_trait_trait + on profession_trait (trait_id); + +create index idx_profession_trait_trait2 + on profession_trait (trait_id); + diff --git a/database/main/requirement.sql b/database/main/requirement.sql new file mode 100644 index 0000000..bc2f676 --- /dev/null +++ b/database/main/requirement.sql @@ -0,0 +1,31 @@ +create table requirement +( + id INTEGER + primary key, + owner_kind TEXT not null, + owner_id INTEGER not null, + group_no INTEGER default 1 not null, + negate INTEGER default 0 not null, + req_type TEXT not null, + req_id INTEGER, + req_level INTEGER, + req_optokey TEXT, + note TEXT, + check (negate IN (0, 1)), + check (owner_kind IN ( + 'TRAIT', 'SF', 'TALENT', 'SPELL', 'LITURGY', 'PROFESSION', 'SPECIES', 'CULTURE' + )), + check (req_type IN ( + 'TRAIT', 'TRAIT_LEVEL_MIN', + 'ATTR_MIN', 'TALENT_MIN', 'SF', + 'SPECIES', 'CULTURE', 'TRADITION', 'MERKMAL', + 'EXCLUSIVE_GROUP' + )) +); + +create index idx_requirement_owner + on requirement (owner_kind, owner_id, group_no); + +create index idx_requirement_ref + on requirement (req_type, req_id); + diff --git a/database/main/sa_type.sql b/database/main/sa_type.sql new file mode 100644 index 0000000..be64a6f --- /dev/null +++ b/database/main/sa_type.sql @@ -0,0 +1,7 @@ +create table sa_type +( + code TEXT + primary key, + name TEXT not null +); + diff --git a/database/main/script.sql b/database/main/script.sql new file mode 100644 index 0000000..9245f5a --- /dev/null +++ b/database/main/script.sql @@ -0,0 +1,10 @@ +create table script +( + id INTEGER + primary key, + code TEXT + unique, + name TEXT not null + unique +); + diff --git a/database/main/special_ability.sql b/database/main/special_ability.sql new file mode 100644 index 0000000..24f7222 --- /dev/null +++ b/database/main/special_ability.sql @@ -0,0 +1,14 @@ +create table special_ability +( + id INTEGER + primary key, + optolith_key TEXT not null + unique, + name TEXT not null, + type_code TEXT + references sa_type + on update cascade, + ap_kosten INTEGER, + beschreibung TEXT +); + diff --git a/database/main/special_ability_citation.sql b/database/main/special_ability_citation.sql new file mode 100644 index 0000000..3db6857 --- /dev/null +++ b/database/main/special_ability_citation.sql @@ -0,0 +1,14 @@ +create table special_ability_citation +( + special_ability_id INTEGER not null + references special_ability + on delete cascade, + citation_id INTEGER not null + references citation + on delete cascade, + primary key (special_ability_id, citation_id) +); + +create index idx_special_ability_citation_cit + on special_ability_citation (citation_id); + diff --git a/database/main/species.sql b/database/main/species.sql new file mode 100644 index 0000000..9d3f6e9 --- /dev/null +++ b/database/main/species.sql @@ -0,0 +1,17 @@ +create table species +( + id INTEGER + primary key, + optolith_key TEXT not null + unique, + name TEXT not null, + ap_kosten INTEGER, + le_grund INTEGER, + sk_grund INTEGER, + zk_grund INTEGER, + gs_grund INTEGER +); + +create index idx_species_name + on species (name); + diff --git a/database/main/species_attribute_mod.sql b/database/main/species_attribute_mod.sql new file mode 100644 index 0000000..50c8944 --- /dev/null +++ b/database/main/species_attribute_mod.sql @@ -0,0 +1,15 @@ +create table species_attribute_mod +( + species_id INTEGER not null + references species + on delete cascade, + attribute_id INTEGER not null + references attribute + on delete restrict, + delta INTEGER not null, + primary key (species_id, attribute_id) +); + +create index idx_species_attrmod_attr + on species_attribute_mod (attribute_id); + diff --git a/database/main/species_citation.sql b/database/main/species_citation.sql new file mode 100644 index 0000000..89e854a --- /dev/null +++ b/database/main/species_citation.sql @@ -0,0 +1,14 @@ +create table species_citation +( + species_id INTEGER not null + references species + on delete cascade, + citation_id INTEGER not null + references citation + on delete cascade, + primary key (species_id, citation_id) +); + +create index idx_species_citation_cit + on species_citation (citation_id); + diff --git a/database/main/species_trait.sql b/database/main/species_trait.sql new file mode 100644 index 0000000..e733083 --- /dev/null +++ b/database/main/species_trait.sql @@ -0,0 +1,21 @@ +create table species_trait +( + species_id INTEGER not null + references species + on delete cascade, + trait_id INTEGER not null + references trait + on delete restrict, + source TEXT not null, + level INTEGER, + param_value TEXT, + primary key (species_id, trait_id, source), + check (source IN ('AUTOMATISCH', 'TYPISCH', 'EMPFOHLEN')) +); + +create index idx_species_trait_trait + on species_trait (trait_id); + +create index idx_species_trait_trait2 + on species_trait (trait_id); + diff --git a/database/main/spell.sql b/database/main/spell.sql new file mode 100644 index 0000000..dcff04a --- /dev/null +++ b/database/main/spell.sql @@ -0,0 +1,22 @@ +create table spell +( + id INTEGER + primary key, + optolith_key TEXT not null + unique, + name TEXT not null, + probe_attr1_id INTEGER not null + references attribute, + probe_attr2_id INTEGER not null + references attribute, + probe_attr3_id INTEGER not null + references attribute, + wirkung TEXT, + zauberdauer TEXT, + asp_kosten TEXT, + reichweite TEXT, + wirkungsdauer TEXT, + steig_faktor TEXT not null, + check (steig_faktor IN ('A', 'B', 'C', 'D')) +); + diff --git a/database/main/spell_citation.sql b/database/main/spell_citation.sql new file mode 100644 index 0000000..74ad038 --- /dev/null +++ b/database/main/spell_citation.sql @@ -0,0 +1,14 @@ +create table spell_citation +( + spell_id INTEGER not null + references spell + on delete cascade, + citation_id INTEGER not null + references citation + on delete cascade, + primary key (spell_id, citation_id) +); + +create index idx_spell_citation_cit + on spell_citation (citation_id); + diff --git a/database/main/spell_merkmal.sql b/database/main/spell_merkmal.sql new file mode 100644 index 0000000..79eb6de --- /dev/null +++ b/database/main/spell_merkmal.sql @@ -0,0 +1,14 @@ +create table spell_merkmal +( + spell_id INTEGER not null + references spell + on delete cascade, + merkmal_id INTEGER not null + references merkmal + on delete restrict, + primary key (spell_id, merkmal_id) +); + +create index idx_spell_merkmal_m + on spell_merkmal (merkmal_id); + diff --git a/database/main/spell_tradition.sql b/database/main/spell_tradition.sql new file mode 100644 index 0000000..e867ea7 --- /dev/null +++ b/database/main/spell_tradition.sql @@ -0,0 +1,14 @@ +create table spell_tradition +( + spell_id INTEGER not null + references spell + on delete cascade, + tradition_id INTEGER not null + references tradition + on delete restrict, + primary key (spell_id, tradition_id) +); + +create index idx_spell_tradition_t + on spell_tradition (tradition_id); + diff --git a/database/main/spell_zielkategorie.sql b/database/main/spell_zielkategorie.sql new file mode 100644 index 0000000..5b98038 --- /dev/null +++ b/database/main/spell_zielkategorie.sql @@ -0,0 +1,14 @@ +create table spell_zielkategorie +( + spell_id INTEGER not null + references spell + on delete cascade, + zielkategorie_id INTEGER not null + references zielkategorie + on delete restrict, + primary key (spell_id, zielkategorie_id) +); + +create index idx_spell_zielkat_z + on spell_zielkategorie (zielkategorie_id); + diff --git a/database/main/talent.sql b/database/main/talent.sql new file mode 100644 index 0000000..dca637b --- /dev/null +++ b/database/main/talent.sql @@ -0,0 +1,24 @@ +create table talent +( + id INTEGER + primary key, + optolith_key TEXT not null + unique, + name TEXT not null, + group_code TEXT + references talent_group + on update cascade, + probe_attr1_id INTEGER not null + references attribute, + probe_attr2_id INTEGER not null + references attribute, + probe_attr3_id INTEGER not null + references attribute, + steig_faktor TEXT not null, + beschreibung TEXT, + check (steig_faktor IN ('A', 'B', 'C', 'D')) +); + +create index idx_talent_group + on talent (group_code); + diff --git a/database/main/talent_citation.sql b/database/main/talent_citation.sql new file mode 100644 index 0000000..6c0e7ab --- /dev/null +++ b/database/main/talent_citation.sql @@ -0,0 +1,14 @@ +create table talent_citation +( + talent_id INTEGER not null + references talent + on delete cascade, + citation_id INTEGER not null + references citation + on delete cascade, + primary key (talent_id, citation_id) +); + +create index idx_talent_citation_cit + on talent_citation (citation_id); + diff --git a/database/main/talent_group.sql b/database/main/talent_group.sql new file mode 100644 index 0000000..2018b56 --- /dev/null +++ b/database/main/talent_group.sql @@ -0,0 +1,7 @@ +create table talent_group +( + code TEXT + primary key, + name TEXT not null +); + diff --git a/database/main/tradition.sql b/database/main/tradition.sql new file mode 100644 index 0000000..05b3129 --- /dev/null +++ b/database/main/tradition.sql @@ -0,0 +1,8 @@ +create table tradition +( + id INTEGER + primary key, + name TEXT not null + unique +); + diff --git a/database/main/trait.sql b/database/main/trait.sql new file mode 100644 index 0000000..5e5a538 --- /dev/null +++ b/database/main/trait.sql @@ -0,0 +1,25 @@ +create table trait +( + id INTEGER + primary key, + optolith_key TEXT not null + unique, + name TEXT not null, + kind TEXT not null, + is_leveled INTEGER default 0 not null, + level_min INTEGER, + level_max INTEGER, + level_step INTEGER, + ap_cost_mode TEXT default 'FIXED' not null, + ap_wert INTEGER, + ap_per_level INTEGER, + ap_formula TEXT, + beschreibung TEXT, + check (ap_cost_mode IN ('FIXED', 'PER_LEVEL', 'TABLE', 'FORMULA')), + check (is_leveled IN (0, 1)), + check (kind IN ('VORTEIL', 'NACHTEIL')) +); + +create index idx_trait_kind + on trait (kind); + diff --git a/database/main/trait_citation.sql b/database/main/trait_citation.sql new file mode 100644 index 0000000..d78de40 --- /dev/null +++ b/database/main/trait_citation.sql @@ -0,0 +1,14 @@ +create table trait_citation +( + trait_id INTEGER not null + references trait + on delete cascade, + citation_id INTEGER not null + references citation + on delete cascade, + primary key (trait_id, citation_id) +); + +create index idx_trait_citation_cit + on trait_citation (citation_id); + diff --git a/database/main/trait_conflict.sql b/database/main/trait_conflict.sql new file mode 100644 index 0000000..e5e925d --- /dev/null +++ b/database/main/trait_conflict.sql @@ -0,0 +1,11 @@ +create table trait_conflict +( + trait_id INTEGER not null + references trait + on delete cascade, + incompatible_trait_id INTEGER not null + references trait + on delete cascade, + primary key (trait_id, incompatible_trait_id) +); + diff --git a/database/main/trait_level.sql b/database/main/trait_level.sql new file mode 100644 index 0000000..0f12916 --- /dev/null +++ b/database/main/trait_level.sql @@ -0,0 +1,12 @@ +create table trait_level +( + trait_id INTEGER not null + references trait + on delete cascade, + level INTEGER not null, + ap_cost INTEGER, + label TEXT, + note TEXT, + primary key (trait_id, level) +); + diff --git a/database/main/trg_requirement_check_attr_insert.sql b/database/main/trg_requirement_check_attr_insert.sql new file mode 100644 index 0000000..bf03f5e --- /dev/null +++ b/database/main/trg_requirement_check_attr_insert.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_attr_insert +BEFORE INSERT ON requirement +WHEN NEW.req_type = 'ATTR_MIN' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM attribute WHERE id = NEW.req_id) + THEN RAISE(ABORT, 'requirement.req_id must reference attribute.id for ATTR_MIN') + END; +END; + diff --git a/database/main/trg_requirement_check_attr_update.sql b/database/main/trg_requirement_check_attr_update.sql new file mode 100644 index 0000000..f053eda --- /dev/null +++ b/database/main/trg_requirement_check_attr_update.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_attr_update +BEFORE UPDATE ON requirement +WHEN NEW.req_type = 'ATTR_MIN' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM attribute WHERE id = NEW.req_id) + THEN RAISE(ABORT, 'requirement.req_id must reference attribute.id for ATTR_MIN (UPDATE)') + END; +END; + diff --git a/database/main/trg_requirement_check_culture_insert.sql b/database/main/trg_requirement_check_culture_insert.sql new file mode 100644 index 0000000..120cbe4 --- /dev/null +++ b/database/main/trg_requirement_check_culture_insert.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_culture_insert +BEFORE INSERT ON requirement +WHEN NEW.req_type='CULTURE' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM culture WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference culture.id for CULTURE') + END; +END; + diff --git a/database/main/trg_requirement_check_culture_update.sql b/database/main/trg_requirement_check_culture_update.sql new file mode 100644 index 0000000..e34aa99 --- /dev/null +++ b/database/main/trg_requirement_check_culture_update.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_culture_update +BEFORE UPDATE ON requirement +WHEN NEW.req_type='CULTURE' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM culture WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference culture.id for CULTURE (UPDATE)') + END; +END; + diff --git a/database/main/trg_requirement_check_exclgrp_insert.sql b/database/main/trg_requirement_check_exclgrp_insert.sql new file mode 100644 index 0000000..bb85e07 --- /dev/null +++ b/database/main/trg_requirement_check_exclgrp_insert.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_exclgrp_insert +BEFORE INSERT ON requirement +WHEN NEW.req_type='EXCLUSIVE_GROUP' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM exclusive_group WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference exclusive_group.id for EXCLUSIVE_GROUP') + END; +END; + diff --git a/database/main/trg_requirement_check_exclgrp_update.sql b/database/main/trg_requirement_check_exclgrp_update.sql new file mode 100644 index 0000000..a822f07 --- /dev/null +++ b/database/main/trg_requirement_check_exclgrp_update.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_exclgrp_update +BEFORE UPDATE ON requirement +WHEN NEW.req_type='EXCLUSIVE_GROUP' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM exclusive_group WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference exclusive_group.id for EXCLUSIVE_GROUP (UPDATE)') + END; +END; + diff --git a/database/main/trg_requirement_check_merk_insert.sql b/database/main/trg_requirement_check_merk_insert.sql new file mode 100644 index 0000000..2a21797 --- /dev/null +++ b/database/main/trg_requirement_check_merk_insert.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_merk_insert +BEFORE INSERT ON requirement +WHEN NEW.req_type='MERKMAL' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM merkmal WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference merkmal.id for MERKMAL') + END; +END; + diff --git a/database/main/trg_requirement_check_merk_update.sql b/database/main/trg_requirement_check_merk_update.sql new file mode 100644 index 0000000..cf017ea --- /dev/null +++ b/database/main/trg_requirement_check_merk_update.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_merk_update +BEFORE UPDATE ON requirement +WHEN NEW.req_type='MERKMAL' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM merkmal WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference merkmal.id for MERKMAL (UPDATE)') + END; +END; + diff --git a/database/main/trg_requirement_check_sf_insert.sql b/database/main/trg_requirement_check_sf_insert.sql new file mode 100644 index 0000000..ce3f059 --- /dev/null +++ b/database/main/trg_requirement_check_sf_insert.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_sf_insert +BEFORE INSERT ON requirement +WHEN NEW.req_type='SF' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM special_ability WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference special_ability.id for SF') + END; +END; + diff --git a/database/main/trg_requirement_check_sf_update.sql b/database/main/trg_requirement_check_sf_update.sql new file mode 100644 index 0000000..bc90bca --- /dev/null +++ b/database/main/trg_requirement_check_sf_update.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_sf_update +BEFORE UPDATE ON requirement +WHEN NEW.req_type='SF' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM special_ability WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference special_ability.id for SF (UPDATE)') + END; +END; + diff --git a/database/main/trg_requirement_check_species_insert.sql b/database/main/trg_requirement_check_species_insert.sql new file mode 100644 index 0000000..637e58e --- /dev/null +++ b/database/main/trg_requirement_check_species_insert.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_species_insert +BEFORE INSERT ON requirement +WHEN NEW.req_type='SPECIES' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM species WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference species.id for SPECIES') + END; +END; + diff --git a/database/main/trg_requirement_check_species_update.sql b/database/main/trg_requirement_check_species_update.sql new file mode 100644 index 0000000..71dba68 --- /dev/null +++ b/database/main/trg_requirement_check_species_update.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_species_update +BEFORE UPDATE ON requirement +WHEN NEW.req_type='SPECIES' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM species WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference species.id for SPECIES (UPDATE)') + END; +END; + diff --git a/database/main/trg_requirement_check_talent_insert.sql b/database/main/trg_requirement_check_talent_insert.sql new file mode 100644 index 0000000..e4b5636 --- /dev/null +++ b/database/main/trg_requirement_check_talent_insert.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_talent_insert +BEFORE INSERT ON requirement +WHEN NEW.req_type='TALENT_MIN' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM talent WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference talent.id for TALENT_MIN') + END; +END; + diff --git a/database/main/trg_requirement_check_talent_update.sql b/database/main/trg_requirement_check_talent_update.sql new file mode 100644 index 0000000..0b939e4 --- /dev/null +++ b/database/main/trg_requirement_check_talent_update.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_talent_update +BEFORE UPDATE ON requirement +WHEN NEW.req_type='TALENT_MIN' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM talent WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference talent.id for TALENT_MIN (UPDATE)') + END; +END; + diff --git a/database/main/trg_requirement_check_trad_insert.sql b/database/main/trg_requirement_check_trad_insert.sql new file mode 100644 index 0000000..f54a8f7 --- /dev/null +++ b/database/main/trg_requirement_check_trad_insert.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_trad_insert +BEFORE INSERT ON requirement +WHEN NEW.req_type='TRADITION' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM tradition WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference tradition.id for TRADITION') + END; +END; + diff --git a/database/main/trg_requirement_check_trad_update.sql b/database/main/trg_requirement_check_trad_update.sql new file mode 100644 index 0000000..0c4ef84 --- /dev/null +++ b/database/main/trg_requirement_check_trad_update.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_trad_update +BEFORE UPDATE ON requirement +WHEN NEW.req_type='TRADITION' +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM tradition WHERE id=NEW.req_id) + THEN RAISE(ABORT,'requirement.req_id must reference tradition.id for TRADITION (UPDATE)') + END; +END; + diff --git a/database/main/trg_requirement_check_trait_insert.sql b/database/main/trg_requirement_check_trait_insert.sql new file mode 100644 index 0000000..a4ca131 --- /dev/null +++ b/database/main/trg_requirement_check_trait_insert.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_trait_insert +BEFORE INSERT ON requirement +WHEN NEW.req_type IN ('TRAIT','TRAIT_LEVEL_MIN') +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM trait WHERE id = NEW.req_id) + THEN RAISE(ABORT, 'requirement.req_id must reference trait.id for TRAIT/TRAIT_LEVEL_MIN') + END; +END; + diff --git a/database/main/trg_requirement_check_trait_update.sql b/database/main/trg_requirement_check_trait_update.sql new file mode 100644 index 0000000..c855177 --- /dev/null +++ b/database/main/trg_requirement_check_trait_update.sql @@ -0,0 +1,10 @@ +CREATE TRIGGER trg_requirement_check_trait_update +BEFORE UPDATE ON requirement +WHEN NEW.req_type IN ('TRAIT','TRAIT_LEVEL_MIN') +BEGIN + SELECT CASE + WHEN NEW.req_id IS NULL OR NOT EXISTS (SELECT 1 FROM trait WHERE id = NEW.req_id) + THEN RAISE(ABORT, 'requirement.req_id must reference trait.id for TRAIT/TRAIT_LEVEL_MIN (UPDATE)') + END; +END; + diff --git a/database/main/trg_trait_conflict_order.sql b/database/main/trg_trait_conflict_order.sql new file mode 100644 index 0000000..9bb2f69 --- /dev/null +++ b/database/main/trg_trait_conflict_order.sql @@ -0,0 +1,7 @@ +CREATE TRIGGER trg_trait_conflict_order +BEFORE INSERT ON trait_conflict +WHEN NEW.trait_id > NEW.incompatible_trait_id +BEGIN + SELECT RAISE(ABORT, 'Insert smaller id first (trait_id < incompatible_trait_id)'); +END; + diff --git a/database/main/v_book_index.sql b/database/main/v_book_index.sql new file mode 100644 index 0000000..d652e69 --- /dev/null +++ b/database/main/v_book_index.sql @@ -0,0 +1,17 @@ +CREATE VIEW v_book_index AS +SELECT 'TRAIT' AS kind, t.name, b.code, c.page_start, c.page_end +FROM trait t JOIN trait_citation tc ON tc.trait_id=t.id + JOIN citation c ON c.id=tc.citation_id JOIN book b ON b.id=c.book_id +UNION ALL +SELECT 'SPECIES', s.name, b.code, c.page_start, c.page_end +FROM species s JOIN species_citation sc ON sc.species_id=s.id + JOIN citation c ON c.id=sc.citation_id JOIN book b ON b.id=c.book_id +UNION ALL +SELECT 'CULTURE', cu.name, b.code, c.page_start, c.page_end +FROM culture cu JOIN culture_citation cc ON cc.culture_id=cu.id + JOIN citation c ON c.id=cc.citation_id JOIN book b ON b.id=c.book_id +UNION ALL +SELECT 'PROFESSION', p.name, b.code, c.page_start, c.page_end +FROM profession p JOIN profession_citation pc ON pc.profession_id=p.id + JOIN citation c ON c.id=pc.citation_id JOIN book b ON b.id=c.book_id; + diff --git a/database/main/v_requirement_debug.sql b/database/main/v_requirement_debug.sql new file mode 100644 index 0000000..e258d6d --- /dev/null +++ b/database/main/v_requirement_debug.sql @@ -0,0 +1,13 @@ +CREATE VIEW v_requirement_debug AS +SELECT + owner_kind, + owner_id, + group_no, + CASE negate WHEN 1 THEN 'NOT ' ELSE '' END || req_type AS req_op, + req_id, + req_level, + req_optokey, + note +FROM requirement +ORDER BY owner_kind, owner_id, group_no, negate DESC, req_type, req_id; + diff --git a/database/main/v_species_auto_traits.sql b/database/main/v_species_auto_traits.sql new file mode 100644 index 0000000..eab51ed --- /dev/null +++ b/database/main/v_species_auto_traits.sql @@ -0,0 +1,7 @@ +CREATE VIEW v_species_auto_traits AS +SELECT s.id AS species_id, s.name AS species, + t.id AS trait_id, t.name AS trait, st.level, st.param_value +FROM species s + JOIN species_trait st ON st.species_id = s.id AND st.source = 'AUTOMATISCH' + JOIN trait t ON t.id = st.trait_id; + diff --git a/database/main/zielkategorie.sql b/database/main/zielkategorie.sql new file mode 100644 index 0000000..9fe4184 --- /dev/null +++ b/database/main/zielkategorie.sql @@ -0,0 +1,8 @@ +create table zielkategorie +( + id INTEGER + primary key, + name TEXT not null + unique +); + diff --git a/rules.db b/rules.db new file mode 100644 index 0000000..bcf6c6a Binary files /dev/null and b/rules.db differ