Skip to content

Commit

Permalink
adding support for mssql & spock-reports
Browse files Browse the repository at this point in the history
  • Loading branch information
kristyldatical committed Jan 25, 2021
1 parent 2033a7b commit 51b706b
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ target/
/.apt_generated/
/.apt_generated_tests/
bin/
build/
.project
.DS_Store
32 changes: 32 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,38 @@
<artifactId>ojdbc8</artifactId>
<version>18.3.0.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>8.4.0.jre8</version>
</dependency>
<dependency>
<groupId>com.athaydes</groupId>
<artifactId>spock-reports</artifactId>
<version>1.7.1</version>
<scope>test</scope>
<!-- this avoids affecting your version of Groovy/Spock -->
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- // if you don't already have slf4j-api and an implementation of it in the classpath, add this! -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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="kristyl">
<createTable tableName="countries" schemaName="lbcat2">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)"/>
</createTable>
</changeSet>

<changeSet id="2" author="kristyl">
<createTable tableName="person">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
</createTable>
<addColumn tableName="person">
<column name="country_id" type="int"/>
</addColumn>
<addForeignKeyConstraint
baseTableName="person" baseColumnNames="country_id"
constraintName="fk_person_country"
referencedTableName="countries" referencedTableSchemaName="lbcat2" referencedColumnNames="id"
/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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="nvoxland">
<comment>
You can add comments to changeSets.
They can even be multiple lines if you would like.
They aren't used to compute the changeSet MD5Sum, so you can update them whenever you want without causing problems.
</comment>
<createTable tableName="person">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="firstname" type="varchar(50)"/>
<column name="lastname" type="varchar(50)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="7" author="nvoxland">
<createTable tableName="company">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="22" author="nvoxland">
<addColumn tableName="person">
<column name="employer_id" type="int"/>
</addColumn>
</changeSet>

<changeSet id="23" author="nvoxland">
<addForeignKeyConstraint
baseTableName="person" baseColumnNames="employer_id"
constraintName="fk_person_employer"
referencedTableName="company" referencedColumnNames="id"
deleteCascade="true"/>
</changeSet>

