changes
This commit is contained in:
parent
2b8b9f8a5b
commit
5583449c0d
@ -1,9 +1,23 @@
|
|||||||
|
create sequence account_s
|
||||||
|
start with 1
|
||||||
|
increment by 1;
|
||||||
|
|
||||||
|
create table account_t (
|
||||||
|
id integer not null default nextval('account_s'),
|
||||||
|
comment varchar(128) not null,
|
||||||
|
constraint account_t_pk primary key (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
alter table account_t rename column comment to description;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
create sequence tenant_s
|
create sequence tenant_s
|
||||||
start with 1
|
start with 1
|
||||||
increment by 1;
|
increment by 1;
|
||||||
|
|
||||||
create table tenant_t (
|
create table tenant_t (
|
||||||
id integer primary key not null default nextval('tenant_s'),
|
id integer not null default nextval('tenant_s'),
|
||||||
salutation varchar(128) default null,
|
salutation varchar(128) default null,
|
||||||
firstname varchar(128) default null,
|
firstname varchar(128) default null,
|
||||||
lastname varchar(128) not null,
|
lastname varchar(128) not null,
|
||||||
@ -14,61 +28,126 @@ create table tenant_t (
|
|||||||
city varchar(128) default null,
|
city varchar(128) default null,
|
||||||
phone1 varchar(64) default null,
|
phone1 varchar(64) default null,
|
||||||
phone2 varchar(64) default null,
|
phone2 varchar(64) default null,
|
||||||
iban varchar(34) default null
|
iban varchar(34) default null,
|
||||||
|
account integer not null,
|
||||||
|
constraint tenant_t_pk primary key (id),
|
||||||
|
constraint tenant_t_account_uk unique (id),
|
||||||
|
constraint tenant_t_account_fk foreign key (account) references account_t (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
alter table tenant_t rename column account to fee_account;
|
||||||
|
|
||||||
|
alter table tenant_t add column overhead_account integer;
|
||||||
|
alter table tenant_t add constraint tenant_t_overhead_account_fk foreign key (overhead_account) references account_t (id);
|
||||||
|
|
||||||
|
alter table tenant_t add column disposit_account integer;
|
||||||
|
alter table tenant_t add constraint tenant_t_disposit_account_fk foreign key (disposit_account) references account_t (id);
|
||||||
|
|
||||||
|
alter table tenant_t alter column overhead_account set not null;
|
||||||
|
alter table tenant_t alter column disposit_account set not null;
|
||||||
|
|
||||||
|
|
||||||
create sequence premise_s
|
create sequence premise_s
|
||||||
start with 1
|
start with 1
|
||||||
increment by 1;
|
increment by 1;
|
||||||
|
|
||||||
create table premise_t (
|
create table premise_t (
|
||||||
id integer primary key not null default nextval('premise_s'),
|
id integer not null default nextval('premise_s'),
|
||||||
street varchar(128) not null,
|
street varchar(128) not null,
|
||||||
zip varchar(10) not null,
|
zip varchar(10) not null,
|
||||||
city varchar(128) not null
|
city varchar(128) not null,
|
||||||
|
constraint premise_t_pk primary key (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
create sequence rented_object_s
|
create sequence flat_s
|
||||||
start with 1
|
start with 1
|
||||||
increment by 1;
|
increment by 1;
|
||||||
|
|
||||||
create table rented_object_t (
|
|
||||||
id integer primary key not null default nextval('rented_object_s'),
|
|
||||||
comment varchar(32) default null,
|
|
||||||
premise integer references premise_t(id)
|
|
||||||
);
|
|
||||||
|
|
||||||
create table flat_t (
|
create table flat_t (
|
||||||
|
id integer not null default nextval('flat_s'),
|
||||||
|
description varchar(32) default null,
|
||||||
|
premise integer,
|
||||||
area numeric(10,2) not null,
|
area numeric(10,2) not null,
|
||||||
flat_no integer default null
|
flat_no integer default null,
|
||||||
) inherits (rented_object_t);
|
constraint flat_t_pk primary key (id),
|
||||||
|
constraint flat_t_premise_fk foreign key (premise) references premise_t (id)
|
||||||
|
);
|
||||||
|
|
||||||
create sequence overhead_advance_s
|
create sequence overhead_advance_s
|
||||||
start with 1
|
start with 1
|
||||||
increment by 1;
|
increment by 1;
|
||||||
|
|
||||||
create table overhead_advance_t (
|
create table overhead_advance_t (
|
||||||
id integer primary key not null default nextval('overhead_advance_s'),
|
id integer not null default nextval('overhead_advance_s'),
|
||||||
comment varchar(128) default null,
|
description varchar(128) default null,
|
||||||
rented_object integer not null references rented_object_t(id),
|
|
||||||
amount numeric(10, 4) not null,
|
amount numeric(10, 4) not null,
|
||||||
startdate date default null,
|
startdate date default null,
|
||||||
enddate date default null
|
enddate date default null,
|
||||||
|
constraint overhead_advance_t_pk primary key (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
create table parking_t (
|
|
||||||
|
|
||||||
) inherits (rented_object_t);
|
create sequence overhead_advance_flat_mapping_s
|
||||||
|
start with 1
|
||||||
|
increment by 1;
|
||||||
|
|
||||||
|
create table overhead_advance_flat_mapping_t (
|
||||||
|
id integer not null default nextval('overhead_advance_flat_mapping_s'),
|
||||||
|
overhead_advance integer not null,
|
||||||
|
flat integer not null,
|
||||||
|
constraint overhead_advance_flat_mapping_t_pk primary key (id),
|
||||||
|
constraint overhead_advance_flat_mapping_t_overhead_advance_fk foreign key (overhead_advance) references overhead_advance_t (id),
|
||||||
|
constraint overhead_advance_flat_mapping_t_flat_fk foreign key (flat) references flat_t (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
create sequence parking_s
|
||||||
|
start with 1
|
||||||
|
increment by 1;
|
||||||
|
|
||||||
|
create table parking_t (
|
||||||
|
id integer not null default nextval('parking_s'),
|
||||||
|
description varchar(32) default null,
|
||||||
|
premise integer,
|
||||||
|
constraint parking_t_pk primary key (id),
|
||||||
|
constraint parking_t_premise_fk foreign key (premise) references premise_t (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
create sequence commercial_premise_s
|
||||||
|
start with 1
|
||||||
|
increment by 1;
|
||||||
|
|
||||||
create table commercial_premise_t (
|
create table commercial_premise_t (
|
||||||
|
id integer not null default nextval('commercial_premise_s'),
|
||||||
|
description varchar(32) default null,
|
||||||
|
premise integer,
|
||||||
|
constraint commercial_premise_t_pk primary key (id),
|
||||||
|
constraint commercial_premise_t_premise_fk foreign key (premise) references premise_t (id)
|
||||||
|
);
|
||||||
|
|
||||||
) inherits (rented_object_t);
|
create sequence tenancy_s
|
||||||
|
start with 1
|
||||||
|
increment by 1;
|
||||||
|
|
||||||
create table tenancy_t (
|
create table tenancy_t (
|
||||||
tenant integer not null references tenant_t(id),
|
id integer not null default nextval('tenancy_s'),
|
||||||
rented_object integer not null references rented_object_t(id),
|
tenant integer not null,
|
||||||
|
flat integer default null,
|
||||||
|
parking integer default null,
|
||||||
|
commercial_premise integer default null,
|
||||||
startdate date not null,
|
startdate date not null,
|
||||||
enddate date default null
|
enddate date default null,
|
||||||
|
constraint tenancy_t_pk primary key (id),
|
||||||
|
constraint tenancy_t_tenant_fk foreign key (tenant) references tenant_t (id),
|
||||||
|
constraint tenancy_t_flat_fk foreign key (flat) references flat_t (id) match simple,
|
||||||
|
constraint tenancy_t_parking_fk foreign key (parking) references parking_t (id) match simple,
|
||||||
|
constraint tenancy_t_commercial_premise_fk foreign key (commercial_premise) references commercial_premise_t (id) match simple,
|
||||||
|
constraint tenancy_t_only_one_object check (
|
||||||
|
(flat is not null and parking is null and commercial_premise is null) or
|
||||||
|
(flat is null and parking is not null and commercial_premise is null) or
|
||||||
|
(flat is null and parking is null and commercial_premise is not null)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
create sequence fee_s
|
create sequence fee_s
|
||||||
@ -76,16 +155,31 @@ create sequence fee_s
|
|||||||
increment by 1;
|
increment by 1;
|
||||||
|
|
||||||
create table fee_t (
|
create table fee_t (
|
||||||
id integer primary key not null default nextval('fee_s'),
|
id integer not null default nextval('fee_s'),
|
||||||
comment varchar(128) default null,
|
comment varchar(128) default null,
|
||||||
amount numeric(10, 2) not null,
|
amount numeric(10, 2) not null,
|
||||||
startdate date default null,
|
startdate date default null,
|
||||||
enddate date default null
|
enddate date default null,
|
||||||
|
constraint fee_t_pk primary key (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
create table rented_object_fee_mapping_t (
|
CREATE TYPE fee_type_e AS ENUM ('per_area', 'total');
|
||||||
rented_object integer not null references rented_object_t(id),
|
|
||||||
fee integer not null references fee_t(id)
|
alter table fee_t add column fee_type fee_type_e;
|
||||||
|
ALTER TABLE fee_t ALTER COLUMN fee_type SET NOT NULL;
|
||||||
|
|
||||||
|
|
||||||
|
create sequence tenancy_fee_mapping_s
|
||||||
|
start with 1
|
||||||
|
increment by 1;
|
||||||
|
|
||||||
|
create table tenancy_fee_mapping_t (
|
||||||
|
id integer not null default nextval('tenancy_fee_mapping_s'),
|
||||||
|
tenancy integer not null,
|
||||||
|
fee integer not null,
|
||||||
|
constraint tenancy_fee_mapping_t_pk primary key (id),
|
||||||
|
constraint tenancy_fee_mapping_t_tenancy_fk foreign key (tenancy) references tenancy_t (id),
|
||||||
|
constraint tenancy_fee_mapping_t_fee_fk foreign key (fee) references fee_t (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -95,11 +189,13 @@ create sequence account_entry_s
|
|||||||
increment by 1;
|
increment by 1;
|
||||||
|
|
||||||
create table account_entry_t (
|
create table account_entry_t (
|
||||||
id integer primary key not null default nextval('account_entry_s'),
|
id integer not null default nextval('account_entry_s'),
|
||||||
tenant integer not null references tenant_t(id),
|
account integer not null,
|
||||||
created_at date not null default now(),
|
created_at date not null default now(),
|
||||||
amount numeric(10, 2) not null,
|
amount numeric(10, 2) not null,
|
||||||
comment varchar(32) not null
|
comment varchar(32) not null,
|
||||||
|
constraint account_entry_t_pk primary key (id),
|
||||||
|
constraint account_entry_t_account_fk foreign key (account) references account_t (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
40
initial/testdata.sql
Normal file
40
initial/testdata.sql
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
insert into account_t (description) values ('fee testtenant1');
|
||||||
|
insert into account_t (description) values ('overhead testtenant1');
|
||||||
|
insert into account_t (description) values ('disposit testtenant1');
|
||||||
|
|
||||||
|
insert into tenant_t (lastname, fee_account, overhead_account, disposit_account) values (
|
||||||
|
'testtenant1',
|
||||||
|
(select id from account_t where comment = 'fee testtenant1'),
|
||||||
|
(select id from account_t where comment = 'overhead testtenant1'),
|
||||||
|
(select id from account_t where comment = 'disposit testtenant1'),
|
||||||
|
);
|
||||||
|
|
||||||
|
insert into premise_t (street, zip, city) values ('Hemsingskotten 38', '45259', 'Essen');
|
||||||
|
|
||||||
|
insert into parking_t (description, premise) values ('Garage 1', (select id from premise_t where street = 'Hemsingskotten 38'));
|
||||||
|
|
||||||
|
insert into flat_t (description, premise, area, flat_no) values('EG links', (select id from premise_t where street = 'Hemsingskotten 38'), 59.0, 1);
|
||||||
|
|
||||||
|
insert into fee_t (comment, amount, fee_type, startdate) values ('Altenwohnung Hemsingskotten', 5.23, 'per_area', '2021-01-01');
|
||||||
|
|
||||||
|
insert into fee_t (comment, amount, fee_type, startdate) values ('Garage intern', 30.0, 'total', '2021-01-01');
|
||||||
|
|
||||||
|
insert into tenancy_t (tenant, flat, startdate) values (
|
||||||
|
(select id from tenant_t where lastname = 'testtenant1'),
|
||||||
|
(select id from flat_t where flat_no = 1),
|
||||||
|
'2021-06-01'
|
||||||
|
);
|
||||||
|
|
||||||
|
insert into tenancy_t (tenant, parking, startdate) values (
|
||||||
|
(select id from tenant_t where lastname = 'testtenant1'),
|
||||||
|
(select id from parking_t where description = 'Garage 1'),
|
||||||
|
'2021-06-01'
|
||||||
|
);
|
||||||
|
|
||||||
|
insert into overhead_advance_t (description, amount, startdate) values ('BKV Altenwohnung Hemsingskotten', 0.34, '2021-01-01');
|
||||||
|
|
||||||
|
insert into overhead_advance_flat_mapping_t (overhead_advance, flat) values (
|
||||||
|
(select id from overhead_advance_t where description = 'BKV Altenwohnung Hemsingskotten'),
|
||||||
|
(select id from flat_t where flat_no = 1)
|
||||||
|
);
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user