Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sqlite database option #10

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 16 additions & 13 deletions medicines/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,29 @@ repositories {
}

dependencies {
implementation ('org.springframework.boot:spring-boot-starter-data-jpa')
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.postgresql:postgresql:42.7.3'
implementation 'org.mapstruct:mapstruct:1.5.5.Final'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
compileOnly 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'io.netty:netty-resolver-dns-native-macos:4.1.72.Final:osx-aarch_64'
implementation 'org.liquibase:liquibase-core:4.25.1'
implementation 'org.jsoup:jsoup:1.17.2'
implementation 'org.xhtmlrenderer:flying-saucer-pdf:9.5.1'
implementation 'com.itextpdf.tool:xmlworker:5.5.13.3'
implementation 'commons-io:commons-io:2.15.1'
implementation 'org.springframework.boot:spring-boot-starter-json:3.3.2'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.xerial:sqlite-jdbc:3.46.0.1'
implementation 'org.hibernate.orm:hibernate-community-dialects:6.4.2.Final'
implementation 'org.hibernate.orm:hibernate-core:6.4.2.Final'
annotationProcessor 'org.projectlombok:lombok'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: '3.2.1'
implementation 'io.netty:netty-resolver-dns-native-macos:4.1.72.Final:osx-aarch_64'
implementation group: 'org.liquibase', name: 'liquibase-core', version: '4.25.1'
implementation group: 'org.jsoup', name: 'jsoup', version: '1.17.2'
implementation group: 'org.xhtmlrenderer', name: 'flying-saucer-pdf', version: '9.5.1'
implementation group: 'com.itextpdf.tool', name: 'xmlworker', version: '5.5.13.3'
implementation group: 'commons-io', name: 'commons-io', version: '2.15.1'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-json', version: '3.2.3'
implementation 'org.springframework.boot:spring-boot-starter-aop:3.2.5'
compileOnly 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation group: 'com.h2database', name: 'h2', version: '2.2.224'
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '5.10.0'
testImplementation 'com.h2database:h2:2.3.230'
testImplementation 'org.mockito:mockito-junit-jupiter:5.12.0'
}

