Skip to content

Commit

Permalink
feat: adapt new database for messageservice
Browse files Browse the repository at this point in the history
BREAKING CHANGE: creating a new database for messageservice is required
  • Loading branch information
mebo4b committed Oct 29, 2020
1 parent fb39ee2 commit e60c87a
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 8 deletions.
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,6 @@
<version>2.3.0</version>
</dependency>

<!-- Test scope dependencies -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package de.caritas.cob.messageservice.api.model.entity;

import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "draftmessage")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DraftMessage {

@Id
@SequenceGenerator(name = "id_seq", allocationSize = 1, sequenceName = "sequence_draftmessage")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_seq")
@Column(name = "id", updatable = false, nullable = false)
private Long id;

@Column(name = "user_id", nullable = false)
private String userId;

@Column(name = "rc_group_id", nullable = false)
private String rcGroupId;

@Column(name = "draft_message", nullable = false)
private String message;

@Column(name = "create_date", nullable = false)
private LocalDateTime createDate;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.caritas.cob.messageservice.api.repository;

import de.caritas.cob.messageservice.api.model.entity.DraftMessage;
import org.springframework.data.repository.CrudRepository;

public interface DraftMessageRepository extends CrudRepository<DraftMessage, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ protected void configure(HttpSecurity http) throws Exception {
.hasAnyAuthority(Authority.USER_DEFAULT, Authority.CONSULTANT_DEFAULT,
Authority.TECHNICAL_DEFAULT)
.antMatchers("/messages/forward").hasAnyAuthority(Authority.USE_FEEDBACK)
.antMatchers("/messages/feedback/new").hasAnyAuthority(Authority.USE_FEEDBACK).anyRequest()
.antMatchers("/messages/feedback/new").hasAnyAuthority(Authority.USE_FEEDBACK)
.antMatchers("/messages/draft").hasAnyAuthority(Authority.USER_DEFAULT, Authority.CONSULTANT_DEFAULT)
.anyRequest()
.denyAll();
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@ user.service.api.liveproxy.url=<containername>:<port>
# CSRF token
csrf.header.property=
csrf.cookie.property=

# LIQUIBASE (LiquibaseProperties)
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDB103Dialect
spring.liquibase.change-log=classpath:db/changelog/messageservice-local-master.xml
spring.liquibase.user=
spring.liquibase.password=
spring.liquibase.default-schema=messageservice
11 changes: 11 additions & 0 deletions src/main/resources/db/changelog/changeset/0001_initsql/initSql.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
<changeSet author="initialSetup" id="initSql-tables">
<sqlFile path="db/changelog/changeset/0001_initsql/initTables.sql" stripComments="true" />
<rollback><sql/></rollback>
</changeSet>
<changeSet author="initialSetup" id="initSql-trigger">
<sqlFile endDelimiter="//" path="db/changelog/changeset/0001_initsql/initTrigger.sql" stripComments="true" />
<rollback><sql/></rollback>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE messageservice.`draftmessage` (
`id` bigint(21) NOT NULL,
`user_id` varchar(36) COLLATE utf8_unicode_ci NOT NULL,
`rc_group_id` varchar(255) NOT NULL,
`draft_message` longtext COLLATE utf8_unicode_ci NOT NULL,
`create_date` datetime NOT NULL DEFAULT UTC_TIMESTAMP(),
`update_date` datetime NOT NULL DEFAULT UTC_TIMESTAMP(),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE SEQUENCE messageservice.sequence_draftmessage
INCREMENT BY 1
MINVALUE = 0
NOMAXVALUE
START WITH 0
CACHE 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TRIGGER messageservice.`message_update` BEFORE UPDATE ON messageservice.`draftmessage` FOR EACH
ROW BEGIN
set new.update_date=utc_timestamp();
END //
10 changes: 10 additions & 0 deletions src/main/resources/db/changelog/messageservice-dev-master.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd">

<!-- The base changeset contains the database state when liquibase was added to the project -->
<include file="db/changelog/changeset/0001_initsql/initSql.xml"/>
</databaseChangeLog>
10 changes: 10 additions & 0 deletions src/main/resources/db/changelog/messageservice-local-master.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd">

<!-- The base changeset contains the database state when liquibase was added to the project -->
<include file="db/changelog/changeset/0001_initsql/initSql.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd">
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd">
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd">

<!-- PLEASE LEAVE THIS FILE EMPTY -->
</databaseChangeLog>

0 comments on commit e60c87a

Please sign in to comment.