Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class Result {
private static final Logger logger = LoggerFactory.getLogger(Result.class);

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@SequenceGenerator(name = "result_seq", sequenceName = "result_sequence", schema = "dbo", allocationSize = 100)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "result_seq")
private Long id;

@Column(nullable = false)
Expand Down
6 changes: 6 additions & 0 deletions Java/validation/src/main/resources/application-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ spring:
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
jdbc:
batch_size: 100
order_inserts: true
order_updates: true

data:
redis:
Expand Down
4 changes: 4 additions & 0 deletions Java/validation/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ spring:
schema-generation:
script:
append: false
jdbc:
batch_size: 100
order_inserts: true
order_updates: true

jakarta:
persistence:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
-- Drop old result tables (data will be lost per migration plan)
if exists (select 1 from sys.foreign_keys where name = 'fk_result_category_result_id')
begin
alter table result_category drop constraint fk_result_category_result_id
end

if exists (select 1 from sys.foreign_keys where name = 'fk_result_category_category_id')
begin
alter table result_category drop constraint fk_result_category_category_id
end

if exists (select 1 from sys.tables where name = 'result_category' and schema_id = schema_id('dbo'))
begin
drop table result_category
end

if exists (select 1 from sys.tables where name = 'result' and schema_id = schema_id('dbo'))
begin
drop table result
end
Comment thread
coderabbitai[bot] marked this conversation as resolved.

if exists (select 1 from sys.sequences where name = 'result_sequence' and schema_name(schema_id) = 'dbo')
begin
drop sequence dbo.result_sequence
end

-- Create sequence for Result IDs
create sequence dbo.result_sequence
as bigint
start with 1
increment by 100;

-- Recreate result table using sequence-based IDs (not IDENTITY)
create table result
(
id bigint not null primary key default (NEXT VALUE FOR dbo.result_sequence),
expression varchar(1000),
code varchar(255) not null check (code in
('INVALID', 'STRUCTURE', 'REQUIRED', 'VALUE', 'INVARIANT', 'SECURITY',
'LOGIN', 'UNKNOWN', 'EXPIRED', 'FORBIDDEN', 'SUPPRESSED', 'PROCESSING',
'NOTSUPPORTED', 'DUPLICATE', 'MULTIPLEMATCHES', 'NOTFOUND', 'DELETED',
'TOOLONG', 'CODEINVALID', 'EXTENSION', 'TOOCOSTLY', 'BUSINESSRULE',
'CONFLICT', 'TRANSIENT', 'LOCKERROR', 'NOSTORE', 'EXCEPTION',
'TIMEOUT', 'INCOMPLETE', 'THROTTLED', 'INFORMATIONAL', 'NULL')),
facility_id varchar(255) not null,
location varchar(255),
message varchar(max) not null,
patient_id varchar(255) not null,
report_id varchar(255) not null,
severity varchar(255) not null check (severity in ('FATAL', 'ERROR', 'WARNING', 'INFORMATION', 'NULL'))
);

-- Recreate result_category join table
create table result_category
(
result_id bigint not null,
category_id varchar(255) not null
);

-- Indexes and constraints
if not exists (select 1 from sys.indexes where name = 'ix_result_facility_id' and object_id = object_id('result'))
create index ix_result_facility_id
on result (facility_id);

if not exists (select 1 from sys.indexes where name = 'ix_result_facility_id_report_id' and object_id = object_id('result'))
create index ix_result_facility_id_report_id
on result (facility_id, report_id);

if not exists (select 1 from sys.indexes where name = 'ix_result_facility_id_report_id_patient_id' and object_id = object_id('result'))
create index ix_result_facility_id_report_id_patient_id
on result (facility_id, report_id, patient_id);

if not exists (select 1 from sys.indexes where name = 'ix_result_category_result_id' and object_id = object_id('result_category'))
create index ix_result_category_result_id
on result_category (result_id);

if not exists (select 1 from sys.key_constraints where name = 'ix_result_category_result_id_category_id')
begin
alter table result_category
add constraint ix_result_category_result_id_category_id unique (result_id, category_id);
end;

-- Foreign keys
if not exists (select 1 from sys.foreign_keys where name = 'fk_result_category_category_id')
begin
alter table result_category
add constraint fk_result_category_category_id
foreign key (category_id)
references category;
end;

if not exists (select 1 from sys.foreign_keys where name = 'fk_result_category_result_id')
begin
alter table result_category
add constraint fk_result_category_result_id
foreign key (result_id)
references result;
end;

-- Ensure existing sequence uses increment 100 to match Hibernate allocationSize
IF EXISTS (SELECT 1 FROM sys.sequences WHERE name = 'result_sequence' AND schema_name(schema_id) = 'dbo')
BEGIN
ALTER SEQUENCE dbo.result_sequence
INCREMENT BY 100;
END
ELSE
BEGIN
CREATE SEQUENCE dbo.result_sequence
AS bigint
START WITH 1
INCREMENT BY 100;
END
Loading