Skip to content

Commit 749a6cd

Browse files
committed
add liquibase config
1 parent a6a5516 commit 749a6cd

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

pom.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@
9595
<scope>"runtime</scope>
9696
</dependency>
9797

98+
<dependency>
99+
<groupId>io.micronaut.liquibase</groupId>
100+
<artifactId>micronaut-liquibase</artifactId>
101+
</dependency>
98102
</dependencies>
99103

100104
<build>
@@ -109,7 +113,7 @@
109113
<artifactId>maven-compiler-plugin</artifactId>
110114
<configuration>
111115
<!-- Uncomment to enable incremental compilation -->
112-
<!-- <useIncrementalCompilation>false</useIncrementalCompilation> -->
116+
<!-- <useIncrementalCompilation>false</useIncrementalCompilation>-->
113117

114118
<annotationProcessorPaths combine.children="append">
115119
<path>

src/main/java/com/example/Pen.java renamed to src/main/java/com/example/Book.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
import javax.persistence.*;
44

55
@Entity
6-
public class Pen {
6+
@Table(name = "books")
7+
public class Book {
78
@Id
8-
@GeneratedValue(strategy = GenerationType.SEQUENCE)
9+
@GeneratedValue(strategy = GenerationType.IDENTITY)
910
private Long id;
1011
private String title;
1112
private int pages;
1213

13-
public Pen(String title, int pages) {
14+
public Book(String title, int pages) {
1415
this.title = title;
1516
this.pages = pages;
1617
}
1718

18-
public Pen() {
19+
public Book() {
1920
}
2021

2122
public Long getId() {

src/main/java/com/example/BookController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void init() {
1818
}
1919

2020
@Get("/books")
21-
public List<Pen> books() {
21+
public List<Book> books() {
2222
return service.findAll();
2323
}
2424

src/main/java/com/example/BookRepository.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
package com.example;
22

3-
import io.micronaut.core.annotation.NonNull;
43
import io.micronaut.context.annotation.Executable;
54
import io.micronaut.data.annotation.*;
6-
import io.micronaut.data.model.*;
75
import io.micronaut.data.repository.CrudRepository;
86

9-
import javax.validation.Valid;
10-
import javax.validation.constraints.NotNull;
11-
import java.util.List;
12-
137
@Repository //
14-
interface BookRepository extends CrudRepository<Pen, Long> {
8+
interface BookRepository extends CrudRepository<Book, Long> {
159

1610
@Executable
17-
Pen find(String title);
11+
Book find(String title);
1812

1913

2014

src/main/java/com/example/BookService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ public class BookService {
1515

1616
public void initDataBase(){
1717

18-
Pen book = new Pen();
18+
Book book = new Book();
1919
book.setTitle("The Stand");
2020
book.setPages(1000);
2121
repository.save(book);
2222
}
2323

24-
public List<Pen> findAll(){
24+
public List<Book> findAll(){
2525

26-
return (List<Pen>) repository.findAll();
26+
return (List<Book>) repository.findAll();
2727
}
2828
}

src/main/resources/application.yml

+10-9
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ netty:
88

99
datasources:
1010
default:
11-
url: jdbc:h2:mem:devDb
12-
driverClassName: org.h2.Driver
13-
username: sa
11+
url: 'jdbc:h2:mem:liquibaseDisabledDb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE'
12+
username: 'sa'
1413
password: ''
15-
schema-generate: CREATE_DROP
16-
dialect: H2
17-
14+
driverClassName: 'org.h2.Driver'
1815
jpa:
1916
default:
20-
entity-scan:
21-
packages: 'com.example'
17+
packages-to-scan:
18+
- 'com.example'
2219
properties:
2320
hibernate:
2421
hbm2ddl:
2522
auto: update
26-
show_sql: true
23+
show_sql: true
24+
liquibase:
25+
datasources:
26+
default:
27+
change-log: 'classpath:db/liquibase-changelog.xml'

0 commit comments

Comments
 (0)