Skip to content

Commit

Permalink
feat: support UUID type (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillKurdyukov authored Nov 8, 2024
1 parent e940f1d commit 0d73497
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 20 deletions.
4 changes: 4 additions & 0 deletions liquibase-dialect/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0 ##

* Supported UUID type in .xml, .yaml, and .json formats

## 1.0.2 ##

* Added duration format for `Interval` type and ISO for time types when loading data into tables
Expand Down
6 changes: 3 additions & 3 deletions liquibase-dialect/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>tech.ydb.dialects</groupId>
<artifactId>liquibase-ydb-dialect</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.0</version>

<name>Liquibase YDB Dialect</name>
<description>Support Liquibase YDB Dialect</description>
Expand Down Expand Up @@ -43,7 +43,7 @@
<maven.compiler.source>1.8</maven.compiler.source>

<liquibase.core.version>4.24.0</liquibase.core.version>
<ydb.jdbc.version>2.2.0</ydb.jdbc.version>
<ydb.jdbc.version>2.3.3</ydb.jdbc.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -119,7 +119,7 @@
<configuration>
<environmentVariables>
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
<YDB_DOCKER_IMAGE>cr.yandex/yc/yandex-docker-local-ydb:24.1</YDB_DOCKER_IMAGE>
<YDB_DOCKER_IMAGE>cr.yandex/yc/yandex-docker-local-ydb:trunk</YDB_DOCKER_IMAGE>
</environmentVariables>
<systemPropertyVariables>
<java.util.logging.config.file>src/test/resources/logging.properties</java.util.logging.config.file>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tech.ydb.liquibase.type;

import liquibase.change.core.LoadDataChange;
import liquibase.datatype.DataTypeInfo;
import liquibase.datatype.LiquibaseDataType;

/**
* @author Kirill Kurdyukov
*/
@DataTypeInfo(
name = "UUID",
aliases = {"uniqueidentifier", "java.util.UUID"},
minParameters = 0,
maxParameters = 0,
priority = LiquibaseDataType.PRIORITY_DATABASE
)
public class UuidTypeYdb extends BaseTypeYdb {

@Override
public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() {
return LoadDataChange.LOAD_DATA_TYPE.UUID;
}

@Override
protected String objectToSql(Object value) {
return "Uuid('" + value + "')";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ tech.ydb.liquibase.type.TinyIntTypeYdb
tech.ydb.liquibase.type.Uint8TypeYdb
tech.ydb.liquibase.type.Uint16TypeYdb
tech.ydb.liquibase.type.Uint32TypeYdb
tech.ydb.liquibase.type.Uint64TypeYdb
tech.ydb.liquibase.type.Uint64TypeYdb
tech.ydb.liquibase.type.UuidTypeYdb
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ void changeLogLoadCSVFileTest() throws SQLException, LiquibaseException {
assertTrue(migrationStr.contains("UPSERT INTO all_types_table (id, bool_column, bigint_column, smallint_column, " +
"tinyint_column, float_column, double_column, decimal_column, uint8_column, " +
"uint16_column, uint32_column, uint64_column, text_column, binary_column, json_column, " +
"jsondocument_column, date_column, datetime_column, timestamp_column, interval_column) VALUES " +
"jsondocument_column, date_column, datetime_column, timestamp_column, interval_column, uuid_column) VALUES " +
"('1', 'true', '123123', '13000', '113', '1.123', '1.123123', '1.123123', '12', '13', '14', " +
"'15', 'Кирилл Курдюков Алексеевич', 'binary', '{\"asd\": \"asd\"}', '{\"asd\": \"asd\"}', " +
"'2014-04-06', '2023-09-16T12:30', '2023-07-31T17:00:00.000000Z', 'PT10S');"
"'2014-04-06', '2023-09-16T12:30', '2023-07-31T17:00:00.000000Z', 'PT10S', '689fd2b6-5764-4c43-8803-519da8f5f305');"
));

assertTrue(migrationStr.contains("UPSERT INTO all_types_table (id, bool_column, bigint_column, smallint_column, " +
"tinyint_column, float_column, double_column, decimal_column, uint8_column, " +
"uint16_column, uint32_column, uint64_column, text_column, binary_column, json_column, " +
"jsondocument_column, date_column, datetime_column, timestamp_column, interval_column) VALUES " +
"jsondocument_column, date_column, datetime_column, timestamp_column, interval_column, uuid_column) VALUES " +
"('5', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, " +
"NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);"
"NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);"
));

assertTrue(migrationStr.contains("INSERT INTO all_types_table (id, bool_column, bigint_column, smallint_column, " +
"tinyint_column, float_column, double_column, decimal_column, uint8_column, uint16_column, " +
"uint32_column, uint64_column, text_column, binary_column, json_column, jsondocument_column, " +
"date_column, datetime_column, timestamp_column, interval_column) VALUES " +
"date_column, datetime_column, timestamp_column, interval_column, uuid_column) VALUES " +
"('2', 'true', '123123', '13000', '112', '1.123', '1.123123', '1.123123', '12', '13', " +
"'14', '15', 'Кирилл Курдюков Алексеевич', 'binary', '{\"asd\": \"asd\"}', '{\"asd\": \"asd\"}', " +
"'2014-04-06', '2023-09-16T12:30', '2023-07-31T17:00:00.000000Z', 'PT10S'), " +
"'2014-04-06', '2023-09-16T12:30', '2023-07-31T17:00:00.000000Z', 'PT10S', '689fd2b6-5764-4c43-8803-519da8f5f305'), " +
"('3', 'true', '123123', '13000', '112', '1.123', '1.123123', '1.123123', '12', " +
"'13', '14', '15', 'Кирилл Курдюков Алексеевич', 'binary', '{\"asd\": \"asd\"}', " +
"'{\"asd\": \"asd\"}', '2014-04-06', '2023-09-16T12:30', '2023-07-31T17:00:00.000000Z', 'PT10S'), " +
"'{\"asd\": \"asd\"}', '2014-04-06', '2023-09-16T12:30', '2023-07-31T17:00:00.000000Z', 'PT10S', '689fd2b6-5764-4c43-8803-519da8f5f305'), " +
"('6', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, " +
"NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);"
"NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);"
));

migrateChangeFile(changeLogFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void changelogXmlMigrationAllTypesTableTest() throws SQLException, LiquibaseExce
"datetime_column DATETIME, " +
"timestamp_column TIMESTAMP, " +
"interval_column INTERVAL, " +
"uuid_column UUID, " +
"PRIMARY KEY (id) " +
");"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id,bool_column,bigint_column,smallint_column,tinyint_column,float_column,double_column,decimal_column,uint8_column,uint16_column,uint32_column,uint64_column,text_column,binary_column,json_column,jsondocument_column,date_column,datetime_column,timestamp_column,interval_column
2,true,123123,13000,112,1.123,1.123123,1.123123,12,13,14,15,Кирилл Курдюков Алексеевич,binary,{"asd": "asd"},{"asd": "asd"},2014-04-06,2023-09-16T12:30,2023-07-31T17:00:00.000000Z,PT10S
3,true,123123,13000,112,1.123,1.123123,1.123123,12,13,14,15,Кирилл Курдюков Алексеевич,binary,{"asd": "asd"},{"asd": "asd"},2014-04-06,2023-09-16T12:30,2023-07-31T17:00:00.000000Z,PT10S
6,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null
id,bool_column,bigint_column,smallint_column,tinyint_column,float_column,double_column,decimal_column,uint8_column,uint16_column,uint32_column,uint64_column,text_column,binary_column,json_column,jsondocument_column,date_column,datetime_column,timestamp_column,interval_column,uuid_column
2,true,123123,13000,112,1.123,1.123123,1.123123,12,13,14,15,Кирилл Курдюков Алексеевич,binary,{"asd": "asd"},{"asd": "asd"},2014-04-06,2023-09-16T12:30,2023-07-31T17:00:00.000000Z,PT10S,689fd2b6-5764-4c43-8803-519da8f5f305
3,true,123123,13000,112,1.123,1.123123,1.123123,12,13,14,15,Кирилл Курдюков Алексеевич,binary,{"asd": "asd"},{"asd": "asd"},2014-04-06,2023-09-16T12:30,2023-07-31T17:00:00.000000Z,PT10S,689fd2b6-5764-4c43-8803-519da8f5f305
6,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
id,bool_column,bigint_column,smallint_column,tinyint_column,float_column,double_column,decimal_column,uint8_column,uint16_column,uint32_column,uint64_column,text_column,binary_column,json_column,jsondocument_column,date_column,datetime_column,timestamp_column,interval_column
1,true,123123,13000,113,1.123,1.123123,1.123123,12,13,14,15,Кирилл Курдюков Алексеевич,binary,{"asd": "asd"},{"asd": "asd"},2014-04-06,2023-09-16T12:30,2023-07-31T17:00:00.000000Z,PT10S
5,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null
id,bool_column,bigint_column,smallint_column,tinyint_column,float_column,double_column,decimal_column,uint8_column,uint16_column,uint32_column,uint64_column,text_column,binary_column,json_column,jsondocument_column,date_column,datetime_column,timestamp_column,interval_column,uuid_column
1,true,123123,13000,113,1.123,1.123123,1.123123,12,13,14,15,Кирилл Курдюков Алексеевич,binary,{"asd": "asd"},{"asd": "asd"},2014-04-06,2023-09-16T12:30,2023-07-31T17:00:00.000000Z,PT10S,689fd2b6-5764-4c43-8803-519da8f5f305
5,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
<column name="datetime_column" type="datetime" remarks="Date/time, precision to the second."/>
<column name="timestamp_column" type="timestamp" remarks="Date/time, precision to the microsecond."/>
<column name="interval_column" type="interval" remarks="Time interval (signed), precision to microseconds"/>

<column name="uuid_column" type="uuid" remarks="UUID value."/>
</createTable>

<rollback>
Expand Down
2 changes: 1 addition & 1 deletion liquibase-dialect/stress-test/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
YDB_JDBC_DRIVER_VERSION=2.2.0
YDB_JDBC_DRIVER_VERSION=2.3.3

echo Stress test using ydb-jdbc-driver-shaded:"$YDB_JDBC_DRIVER_VERSION"

Expand Down

0 comments on commit 0d73497

Please sign in to comment.