Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
alex268 committed Mar 19, 2024
2 parents d2fce14 + 35ce0d2 commit d302bea
Show file tree
Hide file tree
Showing 11 changed files with 335 additions and 2 deletions.
1 change: 1 addition & 0 deletions jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
</activation>
<modules>
<module>spring-data-jpa</module>
<module>spring-liquibase-app</module>
</modules>
</profile>
</profiles>
Expand Down
2 changes: 1 addition & 1 deletion jdbc/spring-data-jpa-v5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<description>Basic example for SpringBoot3 and Hibernate 6</description>
<properties>
<kotlin.version>1.9.22</kotlin.version>
<hibernate.ydb.dialect.version>0.9.1</hibernate.ydb.dialect.version>
<hibernate.ydb.dialect.version>0.9.2</hibernate.ydb.dialect.version>
<spring.boot.version>2.5.7</spring.boot.version>
</properties>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion jdbc/spring-data-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<properties>
<maven.compiler.release>17</maven.compiler.release>
<kotlin.version>1.9.22</kotlin.version>
<hibernate.ydb.dialect.version>0.9.1</hibernate.ydb.dialect.version>
<hibernate.ydb.dialect.version>0.9.2</hibernate.ydb.dialect.version>
<spring.boot.version>3.2.1</spring.boot.version>
</properties>
<dependencies>
Expand Down
140 changes: 140 additions & 0 deletions jdbc/spring-liquibase-app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<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-liquibase-app</artifactId>
<name>Spring Liquibase Example</name>
<description>Basic example for SpringBoot3 and Liquibase</description>
<properties>
<maven.compiler.release>17</maven.compiler.release>
<kotlin.version>1.9.22</kotlin.version>
<hibernate.ydb.dialect.version>0.9.1</hibernate.ydb.dialect.version>
<spring.boot.version>3.2.1</spring.boot.version>
<liquibase.ydb.dialect.version>0.9.1</liquibase.ydb.dialect.version>
<liquibase.core.version>4.24.0</liquibase.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>liquibase-ydb-dialect</artifactId>
<version>0.9.7</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.core.version}</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>
<exclusions>
<exclusion>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</exclusion>
</exclusions>
</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>
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 LiquibaseApplication
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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,
)
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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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

spring.liquibase.change-log=classpath:changelog.yaml

logging.level.liquibase=DEBUG
45 changes: 45 additions & 0 deletions jdbc/spring-liquibase-app/src/main/resources/changelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
databaseChangeLog:
- changeSet:
id: "employee"
author: "kurdyukov-kir"
changes:
- createTable:
tableName: employee
columns:
- column:
name: id
type: bigint
constraints:
primaryKey: true
nullable: false
- column:
name: full_name
type: varchar
- column:
name: email
type: varchar
- column:
name: hire_date
type: date
- column:
name: salary
type: decimal(22,9)
- column:
name: is_active
type: boolean
- column:
name: department
type: varchar
- column:
name: age
type: int
- column:
name: limit_date_password
type: datetime
- createIndex:
indexName: idx_employee_email
tableName: employee
unique: false
columns:
- column:
name: email
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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.ZoneId
import java.util.*

/**
* @author Kirill Kurdyukov
*/
@SpringBootTest
class YdbLiquibaseTest {

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 liquibase 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
)

employeeRepository.save(employee)

assertEquals(employee, employeeRepository.findByIdOrNull(employee.id))

employeeRepository.delete(employee)

assertNull(employeeRepository.findByIdOrNull(employee.id))
}
}
19 changes: 19 additions & 0 deletions jdbc/spring-liquibase-app/src/test/resources/logback.xml
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>

0 comments on commit d302bea

Please sign in to comment.