-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 553bd23
Showing
17 changed files
with
442 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>LibrarySpring</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<!-- Spring-boot-starter-parent - это специальный стартер, который обеспечивает значения по умолчанию Maven. | ||
Он также предоставляет раздел dependency-management (управления зависимостями), | ||
так что вы можете опустить теги version для общераспространенных зависимостей. --> | ||
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent --> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.5.5</version> | ||
</parent> | ||
|
||
<dependencies> | ||
|
||
<!-- Spring Boot — это проект, целью которого является упрощение создания приложений на основе Spring. | ||
Он позволяет наиболее простым способом создать web-приложение, | ||
требуя от разработчиков минимум усилий по его настройке и написанию кода --> | ||
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<!-- H2 — открытая кроссплатформенная СУБД, полностью написанная на языке Java --> | ||
<!-- https://mvnrepository.com/artifact/com.h2database/h2 --> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>${h2.version}</version> | ||
</dependency> | ||
|
||
<!-- Liquibase - это независимая от базы данных библиотека с открытым исходным кодом для отслеживания, | ||
управления и применения изменений схемы базы данных --> | ||
<!-- https://mvnrepository.com/artifact/org.liquibase/liquibase-core --> | ||
<dependency> | ||
<groupId>org.liquibase</groupId> | ||
<artifactId>liquibase-core</artifactId> | ||
<version>${liquibase.version}</version> | ||
</dependency> | ||
|
||
<!-- Spring Data — дополнительный удобный механизм для взаимодействия с сущностями базы данных, | ||
организации их в репозитории, извлечение данных, изменение --> | ||
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
|
||
<!-- Spring Web MVC — веб фреймворк, основанный на Servlet API и являющийся частью Spring framework. --> | ||
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<!-- SnakeYaml – это библиотека синтаксического анализа YAML с высокоуровневым | ||
API для сериализации и десериализации документов YAML --> | ||
<!-- https://mvnrepository.com/artifact/org.yaml/snakeyaml --> | ||
<dependency> | ||
<groupId>org.yaml</groupId> | ||
<artifactId>snakeyaml</artifactId> | ||
<version>${snakeyaml.version}</version> | ||
</dependency> | ||
|
||
<!-- Проект Lombok — это плагин компилятора, который добавляет в Java новые «ключевые слова» | ||
и превращает аннотации в Java-код, уменьшая усилия на разработку | ||
и обеспечивая некоторую дополнительную функциональность. --> | ||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
|
||
<!-- Spring Test это одна из библиотек, входящих в Spring Framework. | ||
Четыре главных задачи, которые решает библиотека это: | ||
1. Управлять Spring IoC контейнерами и их кэшированием между тестами | ||
2. Предоставить внедрение зависимостей для тестовых классов | ||
3. Предоставить управление транзакциями, подходящее для интеграционных тестов | ||
4. Предоставить набор базовых классов чтобы помочь разработчику писать интеграционные тесты --> | ||
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ru.tsutmb; | ||
|
||
import org.h2.tools.Console; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
import java.sql.SQLException; | ||
|
||
// url h2 консоли: http://localhost:8080/h2-console | ||
// url базы: jdbc:h2:mem:testdb | ||
|
||
@SpringBootApplication | ||
public class LibraryApp { | ||
|
||
public static void main(String[] args) { | ||
|
||
//Запуск SpringBoot-приложения и получение контекста | ||
ConfigurableApplicationContext context = SpringApplication.run(LibraryApp.class, args); | ||
// Author bean = context.getBean(Author.class); | ||
|
||
try { | ||
//Консоль для визуализации бд в браузере | ||
Console.main(args); | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Конфигурационный файл | ||
spring: | ||
|
||
# Подключение к H2 бд через jdbc | ||
datasource: | ||
url: jdbc:h2:mem:testdb | ||
|
||
# Включение консоли | ||
h2: | ||
console: | ||
#enabled: false | ||
enabled: true | ||
|
||
# Включение liquibase и установка основного файла | ||
liquibase: | ||
enabled: true | ||
change-log: classpath:db.changelog/db.changelog-master.xml | ||
|
||
jpa: | ||
|
||
# Отключаем автогенерацию схемы | ||
generate-ddl: false | ||
#generate-ddl: true | ||
|
||
hibernate: | ||
ddl-auto: none | ||
#ddl-auto: create-drop | ||
|
||
# Показываем запросы | ||
show-sql: true | ||
server: | ||
port : 8081 |
45 changes: 45 additions & 0 deletions
45
src/main/resources/db.changelog/1.0/2021-10-20--0001-book.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?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" | ||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd | ||
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> | ||
|
||
<changeSet id="2021-10-20--0001-book" author="akozadaev"> | ||
|
||
<!-- Проверяем нет ли уже таблицы с таким названием --> | ||
<preConditions onFail="MARK_RAN"> | ||
<not> | ||
<tableExists tableName="book"/> | ||
</not> | ||
</preConditions> | ||
|
||
<!-- Создаем таблицу --> | ||
<createTable tableName="book"> | ||
|
||
<!-- Описываем колонки --> | ||
<column name="id" | ||
type="NUMERIC(19,0)" | ||
autoIncrement="true"> | ||
<constraints primaryKey="true" nullable="false"/> | ||
</column> | ||
|
||
<column name="name" type="VARCHAR(100)"> | ||
<constraints nullable="false"/> | ||
</column> | ||
|
||
<column name="author_id" type="NUMERIC(19,0)"> | ||
<constraints nullable="false" foreignKeyName="fk_book_author" references="author(id)" | ||
deleteCascade="true"/> | ||
</column> | ||
|
||
<column name="genre_id" type="NUMERIC(19,0)"> | ||
<constraints nullable="false" foreignKeyName="fk_book_genre" references="genre(id)" | ||
deleteCascade="true"/> | ||
</column> | ||
</createTable> | ||
|
||
</changeSet> | ||
|
||
|
||
</databaseChangeLog> |
35 changes: 35 additions & 0 deletions
35
src/main/resources/db.changelog/1.0/2021-10-20--0002-genre.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?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" | ||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd | ||
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> | ||
|
||
<changeSet id="2021-10-20--0002-genre" author="akozadaev"> | ||
|
||
<!-- Проверяем нет ли уже таблицы с таким названием --> | ||
<preConditions onFail="MARK_RAN"> | ||
<not> | ||
<tableExists tableName="genre"/> | ||
</not> | ||
</preConditions> | ||
|
||
<!-- Создаем таблицу --> | ||
<createTable tableName="genre"> | ||
|
||
<!-- Описываем колонки --> | ||
<column name="id" | ||
type="NUMERIC(19,0)" | ||
autoIncrement="true"> | ||
<constraints primaryKey="true" nullable="false"/> | ||
</column> | ||
|
||
<column name="name" type="VARCHAR(100)"> | ||
<constraints nullable="false"/> | ||
</column> | ||
</createTable> | ||
|
||
</changeSet> | ||
|
||
|
||
</databaseChangeLog> |
35 changes: 35 additions & 0 deletions
35
src/main/resources/db.changelog/1.0/2021-10-20--0003-author.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?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" | ||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd | ||
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> | ||
|
||
<changeSet id="2021-10-20--0003-author" author="akozadaev"> | ||
|
||
<!-- Проверяем нет ли уже таблицы с таким названием --> | ||
<preConditions onFail="MARK_RAN"> | ||
<not> | ||
<tableExists tableName="author"/> | ||
</not> | ||
</preConditions> | ||
|
||
<!-- Создаем таблицу --> | ||
<createTable tableName="author"> | ||
|
||
<!-- Описываем колонки --> | ||
<column name="id" | ||
type="NUMERIC(19,0)" | ||
autoIncrement="true"> | ||
<constraints primaryKey="true" nullable="false"/> | ||
</column> | ||
|
||
<column name="name" type="VARCHAR(100)"> | ||
<constraints nullable="false"/> | ||
</column> | ||
</createTable> | ||
|
||
</changeSet> | ||
|
||
|
||
</databaseChangeLog> |
40 changes: 40 additions & 0 deletions
40
src/main/resources/db.changelog/1.0/2021-11-18--0004-comment.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?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" | ||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd | ||
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> | ||
|
||
<changeSet id="2021-11-18--0004-comment" author="akozadaev"> | ||
|
||
<!-- Проверяем нет ли уже таблицы с таким названием --> | ||
<preConditions onFail="MARK_RAN"> | ||
<not> | ||
<tableExists tableName="comment"/> | ||
</not> | ||
</preConditions> | ||
|
||
<!-- Создаем таблицу --> | ||
<createTable tableName="comment"> | ||
|
||
<!-- Описываем колонки --> | ||
<column name="id" | ||
type="NUMERIC(19,0)" | ||
autoIncrement="true"> | ||
<constraints primaryKey="true" nullable="false"/> | ||
</column> | ||
|
||
<column name="content" type="VARCHAR(100)"> | ||
<constraints nullable="false"/> | ||
</column> | ||
|
||
<column name="book_id" type="NUMERIC(19,0)"> | ||
<constraints nullable="false" foreignKeyName="fk_comment_book" references="book(id)" | ||
deleteCascade="true"/> | ||
</column> | ||
</createTable> | ||
|
||
</changeSet> | ||
|
||
|
||
</databaseChangeLog> |
16 changes: 16 additions & 0 deletions
16
src/main/resources/db.changelog/data/2021-10-20--0001-book-data.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?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" | ||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd | ||
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> | ||
|
||
<changeSet id="2021-10-20--0001-book-data" author="akozadaev" context="test" runOnChange="true" > | ||
<!-- Наполняем данными из csv --> | ||
<loadData tableName="book" file="db.changelog/data/csv/2021-10-20--0001-book-data.csv" | ||
separator=";" | ||
quotchar='"' | ||
encoding="UTF-8"/> | ||
|
||
</changeSet> | ||
</databaseChangeLog> |
16 changes: 16 additions & 0 deletions
16
src/main/resources/db.changelog/data/2021-10-20--0002-author-data.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?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" | ||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd | ||
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> | ||
|
||
<changeSet id="2021-10-20--0002-author-data" author="akozadaev" context="test" runOnChange="true" > | ||
<!-- Наполняем данными из csv --> | ||
<loadData tableName="author" file="db.changelog/data/csv/2021-10-20--0002-author-data.csv" | ||
separator=";" | ||
quotchar='"' | ||
encoding="UTF-8"/> | ||
|
||
</changeSet> | ||
</databaseChangeLog> |
16 changes: 16 additions & 0 deletions
16
src/main/resources/db.changelog/data/2021-10-20--0003-genre-data.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?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" | ||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd | ||
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> | ||
|
||
<changeSet id="2021-10-20--0003-genre-data" author="akozadaev" context="test" runOnChange="true" > | ||
<!-- Наполняем данными из csv --> | ||
<loadData tableName="genre" file="db.changelog/data/csv/2021-10-20--0003-genre-data.csv" | ||
separator=";" | ||
quotchar='"' | ||
encoding="UTF-8"/> | ||
|
||
</changeSet> | ||
</databaseChangeLog> |
16 changes: 16 additions & 0 deletions
16
src/main/resources/db.changelog/data/2021-11-18--0004-comment-data.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?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" | ||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd | ||
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> | ||
|
||
<changeSet id="2021-11-18--0004-comment-data" author="akozadaev" context="test" runOnChange="true" > | ||
<!-- Наполняем данными из csv --> | ||
<loadData tableName="comment" file="db.changelog/data/csv/2021-11-18--0004-comment-data.csv" | ||
separator=";" | ||
quotchar='"' | ||
encoding="UTF-8"/> | ||
|
||
</changeSet> | ||
</databaseChangeLog> |
Oops, something went wrong.