bootJar{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import jakarta.persistence.*;
import lombok.*;

import java.time.LocalTime;

@Entity
@Table(name = "day_periods")
@AllArgsConstructor
Expand All @@ -25,5 +23,5 @@ public class DayPeriod {
private Integer order;

@Column(name = "day_period_hour")
private LocalTime hour;
private String hour;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.nr.medicines.models.dto;

import lombok.Data;
import java.time.LocalTime;

@Data
public class DayPeriodRequest {
private String name;
private LocalTime hour;
}
private String hour;
}
5 changes: 5 additions & 0 deletions medicines/src/main/resources/application-postgres.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
spring.datasource.url=${DATASOURCE_URL}
spring.datasource.username=${DATASOURCE_USERNAME}
spring.datasource.password=${DATASOURCE_PWD}
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.open-in-view=false
12 changes: 12 additions & 0 deletions medicines/src/main/resources/application-sqlite.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
spring.application.name=sqlite
spring.datasource.url=jdbc:sqlite:medicines.db
spring.datasource.driver-class-name=org.sqlite.JDBC
spring.jpa.show-sql=false
spring.jpa.database-platform=org.hibernate.community.dialect.SQLiteDialect
hibernate.dialect=org.hibernate.community.dialect.SQLiteDialect
spring.jpa.properties.hibernate.dialect=org.hibernate.community.dialect.SQLiteDialect
spring.jpa.open-in-view=false

liquibase.shouldRun=true
liquibase.enable-logging=false
liquibase.autoCommit=true
9 changes: 3 additions & 6 deletions medicines/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Database
spring.datasource.url=${DATASOURCE_URL}
spring.datasource.username=${DATASOURCE_USERNAME}
spring.datasource.password=${DATASOURCE_PWD}
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.open-in-view=false
spring.profiles.default=postgres
spring.liquibase.contexts=${spring.profiles.active}

#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
#spring.jpa.show-sql=true

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE day_periods (
id SERIAL PRIMARY KEY,
description character varying,
display_order integer,
day_period_hour varchar(8)
);

INSERT INTO day_periods (description, display_order, day_period_hour) VALUES
('BEFORE BREAKFAST', 1, '08:00'),
('BREAKFAST', 2, '09:00'),
('LUNCH', 3, '13:00'),
('DINNER', 4, '20:00'),
('NIGHT', 5, '22:00');

SELECT SETVAL('day_periods_id_seq', (SELECT MAX(id) FROM day_periods));
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
CREATE TABLE day_periods (
id INTEGER PRIMARY KEY,
description character varying,
display_order integer,
day_period_hour varchar(8)
);

INSERT INTO day_periods (description, display_order, day_period_hour) VALUES
('BEFORE BREAKFAST', 1, '08:00:00'),
('BREAKFAST', 2, '09:00:00'),
('LUNCH', 3, '13:00:00'),
('DINNER', 4, '20:00:00'),
('NIGHT', 5, '22:00:00');
('BEFORE BREAKFAST', 1, '08:00'),
('BREAKFAST', 2, '09:00'),
('LUNCH', 3, '13:00'),
('DINNER', 4, '20:00'),
('NIGHT', 5, '22:00');
87 changes: 0 additions & 87 deletions medicines/src/main/resources/db/changelog/001-initial-schema.sql

This file was deleted.

61 changes: 61 additions & 0 deletions medicines/src/main/resources/db/changelog/002-initial-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
CREATE TABLE medicines (
barcode integer NOT NULL PRIMARY KEY,
"name" varchar NULL,
dosage varchar NULL,
generic bool NULL,
international_common_name varchar NULL,
form varchar NULL,
packaging_size varchar NULL
);

CREATE TABLE persons (
person_uuid uuid PRIMARY KEY,
name character varying
);

CREATE TABLE stock (
uuid uuid NOT NULL PRIMARY KEY,
medicine_barcode integer NOT NULL,
validity_end_date timestamp without time zone,
created timestamp without time zone,
person_uuid uuid NOT NULL,
FOREIGN KEY (medicine_barcode) REFERENCES medicines(barcode),
FOREIGN KEY (person_uuid) REFERENCES persons(person_uuid)
);

CREATE TABLE stock_notifications (
uuid uuid NOT NULL PRIMARY KEY,
stock_uuid uuid,
title character varying,
body character varying,
created timestamp without time zone,
FOREIGN KEY (stock_uuid) REFERENCES stock(uuid)
);

CREATE TABLE medicine_image (
medicine_image_uuid uuid PRIMARY KEY,
medicine_barcode integer,
image text,
created timestamp without time zone,
FOREIGN KEY (medicine_barcode) REFERENCES medicines(barcode)
);

CREATE TABLE regular_medication (
uuid uuid NOT NULL PRIMARY KEY,
medicine_barcode integer,
day_period_id integer,
created timestamp without time zone,
observations text,
person_uuid uuid NOT NULL,
FOREIGN KEY (day_period_id) REFERENCES day_periods(id),
FOREIGN KEY (person_uuid) REFERENCES persons(person_uuid)
);

CREATE TABLE temporary_medication (
uuid uuid PRIMARY KEY,
medication_uuid uuid,
days integer,
start_date timestamp without time zone,
FOREIGN KEY (medication_uuid) REFERENCES regular_medication(uuid)
);

43 changes: 37 additions & 6 deletions medicines/src/main/resources/db/master.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
databaseChangeLog:
- include:
file: classpath:/db/changelog/001-initial-schema.sql
- include:
file: classpath:/db/changelog/002-initial-data.sql
- include:
file: classpath:/db/changelog/003-day-periods-data.sql
- changeSet:
id: 1
author: admin
context: postgres
changes:
- sqlFile:
path: classpath:/db/changelog/001-day-periods-postgres.sql
endDelimiter: ";"
splitStatements: true

- changeSet:
id: 2
author: admin
context: sqlite
changes:
- sqlFile:
path: classpath:/db/changelog/001-day-periods-sqlite.sql
endDelimiter: ";"
splitStatements: true

- changeSet:
id: 3
author: admin
changes:
- sqlFile:
path: classpath:/db/changelog/002-initial-schema.sql
endDelimiter: ";"
splitStatements: true

- changeSet:
id: 4
author: admin
changes:
- sqlFile:
path: classpath:/db/changelog/003-initial-data.sql
endDelimiter: ";"
splitStatements: true