<changeSet id="24" author="nvoxland">
<dropForeignKeyConstraint baseTableName="person" constraintName="fk_person_employer"/>
<rollback/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"snapshot": {
"objects": {
"liquibase.structure.core.Column": [
{
"column": {
"defaultValue": "title_test",
"defaultValueConstraintName": "DF_posts_title",
"name": "title",
"nullable": true
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"snapshot": {
"objects": {
"liquibase.structure.core.Column": [
{
"column": {
"defaultValue": "getdate\\(\\)\\!\\{liquibase.statement.DatabaseFunction\\}",
"defaultValueConstraintName": "DF_posts_inserted_date",
"name": "inserted_date",
"nullable": true
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"snapshot": {
"objects": {
"liquibase.structure.core.ForeignKey": [
{
"foreignKey": {
"deferrable": false,
"initiallyDeferred": false,
"name": "fk_person_country"
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"snapshot": {
"objects": {
"liquibase.structure.core.View": [
{
"view": {
"definition": " SELECT authors.id,\n authors.first_name,\n authors.last_name,\n authors.email\n FROM authors;",
"name": "test_view"
}
}]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"snapshot": {
"objects": {
"liquibase.structure.core.Column": [
{
"column": {
"name": "title",
"nullable": true
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE posts ADD CONSTRAINT DF_posts_title DEFAULT 'title_test' FOR title
13 changes: 13 additions & 0 deletions src/test/resources/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,16 @@ services:
MYSQL_PASSWORD: LiquibasePass1
volumes:
- "./mariadb-init.sql:/docker-entrypoint-initdb.d/mariadb-init.sql"

mssql-2017:
container_name: sql-server-db
image: microsoft/mssql-server-linux:2017-latest
ports:
- "1433:1433"
environment:
SA_PASSWORD: "LiquibasePass1"
ACCEPT_EULA: "Y"
volumes:
- "./mssql-init.sh:/docker-entrypoint-initdb.d/mssql-init.sh"
- "./mssql-init.sql:/docker-entrypoint-initdb.d/mssql-init.sql"
entrypoint: /bin/bash /docker-entrypoint-initdb.d/mssql-init.sh
20 changes: 20 additions & 0 deletions src/test/resources/docker/mssql-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

/opt/mssql/bin/sqlservr &

echo "Waiting for server to start...."
#do this in a loop because the timing for when the SQL instance is ready is indeterminate
for i in {1..50};
do
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ${SA_PASSWORD} -d master -i /docker-entrypoint-initdb.d/mssql-init.sql
if [ $? -eq 0 ]
then
echo "mssql-init.sh completed"
break
else
echo "not ready yet..."
sleep 5
fi
done

sleep infinity
83 changes: 83 additions & 0 deletions src/test/resources/docker/mssql-init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
DECLARE @dataPath varchar(256);
DECLARE @logPath varchar(256);
SET @dataPath=(SELECT CAST(serverproperty('InstanceDefaultDataPath') AS varchar(256)));
SET @logPath=(SELECT CAST(serverproperty('InstanceDefaultLogPath') AS varchar(256)));

CREATE LOGIN [lbuser] with password=N'LiquibasePass1', CHECK_EXPIRATION=OFF;
GO

CREATE DATABASE lbcat;
GO

EXEC lbcat..sp_addsrvrolemember @loginame = N'lbuser', @rolename = N'sysadmin'
GO

/* By default, we set the compatibility level to the oldest version we are officially supporting. Note that there
* are differences in behaviour, e.g. with implicit conversions of date and time values. See
* https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql for details.
*/
ALTER DATABASE [lbcat] SET COMPATIBILITY_LEVEL = 100
GO

USE [lbcat]
GO
ALTER DATABASE [lbcat] MODIFY FILEGROUP [PRIMARY] DEFAULT
GO
ALTER DATABASE [lbcat] ADD FILEGROUP [liquibase2]
GO

DECLARE @dataPath varchar(256);
DECLARE @logPath varchar(256);
SET @dataPath=(SELECT CAST(serverproperty('InstanceDefaultDataPath') AS varchar(256)));
SET @logPath=(SELECT CAST(serverproperty('InstanceDefaultLogPath') AS varchar(256)));

DECLARE @createSql varchar(2000);
SET @createSql = (SELECT 'ALTER DATABASE [lbcat] ADD FILE ( NAME = N''liquibase2'', FILENAME = N''' + @dataPath + 'liquibase2.ndf'' , SIZE = 8192KB , FILEGROWTH = 65536KB ) TO FILEGROUP [liquibase2]');
EXECUTE(@createSql);
GO

DROP TABLE IF EXISTS [dbo].[authors]
GO

CREATE TABLE [dbo].[authors](
[id] [int] NOT NULL,
[first_name] [varchar](255) NOT NULL,
[last_name] [varchar](255) NULL,
[email] [varchar](255) NULL,
[birthdate] [varchar](255) NULL,
[added] [datetime] NOT NULL,
CONSTRAINT [PK_PrimaryKey] PRIMARY KEY ([id])
) ON [PRIMARY]
GO

INSERT INTO [dbo].[authors] ([id],[first_name],[last_name],[email],[birthdate],[added])
VALUES ('1','Courtney','Hodkiewicz','[email protected]','1986-01-22','1983-08-23 14:55:09'),
('2','Marielle','Kuhlman','[email protected]','1995-08-08','1984-03-05 01:25:02'),
('3','Emmanuel','Gleichner','[email protected]','1997-05-09','1977-08-09 10:28:04'),
('4','Hertha','Goodwin','[email protected]','2014-08-21','2009-01-28 11:02:56'),
('5','Ewald','Sauer','[email protected]','1988-10-10','2000-11-02 00:37:53')
GO

DROP TABLE IF EXISTS [dbo].[posts]
GO

CREATE TABLE [dbo].[posts](
[id] [int] NOT NULL,
[author_id] [varchar](255) NOT NULL,
[title] [varchar](255) NULL,
[description] [varchar](255) NULL,
[content] [varchar](255) NULL,
[inserted_date] [date] NULL
) ON [PRIMARY]
GO

INSERT INTO [dbo].[posts] ([id],[author_id],[title],[description],[content],[inserted_date])
VALUES ('1','1','sit','in','At corporis est sint beatae beatae.','1996-05-04'),
('2','2','nisi','et','Sunt nemo magni et tenetur debitis blanditiis.','2000-05-25'),
('3','3','ratione','blanditiis','Ipsa distinctio doloremque et ut.','1997-09-22'),
('4','4','ad','et','Repudiandae porro explicabo officiis sed quis voluptate et.','1978-12-13'),
('5','5','deserunt','temporibus','Mollitia reiciendis debitis est voluptatem est neque.','1979-12-06')
GO

CREATE SCHEMA [lbcat2] AUTHORIZATION [dbo]
GO
5 changes: 5 additions & 0 deletions src/test/resources/harness-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ databasesUnderTest:
username: lbuser
password:

- name: mssql
version: 2017
url: jdbc:sqlserver://localhost:1433;databaseName=lbcat
username: lbuser
password: LiquibasePass1

0 comments on commit 51b706b

Please sign in to comment.