changeset 6:d57d0c6a841b

Einbau von liquibase zum Erzeugen des Schemas
author Dirk Olmes <dirk.olmes@codedo.de>
date Thu, 13 Aug 2020 16:18:20 +0200
parents 227f3105fedd
children 0c3494137a82
files spring-boot-playground/pom.xml spring-boot-playground/src/main/java/de/comline/spring/controller/MovieController.java spring-boot-playground/src/main/java/de/comline/spring/service/MovieService.java spring-boot-playground/src/main/resources/application.properties spring-boot-playground/src/main/resources/liquibase/changelog.xml
diffstat 5 files changed, 39 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/spring-boot-playground/pom.xml	Thu Aug 13 15:58:57 2020 +0200
+++ b/spring-boot-playground/pom.xml	Thu Aug 13 16:18:20 2020 +0200
@@ -46,6 +46,10 @@
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-data-jpa</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.liquibase</groupId>
+			<artifactId>liquibase-core</artifactId>
+		</dependency>
         <dependency>
             <groupId>com.h2database</groupId>
             <artifactId>h2</artifactId>
--- a/spring-boot-playground/src/main/java/de/comline/spring/controller/MovieController.java	Thu Aug 13 15:58:57 2020 +0200
+++ b/spring-boot-playground/src/main/java/de/comline/spring/controller/MovieController.java	Thu Aug 13 16:18:20 2020 +0200
@@ -1,6 +1,7 @@
 package de.comline.spring.controller;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -12,8 +13,13 @@
 	@Autowired
 	private MovieService service;
 	
+	@GetMapping("/movies")
+	public String getMovies() {
+		return service.listAllMovies();
+	}
+
 	@PostMapping("/movie/{title}")
-	public String index(@PathVariable(name = "title") String title) {
+	public String createMovie(@PathVariable(name = "title") String title) {
 		service.createMovie(title);
 		return "Successfully created movie " + title + ".\n";
 	}
--- a/spring-boot-playground/src/main/java/de/comline/spring/service/MovieService.java	Thu Aug 13 15:58:57 2020 +0200
+++ b/spring-boot-playground/src/main/java/de/comline/spring/service/MovieService.java	Thu Aug 13 16:18:20 2020 +0200
@@ -19,4 +19,11 @@
 		movie = repository.save(movie);
 		return movie;
 	}
+	
+	@Transactional
+	public String listAllMovies() {
+		StringBuilder buf = new StringBuilder(128);
+		repository.findAll().forEach(movie -> buf.append(movie.getTitle()).append(","));
+		return buf.toString();
+	}
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spring-boot-playground/src/main/resources/application.properties	Thu Aug 13 16:18:20 2020 +0200
@@ -0,0 +1,3 @@
+spring.datasource.url = jdbc:h2:~/unittest;AUTO_SERVER=true
+
+spring.liquibase.changelog = classpath:liquibase/changelog.xml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spring-boot-playground/src/main/resources/liquibase/changelog.xml	Thu Aug 13 16:18:20 2020 +0200
@@ -0,0 +1,18 @@
+<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.1.xsd">
+	
+	<changeSet id="create_table" author="olmes">
+		<createTable tableName="MOVIE">
+			<column name="ID" type="INT">
+				<constraints primaryKey="true"/>
+			</column>
+			<column name="TITLE" type="VARCHAR">
+			</column>
+		</createTable>
+	</changeSet>
+	<changeSet id="create_sequence" author="olmes">
+		<createSequence sequenceName="HIBERNATE_SEQUENCE"/>
+	</changeSet>
+</databaseChangeLog>