Skip to content

Commit cfebe89

Browse files
Cnde 2375 liquibase di (#319)
* Added liquibase configuration * Updated changelog to have only Data Ingestion changes * Added Liquibase config class * Updated README --------- Co-authored-by: Ragul Shanmugam <rshanmugam@enquizit.com>
1 parent 0232e5e commit cfebe89

10 files changed

Lines changed: 165 additions & 95 deletions

File tree

data-ingestion-service/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
mavenCentral()
44
gradlePluginPortal()
55
maven {
6-
url "https://plugins.gradle.org/m2/"
6+
url = "https://plugins.gradle.org/m2/"
77
}
88
}
99
dependencies {
@@ -240,6 +240,9 @@ dependencies {
240240
compileOnly 'org.projectlombok:lombok:1.18.34'
241241
annotationProcessor 'org.projectlombok:lombok:1.18.34'
242242

243+
implementation 'org.liquibase:liquibase-core:4.31.1'
244+
245+
243246
// Misc
244247
implementation 'org.yaml:snakeyaml:2.3'
245248
implementation 'org.apache.commons:commons-lang3:3.17.0'
@@ -307,6 +310,7 @@ jar {
307310
}
308311
}
309312

313+
310314
sonarqube {
311315
properties {
312316
property "sonar.projectKey", "CDCgov_NEDSS-DataIngestion"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package gov.cdc.dataingestion.config;
2+
3+
import liquibase.integration.spring.SpringLiquibase;
4+
import org.springframework.beans.factory.annotation.Qualifier;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
7+
import org.springframework.boot.context.properties.ConfigurationProperties;
8+
import org.springframework.boot.jdbc.DataSourceBuilder;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.Configuration;
11+
12+
import javax.sql.DataSource;
13+
14+
@Configuration
15+
public class LiquibaseConfig {
16+
17+
@Value("${spring.liquibase.user}")
18+
private String dbUserName;
19+
20+
@Value("${spring.liquibase.password}")
21+
private String dbUserPassword;
22+
23+
@Value("${spring.liquibase.driver-class-name}")
24+
private String driverClassName;
25+
26+
@Value("${spring.liquibase.url}")
27+
private String dbUrl;
28+
29+
@Bean
30+
@ConfigurationProperties(prefix = "spring.liquibase")
31+
public LiquibaseProperties liquibaseProperties() {
32+
return new LiquibaseProperties();
33+
}
34+
35+
@Bean(name = "liquibaseDataSource")
36+
public DataSource liquibaseDataSource() {
37+
return DataSourceBuilder.create()
38+
.url(dbUrl)
39+
.username(dbUserName)
40+
.password(dbUserPassword)
41+
.driverClassName(driverClassName)
42+
.build();
43+
}
44+
45+
@Bean
46+
public SpringLiquibase liquibase(@Qualifier("liquibaseDataSource") DataSource liquibaseDataSource, LiquibaseProperties liquibaseProperties) {
47+
SpringLiquibase liquibase = new SpringLiquibase();
48+
liquibase.setDataSource(liquibaseDataSource);
49+
liquibase.setChangeLog(liquibaseProperties.getChangeLog());
50+
if (liquibaseProperties.getContexts() != null) {
51+
liquibase.setContexts(String.join(",", liquibaseProperties.getContexts()));
52+
}
53+
return liquibase;
54+
}
55+
}

data-ingestion-service/src/main/resources/application.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ spring:
4848
config:
4949
activate:
5050
on-profile: default
51+
liquibase:
52+
change-log: classpath:db/changelog.yaml
53+
enabled: true
54+
url: jdbc:sqlserver://${NBS_DBSERVER};databaseName=NBS_DATAINGEST;encrypt=true;trustServerCertificate=true;
55+
user: ${NBS_DBUSER}
56+
password: ${NBS_DBPASSWORD}
57+
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
5158
datasource:
5259
username: ${NBS_DBUSER}
5360
password: ${NBS_DBPASSWORD}

data-ingestion-service/src/main/resources/db/changelog.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
databaseChangeLog:
2+
- changeSet:
3+
id: 1
4+
author: liquibase
5+
changes:
6+
- sqlFile:
7+
path: data-ingestion-service/src/main/resources/db/create-nbs-dataingest-db.sql
8+
splitStatements: false
9+
10+
- changeSet:
11+
id: 2
12+
author: liquibase
13+
changes:
14+
- sqlFile:
15+
path: data-ingestion-service/src/main/resources/db/di-service-001.sql
16+
splitStatements: false
17+
18+
- changeSet:
19+
id: 3
20+
author: liquibase
21+
changes:
22+
- sqlFile:
23+
path: data-ingestion-service/src/main/resources/db/di-service-002.sql
24+
splitStatements: false

data-ingestion-service/src/main/resources/db/create-nbs-dataingest-db.sql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,3 @@ IF NOT EXISTS(SELECT *
44
BEGIN
55
CREATE DATABASE NBS_DataIngest
66
END
7-
GO
8-
USE NBS_DataIngest
9-
GO
Lines changed: 68 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,80 @@
1-
-- changeset liquibase:1
2-
--
3-
-- Creates the tables used by Data Ingestion Service
4-
--
5-
6-
IF NOT EXISTS(
1+
USE NBS_DataIngest;
2+
IF
3+
NOT EXISTS(
74
SELECT 'X'
85
FROM INFORMATION_SCHEMA.TABLES
96
WHERE TABLE_NAME = 'elr_raw')
10-
BEGIN
11-
CREATE TABLE elr_raw
12-
(
13-
id UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(),
14-
message_type NVARCHAR(255) NOT NULL,
15-
payload NTEXT NOT NULL,
16-
created_by NVARCHAR(255) NOT NULL,
17-
updated_by NVARCHAR(255) NOT NULL,
18-
created_on DATETIME NOT NULL DEFAULT getdate(),
19-
updated_on DATETIME NULL
20-
);
21-
END
7+
BEGIN
8+
CREATE TABLE elr_raw
9+
(
10+
id UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(),
11+
message_type NVARCHAR(255) NOT NULL,
12+
payload NTEXT NOT NULL,
13+
created_by NVARCHAR(255) NOT NULL,
14+
updated_by NVARCHAR(255) NOT NULL,
15+
created_on DATETIME NOT NULL DEFAULT getdate(),
16+
updated_on DATETIME NULL
17+
);
18+
END
2219

23-
IF NOT EXISTS(
20+
IF
21+
NOT EXISTS(
2422
SELECT 'X'
2523
FROM INFORMATION_SCHEMA.TABLES
2624
WHERE TABLE_NAME = 'elr_validated')
27-
BEGIN
28-
CREATE TABLE elr_validated
29-
(
30-
id UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(),
31-
raw_message_id UNIQUEIDENTIFIER FOREIGN KEY REFERENCES elr_raw (id),
32-
message_type NVARCHAR(255) NOT NULL,
33-
message_version NVARCHAR(255),
34-
validated_message ntext NOT NULL,
35-
hashed_hl7_string varchar(64) NULL,
36-
created_by NVARCHAR(255) NOT NULL,
37-
updated_by NVARCHAR(255) NOT NULL,
38-
created_on DATETIME NOT NULL DEFAULT getdate(),
39-
updated_on DATETIME NULL
40-
);
41-
END
25+
BEGIN
26+
CREATE TABLE elr_validated
27+
(
28+
id UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(),
29+
raw_message_id UNIQUEIDENTIFIER FOREIGN KEY REFERENCES elr_raw (id),
30+
message_type NVARCHAR(255) NOT NULL,
31+
message_version NVARCHAR(255),
32+
validated_message ntext NOT NULL,
33+
hashed_hl7_string varchar(64) NULL,
34+
created_by NVARCHAR(255) NOT NULL,
35+
updated_by NVARCHAR(255) NOT NULL,
36+
created_on DATETIME NOT NULL DEFAULT getdate(),
37+
updated_on DATETIME NULL
38+
);
39+
END
4240

43-
IF NOT EXISTS(
41+
IF
42+
NOT EXISTS(
4443
SELECT 'X'
4544
FROM INFORMATION_SCHEMA.TABLES
4645
WHERE TABLE_NAME = 'elr_dlt')
47-
BEGIN
48-
CREATE TABLE elr_dlt
49-
(
50-
error_message_id UNIQUEIDENTIFIER PRIMARY KEY,
51-
error_message_source NVARCHAR(255) NOT NULL,
52-
error_stack_trace NVARCHAR(MAX) NOT NULL,
53-
error_stack_trace_short NVARCHAR(MAX) NOT NULL,
54-
dlt_status NVARCHAR(10) NOT NULL,
55-
dlt_occurrence INT,
56-
message ntext NOT NULL,
57-
created_by NVARCHAR(255) NOT NULL,
58-
updated_by NVARCHAR(255) NOT NULL,
59-
created_on DATETIME NOT NULL DEFAULT getdate(),
60-
updated_on DATETIME NULL
61-
);
62-
END
46+
BEGIN
47+
CREATE TABLE elr_dlt
48+
(
49+
error_message_id UNIQUEIDENTIFIER PRIMARY KEY,
50+
error_message_source NVARCHAR(255) NOT NULL,
51+
error_stack_trace NVARCHAR(MAX) NOT NULL,
52+
error_stack_trace_short NVARCHAR(MAX) NOT NULL,
53+
dlt_status NVARCHAR(10) NOT NULL,
54+
dlt_occurrence INT,
55+
message ntext NOT NULL,
56+
created_by NVARCHAR(255) NOT NULL,
57+
updated_by NVARCHAR(255) NOT NULL,
58+
created_on DATETIME NOT NULL DEFAULT getdate(),
59+
updated_on DATETIME NULL
60+
);
61+
END
62+
6363

64+
IF
65+
NOT EXISTS(
66+
SELECT 'X'
67+
FROM INFORMATION_SCHEMA.TABLES
68+
WHERE TABLE_NAME = 'elr_record_status_id')
69+
BEGIN
70+
CREATE TABLE elr_record_status_id
71+
(
72+
id UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(),
73+
raw_message_id UNIQUEIDENTIFIER FOREIGN KEY REFERENCES elr_raw (id),
74+
nbs_interface_id NVARCHAR(255) NOT NULL,
75+
created_by NVARCHAR(255) NOT NULL,
76+
updated_by NVARCHAR(255) NOT NULL,
77+
created_on DATETIME NOT NULL DEFAULT getdate(),
78+
updated_on DATETIME NULL
79+
);
80+
END
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
IF NOT EXISTS(
2-
SELECT 'X'
3-
FROM INFORMATION_SCHEMA.TABLES
4-
WHERE TABLE_NAME = 'elr_record_status_id')
5-
BEGIN
6-
CREATE TABLE elr_record_status_id
7-
(
8-
id UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(),
9-
raw_message_id UNIQUEIDENTIFIER FOREIGN KEY REFERENCES elr_raw (id),
10-
nbs_interface_id NVARCHAR(255) NOT NULL,
11-
created_by NVARCHAR(255) NOT NULL,
12-
updated_by NVARCHAR(255) NOT NULL,
13-
created_on DATETIME NOT NULL DEFAULT getdate(),
14-
updated_on DATETIME NULL
15-
);
16-
END
1+
USE NBS_DataIngest;
2+
ALTER TABLE NBS_DataIngest.dbo.elr_raw
3+
ADD version VARCHAR(1);
4+
5+
ALTER TABLE NBS_DataIngest.dbo.elr_dlt
6+
ALTER COLUMN dlt_status NVARCHAR(30);

data-ingestion-service/src/main/resources/db/di-service-003.sql

Lines changed: 0 additions & 3 deletions
This file was deleted.

data-ingestion-service/src/main/resources/db/di-service-004.sql

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)