Skip to content

Commit 761212a

Browse files
committed
add db migration
1 parent 3a04043 commit 761212a

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/main/java/com/example/Book.java

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class Book {
1111
private String title;
1212
private int pages;
1313

14+
private int year;
15+
1416
public Book(String title, int pages) {
1517
this.title = title;
1618
this.pages = pages;
@@ -42,4 +44,12 @@ public int getPages() {
4244
public void setPages(int pages) {
4345
this.pages = pages;
4446
}
47+
48+
public int getYear() {
49+
return year;
50+
}
51+
52+
public void setYear(int year) {
53+
this.year = year;
54+
}
4555
}

src/main/resources/db/liquibase-changelog.xml

+40-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,46 @@
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
77
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
8-
<changeSet id="01" author="tsiupa">
8+
<changeSet id="001" author="ivan_tsiupa">
9+
<sql>
10+
CREATE TABLE IF NOT EXISTS books
11+
(
12+
id BIGSERIAL NOT NULL,
13+
title TEXT NOT NULL,
14+
pages BIGINT NOT NULL,
15+
PRIMARY KEY (id)
16+
);
917

18+
</sql>
19+
</changeSet>
20+
21+
<changeSet id="002" author="ivan_tsiupa">
22+
<sql>
23+
INSERT INTO books(title, pages) VALUES('Philosophers Stone', 200);
24+
INSERT INTO books(title, pages) VALUES('Chamber of Secrets', 233);
25+
INSERT INTO books(title, pages) VALUES('Prisoner of Azkaban', 146);
26+
INSERT INTO books(title, pages) VALUES('Goblet of Fire', 342);
27+
INSERT INTO books(title, pages) VALUES('Order of the Phoenix', 146);
28+
INSERT INTO books(title, pages) VALUES('Half-Blood Prince', 342);
29+
INSERT INTO books(title, pages) VALUES('Deathly Hallows', 342);
30+
</sql>
31+
</changeSet>
32+
33+
<changeSet id="003" author="ivan_tsiupa">
34+
<sql>
35+
ALTER TABLE books ADD year BIGINT DEFAULT 0 NOT NULL;
36+
</sql>
37+
</changeSet>
38+
39+
<changeSet id="004" author="ivan_tsiupa">
40+
<sql>
41+
UPDATE books SET year = 1997 WHERE title = 'Philosophers Stone';
42+
UPDATE books SET year = 1998 WHERE title = 'Chamber of Secrets';
43+
UPDATE books SET year = 1999 WHERE title = 'Prisoner of Azkaban';
44+
UPDATE books SET year = 2000 WHERE title = 'Goblet of Fire';
45+
UPDATE books SET year = 2003 WHERE title = 'Order of the Phoenix';
46+
UPDATE books SET year = 2005 WHERE title = 'Half-Blood Prince';
47+
UPDATE books SET year = 2007 WHERE title = 'Deathly Hallows';
48+
</sql>
1049
</changeSet>
1150
</databaseChangeLog>

0 commit comments

Comments
 (0)