feat(backend): Update SQL schema, don't drop database in prod

This commit is contained in:
2025-11-29 10:14:04 +01:00
parent 2e355ed972
commit 79fbf7ce1b
2 changed files with 61 additions and 30 deletions

View File

@@ -10,9 +10,9 @@ spring:
password: ${LEGALCONSENTHUB_DB_PASSWORD}
jpa:
show-sql: true
show-sql: false
hibernate:
ddl-auto: create
ddl-auto: validate
database-platform: org.hibernate.dialect.PostgreSQLDialect
properties:
hibernate:

View File

@@ -1,11 +1,14 @@
create table app_user
(
created_at timestamp(6) not null,
modified_at timestamp(6) not null,
id varchar(255) not null,
name varchar(255) not null,
status varchar(255) not null check (status in ('INVITED', 'ACTIVE', 'BLOCKED', 'SUSPENDED_SUBSCRIPTION')),
primary key (id)
email_on_form_created boolean not null,
email_on_form_submitted boolean not null,
created_at timestamp(6) not null,
modified_at timestamp(6) not null,
email varchar(255),
keycloak_id varchar(255) not null,
name varchar(255) not null,
organization_id varchar(255),
primary key (keycloak_id)
);
create table application_form
@@ -22,6 +25,20 @@ create table application_form
primary key (id)
);
create table application_form_version
(
version_number integer not null,
created_at timestamp(6) not null,
application_form_id uuid not null,
id uuid not null,
created_by_id varchar(255) not null,
name varchar(255) not null,
organization_id varchar(255) not null,
snapshot_data TEXT not null,
status varchar(255) not null check (status in ('DRAFT', 'SUBMITTED', 'APPROVED', 'REJECTED', 'SIGNED')),
primary key (id)
);
create table comment
(
created_at timestamp(6) not null,
@@ -45,11 +62,12 @@ create table form_element_options
create table form_element
(
type smallint not null check (type between 0 and 4),
form_element_section_id uuid not null,
id uuid not null,
description varchar(255),
title varchar(255),
form_element_order integer,
type smallint not null check (type between 0 and 5),
form_element_sub_section_id uuid not null,
id uuid not null,
description varchar(255),
title varchar(255),
primary key (id)
);
@@ -63,6 +81,16 @@ create table form_element_section
primary key (id)
);
create table form_element_sub_section
(
form_element_sub_section_order integer,
form_element_section_id uuid not null,
id uuid not null,
subtitle varchar(255),
title varchar(255) not null,
primary key (id)
);
create table notification
(
is_read boolean not null,
@@ -72,20 +100,12 @@ create table notification
message TEXT not null,
organization_id varchar(255) not null,
recipient_id varchar(255),
role varchar(255) not null,
target_roles TEXT,
title varchar(255) not null,
type varchar(255) not null check (type in ('INFO', 'WARNING', 'ERROR')),
primary key (id)
);
create table user_organization_roles
(
organization_id varchar(255) not null,
role varchar(255) not null,
user_id varchar(255) not null,
primary key (organization_id, role, user_id)
);
alter table if exists application_form
add constraint FKhtad5onoy2jknhtyfmx6cvvey
foreign key (created_by_id)
@@ -96,6 +116,17 @@ alter table if exists application_form
foreign key (last_modified_by_id)
references app_user;
alter table if exists application_form_version
add constraint FKpfri4lhy9wqfsp8esabedkq6c
foreign key (application_form_id)
references application_form
on delete cascade;
alter table if exists application_form_version
add constraint FKl6fbcrvh439gbwgcvvfyxaggi
foreign key (created_by_id)
references app_user;
alter table if exists comment
add constraint FKlavy9axrt26sepreg5lqtuoap
foreign key (application_form_id)
@@ -117,21 +148,21 @@ alter table if exists form_element_options
references form_element;
alter table if exists form_element
add constraint FKdpr6k93m4hqllqjsvoa4or6mp
foreign key (form_element_section_id)
references form_element_section;
add constraint FKsgs6jmigb70ylymtby3tnpusg
foreign key (form_element_sub_section_id)
references form_element_sub_section;
alter table if exists form_element_section
add constraint FKtn0lreovauwf2v29doo70o3qs
foreign key (application_form_id)
references application_form;
alter table if exists form_element_sub_section
add constraint FK46c23gs3wjyyitiv77wfbq2id
foreign key (form_element_section_id)
references form_element_section;
alter table if exists notification
add constraint FKeg1j4hnp0y4lbm0y35hgr4e8r
foreign key (recipient_id)
references app_user;
alter table if exists user_organization_roles
add constraint FKhgmm93qre3up6hy63wcef3yqk
foreign key (user_id)
references app_user