added schema.sql
This commit is contained in:
parent
26422450bd
commit
7f79078c6a
1 changed files with 258 additions and 0 deletions
258
src/main/resources/schema.sql
Normal file
258
src/main/resources/schema.sql
Normal file
|
|
@ -0,0 +1,258 @@
|
||||||
|
-- meta tables, like units and certificates
|
||||||
|
create table if not exists "legal_base"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
legal_base TEXT,
|
||||||
|
jounal TEXT,
|
||||||
|
page INT,
|
||||||
|
`date` DATE
|
||||||
|
);
|
||||||
|
create table if not exists "monetary_unit"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
monetary_unit_code CHAR(3)
|
||||||
|
);
|
||||||
|
create table if not exists "unit"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
unit_code CHAR(3),
|
||||||
|
unit_qualifier CHAR(1),
|
||||||
|
label TEXT
|
||||||
|
);
|
||||||
|
create table if not exists "certificate_type"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
certificate_type_code CHAR(1)
|
||||||
|
);
|
||||||
|
create table if not exists "certificate"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
certificate_code CHAR(4),
|
||||||
|
FOREIGN KEY (certificate_type_id) REFERENCES certificate_type(id),
|
||||||
|
start_date DATE,
|
||||||
|
end_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "condition_type"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
condition_type_code CHAR(1)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- measure meta infos
|
||||||
|
create table if not exists "footnotes"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
footnote CHAR(5),
|
||||||
|
start_date DATE,
|
||||||
|
end_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "measure_series"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
measure_series_code CHAR(1)
|
||||||
|
);
|
||||||
|
create table if not exists "measure"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (measure_series_id) REFERENCES measure_series(id),
|
||||||
|
measure_code CHAR(3),
|
||||||
|
short_desc TEXT,
|
||||||
|
tm_code TINYINT,
|
||||||
|
start_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "measure_footnote"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (footnote_id) REFERENCES footnote(id),
|
||||||
|
FOREIGN KEY (measure_id) REFERENCES measure(id)
|
||||||
|
);
|
||||||
|
create table if not exists "measure_action"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
measure_action_code CHAR(1)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- geo
|
||||||
|
create table if not exists "geo"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
iso_3166_code CHAR(2),
|
||||||
|
`desc` TEXT
|
||||||
|
);
|
||||||
|
create table if not exists "geo_group"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
geo_group_code CHAR(4),
|
||||||
|
abbr TEXT,
|
||||||
|
start_date DATE,
|
||||||
|
end_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "geo_group_membership"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (geo_id) REFERENCES geo(id),
|
||||||
|
FOREIGN KEY (geo_group_id) REFERENCES geo_group(id),
|
||||||
|
start_date DATE,
|
||||||
|
end_date DATE
|
||||||
|
);
|
||||||
|
|
||||||
|
-- nomenclature
|
||||||
|
create table if not exists "nomenclature"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
hscode CHAR(10),
|
||||||
|
suffix CHAR(2),
|
||||||
|
hierachy TINYINT,
|
||||||
|
indent TINYINT,
|
||||||
|
start_date DATE,
|
||||||
|
end_date DATE,
|
||||||
|
is_leaf BOOLEAN,
|
||||||
|
is_leaf_start_date DATE,
|
||||||
|
parent_id INT -- TODO: for each child do: alter table nomenclature add constraint parent_nomenclature foreign key (parent_id) references nomenclature(id) on delete set null;
|
||||||
|
);
|
||||||
|
create table if not exists "additional_code"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
additional_code CHAR(4),
|
||||||
|
start_date DATE,
|
||||||
|
end_date DATE,
|
||||||
|
);
|
||||||
|
|
||||||
|
-- import, applied_measures
|
||||||
|
create table if not exists "import"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (nomenclature_id) REFERENCES nomenclature(id),
|
||||||
|
FOREIGN KEY (additional_code_id) REFERENCES additional_code(id),
|
||||||
|
FOREIGN KEY (geo_id) REFERENCES geo(id),
|
||||||
|
FOREIGN KEY (geo_group_id) REFERENCES geo_group(id),
|
||||||
|
);
|
||||||
|
create table if not exists "applied_measure"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (import_id) REFERENCES import(id),
|
||||||
|
FOREIGN KEY (measure_id) REFERENCES measure(id),
|
||||||
|
FOREIGN KEY (legal_base_id) REFERENCES legal_base(id),
|
||||||
|
start_date DATE,
|
||||||
|
end_date DATE,
|
||||||
|
amount TEXT
|
||||||
|
);
|
||||||
|
create table if not exists "applied_measure_condition"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (applied_measure_id) REFERENCES applied_measure(id),
|
||||||
|
sequence_no INT,
|
||||||
|
FOREIGN KEY (measure_action_id) REFERENCES measure_action(id),
|
||||||
|
amount TEXT,
|
||||||
|
FOREIGN KEY (monetary_unit_id) REFERENCES monetary_unit(id),
|
||||||
|
FOREIGN KEY (unit_id) REFERENCES unit(id),
|
||||||
|
FOREIGN KEY (certificate_id) REFERENCES certificate(id),
|
||||||
|
FOREIGN KEY (condition_type_id) REFERENCES condition_type(id)
|
||||||
|
);
|
||||||
|
create table if not exists "measure_exclusion"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (geo_id) REFERENCES geo(id),
|
||||||
|
FOREIGN KEY (applied_measure_id) REFERENCES applied_measure(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- descriptions
|
||||||
|
create table if not exists "footnotes_desc"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (ref_id) REFERENCES footnotes(id),
|
||||||
|
lang CHAR(2),
|
||||||
|
`desc` TEXT,
|
||||||
|
desc_start_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "measure_desc"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (ref_id) REFERENCES measure(id),
|
||||||
|
lang CHAR(2),
|
||||||
|
`desc` TEXT,
|
||||||
|
desc_start_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "measure_series_desc"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (ref_id) REFERENCES measure_series(id),
|
||||||
|
lang CHAR(2),
|
||||||
|
`desc` TEXT,
|
||||||
|
desc_start_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "measure_action_desc"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (ref_id) REFERENCES measure_action(id),
|
||||||
|
lang CHAR(2),
|
||||||
|
`desc` TEXT,
|
||||||
|
desc_start_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "geo_group_desc"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (ref_id) REFERENCES geo_group(id),
|
||||||
|
lang CHAR(2),
|
||||||
|
`desc` TEXT,
|
||||||
|
desc_start_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "monetary_unit_desc"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (ref_id) REFERENCES monetary_unit(id),
|
||||||
|
lang CHAR(2),
|
||||||
|
`desc` TEXT,
|
||||||
|
desc_start_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "unit_desc"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (ref_id) REFERENCES unit(id),
|
||||||
|
lang CHAR(2),
|
||||||
|
`desc` TEXT,
|
||||||
|
desc_start_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "certificate_desc"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (ref_id) REFERENCES certificate(id),
|
||||||
|
lang CHAR(2),
|
||||||
|
`desc` TEXT,
|
||||||
|
desc_start_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "certificate_type_desc"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (ref_id) REFERENCES certificate_type(id),
|
||||||
|
lang CHAR(2),
|
||||||
|
`desc` TEXT,
|
||||||
|
desc_start_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "condition_type_desc"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (ref_id) REFERENCES condition_type(id),
|
||||||
|
lang CHAR(2),
|
||||||
|
`desc` TEXT,
|
||||||
|
desc_start_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "additional_code_desc"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (ref_id) REFERENCES additional_code(id),
|
||||||
|
lang CHAR(2),
|
||||||
|
`desc` TEXT,
|
||||||
|
desc_start_date DATE
|
||||||
|
);
|
||||||
|
create table if not exists "nomenclature_desc"
|
||||||
|
(
|
||||||
|
id INT NOT NULL PRIMARY KEY,
|
||||||
|
FOREIGN KEY (ref_id) REFERENCES nomenclature(id),
|
||||||
|
lang CHAR(2),
|
||||||
|
`desc` TEXT,
|
||||||
|
desc_start_date DATE
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue