-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
92bf516
commit ed0079c
Showing
14 changed files
with
308 additions
and
14 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
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
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,135 @@ | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>tech.ydb.jdbc.examples</groupId> | ||
<artifactId>ydb-jdbc-examples</artifactId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>spring-flyway-app</artifactId> | ||
<name>Spring Flyway Example</name> | ||
<description>Basic example for SpringBoot3 and Flyway</description> | ||
<properties> | ||
<maven.compiler.release>17</maven.compiler.release> | ||
<kotlin.version>1.9.22</kotlin.version> | ||
<hibernate.ydb.dialect.version>0.9.2</hibernate.ydb.dialect.version> | ||
<spring.boot.version>3.2.1</spring.boot.version> | ||
<flyway.ydb.dialect.version>1.0.0-RC0</flyway.ydb.dialect.version> | ||
<flyway.core.version>10.7.1</flyway.core.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
<version>${spring.boot.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.data</groupId> | ||
<artifactId>spring-data-commons</artifactId> | ||
<version>${spring.boot.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-reflect</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>tech.ydb.dialects</groupId> | ||
<artifactId>hibernate-ydb-dialect</artifactId> | ||
<version>${hibernate.ydb.dialect.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>tech.ydb.jdbc</groupId> | ||
<artifactId>ydb-jdbc-driver-shaded</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>tech.ydb.dialects</groupId> | ||
<artifactId>flyway-ydb-dialect</artifactId> | ||
<version>${flyway.ydb.dialect.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.flywaydb</groupId> | ||
<artifactId>flyway-core</artifactId> | ||
<version>10.7.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<version>${spring.boot.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>tech.ydb.test</groupId> | ||
<artifactId>ydb-junit5-support</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory> | ||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<environmentVariables> | ||
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE> | ||
</environmentVariables> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>${spring.boot.version}</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>${kotlin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>test-compile</id> | ||
<goals> | ||
<goal>test-compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<args> | ||
<arg>-Xjsr305=strict</arg> | ||
</args> | ||
<compilerPlugins> | ||
<plugin>spring</plugin> | ||
<plugin>jpa</plugin> | ||
</compilerPlugins> | ||
</configuration> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-allopen</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-noarg</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
9 changes: 9 additions & 0 deletions
9
jdbc/spring-flyway-app/src/main/kotlin/tech/ydb/liquibase/FlywayApplication.kt
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,9 @@ | ||
package tech.ydb.liquibase | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
|
||
/** | ||
* @author Kirill Kurdyukov | ||
*/ | ||
@SpringBootApplication | ||
class FlywayApplication |
39 changes: 39 additions & 0 deletions
39
jdbc/spring-flyway-app/src/main/kotlin/tech/ydb/liquibase/model/Employee.kt
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,39 @@ | ||
package tech.ydb.liquibase.model | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Table | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
@Entity | ||
@Table(name = "employee") | ||
data class Employee( | ||
@Id | ||
val id: Long, | ||
|
||
@Column(name = "full_name") | ||
val fullName: String, | ||
|
||
@Column | ||
val email: String, | ||
|
||
@Column(name = "hire_date") | ||
val hireDate: LocalDate, | ||
|
||
@Column | ||
val salary: java.math.BigDecimal, | ||
|
||
@Column(name = "is_active") | ||
val isActive: Boolean, | ||
|
||
@Column | ||
val department: String, | ||
|
||
@Column | ||
val age: Int, | ||
|
||
@Column(name = "limit_date_password") | ||
val limitDatePassword: LocalDateTime, | ||
) |
8 changes: 8 additions & 0 deletions
8
jdbc/spring-flyway-app/src/main/kotlin/tech/ydb/liquibase/repository/EmployeeRepository.kt
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,8 @@ | ||
package tech.ydb.liquibase.repository | ||
|
||
import org.springframework.data.repository.CrudRepository | ||
import tech.ydb.liquibase.model.Employee | ||
|
||
interface EmployeeRepository : CrudRepository<Employee, Long> | ||
|
||
fun EmployeeRepository.findByIdOrNull(id: Long): Employee? = this.findById(id).orElse(null) |
4 changes: 4 additions & 0 deletions
4
jdbc/spring-flyway-app/src/main/resources/application.properties
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,4 @@ | ||
spring.jpa.properties.hibernate.dialect=tech.ydb.hibernate.dialect.YdbDialect | ||
|
||
spring.datasource.driver-class-name=tech.ydb.jdbc.YdbDriver | ||
spring.datasource.url=jdbc:ydb:grpc://localhost:2136/local |
1 change: 1 addition & 0 deletions
1
jdbc/spring-flyway-app/src/main/resources/db/migration/V1.1__create_index_employee_email.sql
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 @@ | ||
ALTER TABLE employee ADD INDEX email_employee_index GLOBAL ON (email) |
14 changes: 14 additions & 0 deletions
14
jdbc/spring-flyway-app/src/main/resources/db/migration/V1__create_employee.sql
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,14 @@ | ||
CREATE TABLE employee | ||
( | ||
id Int64 NOT NULL, | ||
full_name Text, | ||
email Text, | ||
hire_date Date, | ||
salary Decimal(22, 9), | ||
is_active Bool, | ||
department Text, | ||
age Int32, | ||
limit_date_password Datetime, | ||
|
||
PRIMARY KEY (id) | ||
) |
70 changes: 70 additions & 0 deletions
70
jdbc/spring-flyway-app/src/test/kotlin/tech/ydb/liquibase/YdbFlywayTest.kt
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,70 @@ | ||
package tech.ydb.liquibase | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertNull | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.context.DynamicPropertyRegistry | ||
import org.springframework.test.context.DynamicPropertySource | ||
import tech.ydb.liquibase.model.Employee | ||
import tech.ydb.liquibase.repository.EmployeeRepository | ||
import tech.ydb.liquibase.repository.findByIdOrNull | ||
import tech.ydb.test.junit5.YdbHelperExtension | ||
import java.math.BigDecimal | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
import java.time.Month | ||
import java.time.ZoneId | ||
import java.util.* | ||
|
||
/** | ||
* @author Kirill Kurdyukov | ||
*/ | ||
@SpringBootTest | ||
class YdbFlywayTest { | ||
|
||
companion object { | ||
@JvmField | ||
@RegisterExtension | ||
val ydb = YdbHelperExtension() | ||
|
||
@JvmStatic | ||
@DynamicPropertySource | ||
fun propertySource(registry: DynamicPropertyRegistry) { | ||
registry.add("spring.datasource.url") { | ||
"jdbc:ydb:${if (ydb.useTls()) "grpcs://" else "grpc://"}" + | ||
"${ydb.endpoint()}${ydb.database()}${ydb.authToken()?.let { "?token=$it" } ?: ""}" | ||
} | ||
} | ||
} | ||
|
||
@Autowired | ||
lateinit var employeeRepository: EmployeeRepository | ||
|
||
@Test | ||
fun `migration flyway and CRUD actions`() { | ||
TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("UTC"))) | ||
|
||
val employee = Employee( | ||
1, | ||
"Kirill Kurdyukov", | ||
"[email protected]", | ||
LocalDate.parse("2023-12-20"), | ||
BigDecimal("500000.000000000"), | ||
true, | ||
"YDB AppTeam", | ||
23, | ||
LocalDateTime.of(2021, Month.JUNE, 2, 12, 12), | ||
) | ||
|
||
employeeRepository.save(employee) | ||
|
||
assertEquals(employee, employeeRepository.findByIdOrNull(employee.id)) | ||
|
||
employeeRepository.delete(employee) | ||
|
||
assertNull(employeeRepository.findByIdOrNull(employee.id)) | ||
} | ||
} |
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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d %5p %40.40c:%4L - %m%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<!-- https://www.testcontainers.org/supported_docker_environment/logging_config/ --> | ||
<logger name="org.testcontainers" level="warn" /> | ||
<logger name="com.github.dockerjava" level="warn"/> | ||
<logger name="com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.wire" level="off"/> | ||
|
||
<logger name="org.hibernate.SQL" additivity="true" level="debug" /> | ||
|
||
<root level="info"> | ||
<appender-ref ref="console" /> | ||
</root> | ||
</configuration> |
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
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
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