-
Notifications
You must be signed in to change notification settings - Fork 7
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
aba59bf
commit 9c846af
Showing
6 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
liquibase-dialect/src/test/java/tech/ydb/liquibase/YdbDatabaseUpdateChangeLogTest.java
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,59 @@ | ||
package tech.ydb.liquibase; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import liquibase.exception.CommandExecutionException; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* @author Kirill Kurdyukov | ||
*/ | ||
public class YdbDatabaseUpdateChangeLogTest extends BaseTest { | ||
|
||
@Test | ||
void integrationTest() throws CommandExecutionException, SQLException { | ||
migrateChangeFile("./changelogs/changelog-init.xml"); | ||
try (PreparedStatement ps = DriverManager.getConnection(jdbcUrl()).prepareStatement( | ||
"INSERT INTO DATABASECHANGELOG(" + | ||
"ID, AUTHOR, FILENAME, DATEEXECUTED, " + | ||
"ORDEREXECUTED, EXECTYPE, MD5SUM, " + | ||
"DESCRIPTION, COMMENTS, TAG, LIQUIBASE, " + | ||
"CONTEXTS, LABELS, DEPLOYMENT_ID) " + | ||
"VALUES (?, 'kurdyukov-kir', 'stub-file.xml', DATETIME('2024-04-01T11:30:20Z'), ?, " + | ||
"'EXECUTED', '9:cb49879b530528bc2555422bb7db58da', 'Stub', " + | ||
"'', '', '4.25.1', '', '', '1971019939')" | ||
)) { | ||
for (int i = 0; i < 210; i++) { | ||
ps.setString(1, String.valueOf(i)); | ||
ps.setInt(2, i); | ||
|
||
ps.executeUpdate(); | ||
} | ||
} | ||
|
||
migrateChangeFile("./changelogs/update/changelog-step-1.xml"); | ||
try (Connection connection = DriverManager.getConnection(jdbcUrl())) { | ||
ResultSet resultSet = connection.createStatement() | ||
.executeQuery("SELECT COUNT(*) AS cnt FROM test WHERE token is NULL"); | ||
assertTrue(resultSet.next()); | ||
assertEquals(3, resultSet.getLong("cnt")); | ||
} | ||
|
||
migrateChangeFile("./changelogs/update/changelog-step-2.xml"); | ||
try (Connection connection = DriverManager.getConnection(jdbcUrl())) { | ||
ResultSet resultSet = connection.createStatement() | ||
.executeQuery("SELECT COUNT(*) AS cnt FROM test WHERE token is NULL"); | ||
assertTrue(resultSet.next()); | ||
assertEquals(0, resultSet.getLong("cnt")); | ||
} | ||
|
||
try (Connection connection = DriverManager.getConnection(jdbcUrl())) { | ||
connection.createStatement().execute("DROP TABLE test"); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
liquibase-dialect/src/test/resources/changelogs/update/changelog-step-1.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,10 @@ | ||
<?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" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd"> | ||
|
||
<include file="create-table.xml" relativeToChangelogFile="true"/> | ||
<include file="insert.xml" relativeToChangelogFile="true"/> | ||
</databaseChangeLog> |
11 changes: 11 additions & 0 deletions
11
liquibase-dialect/src/test/resources/changelogs/update/changelog-step-2.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,11 @@ | ||
<?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" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd"> | ||
|
||
<include file="create-table.xml" relativeToChangelogFile="true"/> | ||
<include file="insert.xml" relativeToChangelogFile="true"/> | ||
<include file="update.xml" relativeToChangelogFile="true"/> | ||
</databaseChangeLog> |
21 changes: 21 additions & 0 deletions
21
liquibase-dialect/src/test/resources/changelogs/update/create-table.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,21 @@ | ||
<?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" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd"> | ||
|
||
<changeSet id="create-table" author="author" context="all"> | ||
<sql> | ||
create table test( | ||
id Int32 NOT NULL, | ||
code Text NOT NULL, | ||
token bool, | ||
PRIMARY KEY (id) | ||
); | ||
</sql> | ||
<rollback> | ||
drop table test; | ||
</rollback> | ||
</changeSet> | ||
</databaseChangeLog> |
17 changes: 17 additions & 0 deletions
17
liquibase-dialect/src/test/resources/changelogs/update/insert.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,17 @@ | ||
<?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" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd"> | ||
|
||
<changeSet id="insert" author="author" context="all"> | ||
<sql> | ||
insert into test(id, code, token) | ||
values (1, 'A', null), | ||
(2, 'A', null), | ||
(3, 'A', null), | ||
(4, 'B', true); | ||
</sql> | ||
</changeSet> | ||
</databaseChangeLog> |
16 changes: 16 additions & 0 deletions
16
liquibase-dialect/src/test/resources/changelogs/update/update.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" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd"> | ||
|
||
<changeSet id="update" author="author" context="all"> | ||
<sql> | ||
update test set token= true where code = 'A'; | ||
</sql> | ||
<rollback> | ||
update test set token=NULL where code='A'; | ||
</rollback> | ||
</changeSet> | ||
</databaseChangeLog> |