183 lines
6.1 KiB
SQL
183 lines
6.1 KiB
SQL
-- Your SQL goes here
|
|
create table event_types
|
|
(
|
|
type_id uuid default uuid_generate_v1()
|
|
constraint event_types_pk
|
|
primary key,
|
|
name text not null,
|
|
description text,
|
|
is_billable bool not null
|
|
);
|
|
create table events
|
|
(
|
|
entity_id uuid not null
|
|
constraint events_pk
|
|
primary key
|
|
constraint events_entities_entity_id_fk
|
|
references entities
|
|
on update cascade on delete cascade,
|
|
name text not null,
|
|
start timestamp not null,
|
|
"end" timestamp not null,
|
|
site text,
|
|
organiser_id uuid
|
|
constraint events_event_organisers_entity_id_fk
|
|
references event_organisers
|
|
on update cascade on delete set null,
|
|
etype uuid
|
|
constraint events_event_types_type_id_fk
|
|
references event_types
|
|
on update cascade on delete set null,
|
|
contact_on_site_name text,
|
|
contact_on_site_phone text,
|
|
member_responsible uuid
|
|
constraint events_member_responsible_entity_id_fk
|
|
references entities
|
|
on update cascade on delete set null,
|
|
related_group uuid
|
|
constraint events_groups_entity_id_fk
|
|
references groups
|
|
on update cascade on delete set null,
|
|
other text,
|
|
other_intern text
|
|
);
|
|
|
|
create table eu_templates
|
|
(
|
|
entity_id uuid not null
|
|
constraint eu_templates_pk
|
|
primary key
|
|
constraint eu_templates_entities_entity_id_fk
|
|
references entities
|
|
on update cascade on delete cascade,
|
|
name text not null,
|
|
description text
|
|
);
|
|
|
|
comment on table eu_templates is 'Templates for event units';
|
|
|
|
-- Example JSON for requirements:{
|
|
-- "CONDITIONS": [
|
|
-- "AND",
|
|
-- ["OR",
|
|
-- {"qualification" : "SAN B"},
|
|
-- {"qualification" : "SAN C"}
|
|
-- ],
|
|
-- {"qualification" : "SBF-See"}
|
|
-- ]
|
|
-- }
|
|
create table eu_positions
|
|
(
|
|
entity_id uuid not null
|
|
constraint eu_positions_pk
|
|
primary key
|
|
constraint eu_positions_entities_entity_id_fk
|
|
references entities
|
|
on update cascade on delete cascade,
|
|
name text not null,
|
|
description text,
|
|
requirements jsonb
|
|
);
|
|
|
|
comment on table eu_positions is 'Positions to be used in event unit templates';
|
|
|
|
create table eu_vehicle_positions
|
|
(
|
|
entity_id uuid not null
|
|
constraint eu_vehicle_positions_pk
|
|
primary key
|
|
constraint eu_vehicle_positions_entities_entity_id_fk
|
|
references entities
|
|
on update cascade on delete cascade,
|
|
name text not null,
|
|
description text,
|
|
required_vehicle_category uuid not null
|
|
constraint eu_vehicle_positions_vehicle_categories_id_fk
|
|
references vehicle_categories
|
|
on update cascade on delete set null,
|
|
template_id uuid not null
|
|
constraint eu_vehicle_positions_eu_templates_entity_id_fk
|
|
references eu_templates
|
|
on update cascade on delete cascade
|
|
);
|
|
|
|
comment on table eu_vehicle_positions is 'Vehicle templates/positions to be used in event unit templates';
|
|
|
|
create table eu_positions_templates
|
|
(
|
|
position_entity_id uuid not null
|
|
constraint eu_positions_templates_entities_entity_id_fk
|
|
references entities
|
|
on update cascade on delete cascade,
|
|
template_id uuid not null
|
|
constraint eu_positions_templates_entities_entity_id_fk_2
|
|
references entities
|
|
on update cascade on delete cascade,
|
|
constraint eu_positions_templates_pk
|
|
primary key (position_entity_id, template_id)
|
|
);
|
|
|
|
comment on table eu_positions_templates is 'Connects eu_positions/eu_vehicle_positions and eu_templates';
|
|
|
|
create table eu_position_instances
|
|
(
|
|
instance_id uuid not null
|
|
constraint eu_position_instances_entities_entity_id_fk
|
|
references entities
|
|
on update cascade on delete cascade,
|
|
position_id uuid not null
|
|
constraint eu_position_instances_entities_entity_id_fk_2
|
|
references entities
|
|
on update cascade on delete cascade,
|
|
taken_by uuid
|
|
constraint eu_position_instances_entities_entity_id_fk_3
|
|
references entities
|
|
on update cascade on delete cascade,
|
|
constraint eu_position_instances_pk
|
|
primary key (instance_id, position_id)
|
|
);
|
|
|
|
comment on table eu_position_instances is 'assigns member or vehicle to member or vehicle position';
|
|
|
|
create table eu_instances
|
|
(
|
|
instance_id uuid not null
|
|
constraint eu_instances_pk
|
|
primary key
|
|
constraint eu_instances_entities_entity_id_fk
|
|
references entities
|
|
on update cascade on delete cascade,
|
|
template_id uuid not null
|
|
constraint eu_instances_entities_entity_id_fk_2
|
|
references entities
|
|
on update cascade,
|
|
name text not null,
|
|
event_id uuid not null
|
|
constraint eu_instances_entities_entity_id_fk_3
|
|
references entities
|
|
on update cascade on delete cascade
|
|
);
|
|
|
|
INSERT INTO permissions (permission, description)
|
|
VALUES ('modules.event_management.events.view', 'Permission to see all events');
|
|
|
|
INSERT INTO permissions (permission, description)
|
|
VALUES ('modules.event_management.events.edit', 'Permission to edit all events');
|
|
|
|
INSERT INTO permissions (permission, description)
|
|
VALUES ('modules.event_management.events.create', 'Permission to create a new event');
|
|
|
|
INSERT INTO permissions (permission, description)
|
|
VALUES ('modules.event_management.events.delete', 'Permission to delete an existing event');
|
|
|
|
INSERT INTO public.roles_permissions (role_id, permission_id, role_permission_id)
|
|
VALUES ('admin', 'modules.event_management.events.view', DEFAULT);
|
|
|
|
INSERT INTO public.roles_permissions (role_id, permission_id, role_permission_id)
|
|
VALUES ('admin', 'modules.event_management.events.edit', DEFAULT);
|
|
|
|
INSERT INTO public.roles_permissions (role_id, permission_id, role_permission_id)
|
|
VALUES ('admin', 'modules.event_management.events.delete', DEFAULT);
|
|
|
|
INSERT INTO public.roles_permissions (role_id, permission_id, role_permission_id)
|
|
VALUES ('admin', 'modules.event_management.events.create', DEFAULT); |