Skip to content

Commit

Permalink
[DAT-11269] updated test-harness, unified init script (#149)
Browse files Browse the repository at this point in the history
* updated test-harness, unified init script

* fixed typo in folder name, added expected files

* added cleanup files for snpashot test for java 11

* removed redundant files

* updated TH to 1.0.6
  • Loading branch information
KushnirykOleh authored Aug 11, 2022
1 parent fd6e307 commit 2472b9f
Show file tree
Hide file tree
Showing 56 changed files with 295 additions and 96 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ CREATE TABLE authors (
);
INSERT INTO authors(id, first_name, last_name, email, birthdate, added) VALUES
(1,'Courtney','Hodkiewicz','borer.edison@example.org','1986-01-22','1983-08-23 14:55:09');
(1,'Eileen','Lubowitz','ppaucek@example.org','1991-03-04','2004-05-30 02:08:25');
INSERT INTO authors(id, first_name, last_name, email, birthdate, added) VALUES
(2,'Marielle','Kuhlman','llakin@example.org','1995-08-08','1984-03-05 01:25:02');
(2,'Tamia','Mayert','shansen@example.org','2016-03-27','2014-03-21 02:52:00');
INSERT INTO authors(id, first_name, last_name, email, birthdate, added) VALUES
(3,'Emmanuel','Gleichner','jean.zemlak@example.net','1997-05-09','1977-08-09 10:28:04');
(3,'Cyril','Funk','reynolds.godfrey@example.com','1988-04-21','2011-06-24 18:17:48');
INSERT INTO authors(id, first_name, last_name, email, birthdate, added) VALUES
(4,'Hertha','Goodwin','hollis.gusikowski@example.org','2014-08-21','2009-01-28 11:02:56');
(4,'Nicolas','Buckridge','xhoeger@example.net','2017-02-03','2019-04-22 02:04:41');
INSERT INTO authors(id, first_name, last_name, email, birthdate, added) VALUES
(5,'Ewald','Sauer','juvenal35@example.com','1988-10-10','2000-11-02 00:37:53');
(5,'Jayden','Walter','lillian66@example.com','2010-02-27','1990-02-04 02:32:00');
DROP TABLE IF EXISTS posts;
Expand All @@ -70,15 +70,15 @@ CREATE TABLE posts (
);
INSERT INTO posts(id, author_id, title, description, content, inserted_date) VALUES
(1,1,'sit','in','At corporis est sint beatae beatae.','1996-05-04');
(1,1,'temporibus','voluptatum','Fugit non et doloribus repudiandae.','2015-11-18');
INSERT INTO posts(id, author_id, title, description, content, inserted_date) VALUES
(2,2,'nisi','et','Sunt nemo magni et tenetur debitis blanditiis.','2000-05-25');
(2,2,'ea','aut','Tempora molestias maiores provident molestiae sint possimus quasi.','1975-06-08');
INSERT INTO posts(id, author_id, title, description, content, inserted_date) VALUES
(3,3,'ratione','blanditiis','Ipsa distinctio doloremque et ut.','1997-09-22');
(3,3,'illum','rerum','Delectus recusandae sit officiis dolor.','1975-02-25');
INSERT INTO posts(id, author_id, title, description, content, inserted_date) VALUES
(4,4,'ad','et','Repudiandae porro explicabo officiis sed quis voluptate et.','1978-12-13');
(4,4,'itaque','deleniti','Magni nam optio id recusandae.','2010-07-28');
INSERT INTO posts(id, author_id, title, description, content, inserted_date) VALUES
(5,5,'deserunt','temporibus','Mollitia reiciendis debitis est voluptatem est neque.','1979-12-06');
(5,5,'ad','similique','Rerum tempore quis ut nesciunt qui excepturi est.','2006-10-09');;
```

## Contributing
Expand Down
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?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">
<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.liquibase.ext</groupId>
Expand Down Expand Up @@ -86,9 +87,14 @@
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-test-harness</artifactId>
<version>1.0.2</version>
<version>1.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import liquibase.database.DatabaseConnection;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.DatabaseException;
import liquibase.structure.core.Index;

import java.sql.Statement;

Expand Down Expand Up @@ -151,4 +152,12 @@ public boolean supportsNotNullConstraintNames() {
public boolean supportsPrimaryKeyNames() {
return false;
}

/**
* there shouldn't be keyspace name before the index name, queries fail otherwise
*/
@Override
public String escapeIndexName(String catalogName, String schemaName, String indexName) {
return this.escapeObjectName(indexName, Index.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package liquibase.ext.cassandra.sqlgenerator;

import liquibase.database.Database;
import liquibase.database.core.MSSQLDatabase;
import liquibase.database.core.MySQLDatabase;
import liquibase.ext.cassandra.database.CassandraDatabase;
import liquibase.sql.Sql;
import liquibase.sql.UnparsedSql;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.sqlgenerator.core.SetTableRemarksGenerator;
import liquibase.statement.core.SetTableRemarksStatement;
import liquibase.structure.DatabaseObject;
import liquibase.util.StringUtil;

public class SetTableRemarksGeneratorCassandra extends SetTableRemarksGenerator {
@Override
public int getPriority() {
return PRIORITY_DATABASE;
}

@Override
public boolean supports(SetTableRemarksStatement statement, Database database) {
return database instanceof CassandraDatabase;
}

public Sql[] generateSql(SetTableRemarksStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
String remarksEscaped = database.escapeStringForDatabase(StringUtil.trimToEmpty(statement.getRemarks()));
String sql = "ALTER TABLE " + database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName()) + " WITH comment = '" + remarksEscaped + "'";
return new Sql[]{new UnparsedSql(sql, this.getAffectedTable(statement))};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ liquibase.ext.cassandra.sqlgenerator.InitializeDatabaseChangeLogLockTableGenerat
liquibase.ext.cassandra.sqlgenerator.CreateTableGeneratorCassandra
liquibase.ext.cassandra.sqlgenerator.DropColumnGeneratorCassandra
liquibase.ext.cassandra.sqlgenerator.RenameColumnGeneratorCassandra
liquibase.ext.cassandra.sqlgenerator.TagDatabaseGeneratorCassandra
liquibase.ext.cassandra.sqlgenerator.TagDatabaseGeneratorCassandra
liquibase.ext.cassandra.sqlgenerator.SetTableRemarksGeneratorCassandra
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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">
<!-- This changelog overrides default inherited from test harness because-->
<!-- varchar type doesn't have length in Cassandra-->
<changeSet id="1" author="kristyl">
<addColumn tableName="authors">
<column name="varcharColumn" type="varchar"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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">
<!-- This changelog overrides default inherited from test harness because-->
<!-- tables in Cassandra has to have primary key-->
<changeSet id="1" author="oleh">
<createTable tableName="test_table">
<column name="test_id" type="int">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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">
<!-- This changelog overrides default inherited from test harness because-->
<!-- tables in Cassandra has to have primary key-->
<changeSet id="1" author="kristyl">
<createTable tableName="createTableDataTypeText">
<column name="textCol" type="text">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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">
<!-- This changelog overrides default inherited from test harness because-->
<!-- tables in Cassandra has to have primary key-->
<changeSet id="1" author="oleh">
<createTable tableName="test_table_timestamp">
<column name="test_id" type="int">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
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">
<!--https://docs.liquibase.com/change-types/community/add-default-value.html-->
<changeSet author="oleh" id="1">
<!-- This changelog overrides default inherited from test harness because-->
<!-- varchar type doesn't have length in Cassandra-->
<changeSet author="oleh" id="1">
<addColumn tableName="posts">
<column name="varcharColumn" type="varchar"/>
</addColumn>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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">

<!-- This changelog overrides default inherited from test harness because-->
<!-- tables in Cassandra has to have primary key-->
<changeSet author="oleh" id="1">
<createTable tableName="test_table">
<column name="test_id" type="int">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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">
<!-- This changelog overrides default inherited from test harness because-->
<!-- tables in Cassandra need a primary key, added column `id`-->
<changeSet id="1" author="as">
<createTable tableName="full_name_table">
<column name="id"
type="int">
<constraints primaryKey="true"/>
</column>
<column name="first_name"
type="varchar"/>
<column name="last_name"
type="varchar"/>
</createTable>
<rollback/>
</changeSet>
<changeSet id="2" author="as">
<insert tableName="full_name_table">
<column name="id" value="1"/>
<column name="first_name" value="John"/>
<column name="last_name" value="Doe"/>
</insert>
<insert tableName="full_name_table">
<column name="id" value="2"/>
<column name="first_name" value="Jane"/>
<column name="last_name" value="Doe"/>
</insert>
<rollback/>
</changeSet>
<changeSet id="3" author="as">
<mergeColumns column1Name="first_name"
column2Name="last_name"
finalColumnName="full_name"
finalColumnType="varchar"
joinString=" "
tableName="full_name_table"/>
<rollback>
<dropTable tableName="full_name_table"/>
</rollback>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
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">
<!-- This changelog overrides default inherited from test harness because-->
<!-- varchar type doesn't have length in Cassandra-->
<changeSet id="1" author="oleh">
<renameColumn columnDataType="varchar(50) NOT NULL"
<renameColumn columnDataType="varchar NOT NULL"
newColumnName="id_renameColumn_test"
oldColumnName="id"
tableName="authors"/>
Expand Down
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-4.3.xsd">
<!-- This changelog overrides default inherited from test harness because-->
<!--there is no rollback for setTable remarks, setting empty string-->
<changeSet id="1" author="as">
<setTableRemarks remarks="A Test Remark"
tableName="authors"/>
<rollback>
<setTableRemarks remarks=""
tableName="authors"/>
</rollback>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
insert into sqltest (id) values (1);
insert into sqltest (id) values (2);
insert into sqltest (id) values (3);
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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="1" author="as">
<comment>Creates a table and inserts values into the table with actual SQL</comment>
<createTable tableName="sqltest">
<column name="id" type="int">
<constraints primaryKey="true"/>
</column>
</createTable>
<rollback/>
</changeSet>
<changeSet id="2" author="as">
<sqlFile path="sqlFile.txt"
relativeToChangelogFile="true"
stripComments="true"/>
<rollback>
<dropTable tableName="sqltest"/>
</rollback>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"snapshot": {
"objects": {
"liquibase.structure.core.Table": [
{

"table": {
"name": "full_name_table"
}
}
],
"liquibase.structure.core.Column": [
{
"column": {
"name": "full_name"
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INVALID TEST
Cassandra doesn't support auto increment as it is decentralized DB and managing autoincrement require cental place and synch
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INVALID TEST
Cassandra doesn't support check constraint
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ALTER TABLE authors ADD varcharColumn VARCHAR
ALTER TABLE authors ADD intColumn INT
ALTER TABLE authors ADD dateColumn date
ALTER TABLE betterbotz.authors ADD varcharColumn VARCHAR
ALTER TABLE betterbotz.authors ADD intColumn INT
ALTER TABLE betterbotz.authors ADD dateColumn date
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INVALID TEST
--Cassandra doesn't support sequences
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INVALID TEST
Cassandra isn't among PRO supported databases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CREATE INDEX idx_first_name ON authors(first_name)
CREATE INDEX idx_last_name ON authors(last_name)
CREATE INDEX idx_first_name ON betterbotz.authors(first_name)
CREATE INDEX idx_last_name ON betterbotz.authors(last_name)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INVALID TEST
Cassandra isn't among PRO supported databases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INVALID TEST
Cassandra isn't among PRO supported databases
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CREATE TABLE test_table (test_id INT, test_column VARCHAR, PRIMARY KEY (test_id))
CREATE TABLE betterbotz.test_table (test_id INT, test_column VARCHAR, PRIMARY KEY (test_id))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CREATE TABLE createTableDataTypeText (textCol TEXT, PRIMARY KEY (textCol))
CREATE TABLE betterbotz.createTableDataTypeText (textCol TEXT, PRIMARY KEY (textCol))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CREATE TABLE test_table_timestamp (test_id INT, test_column timestamp, PRIMARY KEY (test_id))
CREATE TABLE betterbotz.test_table_timestamp (test_id INT, test_column timestamp, PRIMARY KEY (test_id))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INVALID TEST
Cassandra isn't among PRO supported databases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INVALID TEST
Cassandra doesn't support check constraint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INVALID TEST
Cassandra isn't among PRO supported databases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INVALID TEST
Cassandra doesn't support check constraint
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ALTER TABLE posts ADD varcharColumn VARCHAR
ALTER TABLE posts DROP varcharColumn
ALTER TABLE betterbotz.posts ADD varcharColumn VARCHAR
ALTER TABLE betterbotz.posts DROP varcharColumn
Loading

0 comments on commit 2472b9f

Please sign in to comment.