Liquibase groovy accessomg datebaseChangeLog property - gradle

I have the following Liquibase script written in Groovy.
package data.db
databaseChangeLog {
// H2
property(name: "date", value: "DATETIME", dbms: "h2")
property(name: "integer", value: "INTEGER", dbms: "h2")
property(name: "bigint", value: "BIGINT", dbms: "h2")
property(name: "current_date", value: "NOW()", dbms: "h2")
property(name: "current_timestamp", value: "NOW()", dbms: "h2")
// TABLES
include(file: "tables/2017-06-22-001-user-account-tables.groovy", relativeToChangelogFile: true)
}
I am using Gradle for build and I included compile "org.liquibase:liquibase-groovy-dsl:1.2.2" so the script itself works.
However, I don't know how I can access these databaseChangeLog properties inside the script. I could't find and documentation or examples on how to do it.
Using xml it is pretty straightforward, here is the documentation with an example.
How do I do this using Groovy?

Ok, I found a solution that works, but seems a bit unwieldy. Please recommend something better if there is such a thing:
final DatabaseChangeLog dcl = (DatabaseChangeLog) properties['databaseChangeLog'];
final String bigintType = dcl.changeLogParameters.getValue("bigint", dcl)
Here is a bit of context:
package data.db.tables
import liquibase.changelog.DatabaseChangeLog
databaseChangeLog {
final DatabaseChangeLog dcl = (DatabaseChangeLog) properties['databaseChangeLog'];
final String bigintType = dcl.changeLogParameters.getValue("bigint", dcl)
changeSet(id: "2017-06-22-001-user-account-tables", author: "goranmrzljak") {
comment("User account tables")
createTable(tableName: "user_account_permission") {
column(name: "id", type: bigintType) {
constraints(primaryKey: true, primaryKeyName: "user_account_permission_pk")
}
// ...
}
// ...
}
}
This works both in the same file or databaseChangeLog, or in a different file or databaseChangeLog from where the properties were defined.

Related

gql codegen generate file within the same folder as in query/mutation file path

Using this guide https://the-guild.dev/graphql/codegen/docs/advanced/generated-files-colocation
It works as intended for "operation-types" file, but how about the "types.ts" file itself, is it possible to generate separate type file depending for each operation needs, or just create the object types inside the ".generated.tsx" file?
my config is as follow, similar to the docs, its just putting into a folder called __generated__. Thank you.
const config: CodegenConfig = {
schema: 'http://localhost:4000/graphql',
documents: ['src/**/*.{gql,graphql}'],
generates: {
'src/codegen/types.ts': {
plugins: ['typescript'],
},
'src/': {
preset: 'near-operation-file',
presetConfig: { extension: '.generated.tsx', baseTypesPath: 'codegen/types.ts', folder: '__generated__' },
plugins: ['typescript-operations'],
}
}
}

Hibernate diffChangeLog producing change sets that exist already in the table

I am using spring boot with hibernate 5.3.8. After I run the first schema I generate a diffChangeLog and its dropping and creating the same index. When I look at the collection_days table a common_collection_search exists
How can I mark it as completed so it no longer appears in the diffChangeLog. I only want generate a changelog with the newest changes so I can run it and update the database
collection_days table
index_name|index_algorithm|is_unique|column_name|condition
common_collection_search|BTREE|f|waste_generator_id,refuse_type|NULL
This is from my master schema that I ran on a fresh database
- changeSet:
id: 1572649828026-46
author: comp (generated)
changes:
- createIndex:
columns:
- column:
name: wg_id
- column:
name: type
indexName: common_collection_search
tableName: collection_days
diffChangeLog results
- changeSet:
id: 1615578168770-16
author: comp (generated)
changes:
- dropIndex:
indexName: common_collection_search
tableName: collection_days
- changeSet:
id: 1615578168770-17
author: comp (generated)
changes:
- createIndex:
columns:
- column:
name: wg_id
- column:
name: type
indexName: common_collection_search
tableName: collection_days
CollectionDay entity
#Data
#Entity
#Table(name = "collection_days", uniqueConstraints = {
#UniqueConstraint(columnNames = { "wg_id", "type", "day_of_week" }) }, indexes = {
#Index(name = "common_collection_search", columnList = "wg_id,type") })
public class CollectionDay implements Serializable {
#Column(name = "wg_id",updatable = false,insertable = false)
private Long wgId;
#Column(name = "type")
#Enumerated(EnumType.STRING)
private ESEnums.type type;
build.gradle
compile "org.hibernate:hibernate-core"
compile "org.hibernate:hibernate-entitymanager"
compile "org.hibernate:hibernate-envers"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "com.zaxxer:HikariCP"
compile "org.hibernate:hibernate-ehcache"
compile 'com.fasterxml.jackson.datatype:jackson-datatype-hibernate5'
compile "org.postgresql:postgresql"
compile "org.liquibase:liquibase-core"
compile "org.hibernate:hibernate-validator:6.1.6.Final"
liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:3.8'
liquibaseRuntime sourceSets.main.output
liquibaseRuntime sourceSets.main.compileClasspath
liquibase {
activities {
main {
driver 'org.postgresql.Driver'
url 'jdbc:postgresql://localhost:54323/db2?stringtype=unspecified'
username ''
password ''
changeLogFile "src/main/resources/liquibase/migrations/changelog.yaml"
classpath 'src/main/java'
referenceUrl 'hibernate:spring:com.project.domain.entities?dialect=org.hibernate.dialect.PostgreSQL82Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy'
}
}
}
I think the problem is that PostgreSQL is smart enough to realize that the index is unnecessary and doesn't create it in the way you expect it. Your unique constraint already covers the columns of the index and since it is backed by an index, it will just tell you that it won't create your index, because it is already covered.

mvn pact:verify does not execute provider state but #State code is executed from IDE

When I execute my provider test from IDE #State method is executed, but mvn pact:verify command does not execute the #State of the provider
Provider test class:
#RunWith(PactRunner.class)
#Provider("wProvider")
#PactFolder("/home/username/workspace/automation/pactProject/pacts/")
public class WpproviderTest {
#State("wProvider will create new stuff")
public void providerState(){
System.out.println("execute the the provider state");
//some code...
System.out.println("your new stuff response is: " + jsonResponse)
}
#TestTarget
public final Target target = new HttpTarget(url, true);
#TargetRequestFilter
public void updateAuthHeaders(HttpRequest request) {
request.addHeader("some auth headers")
}
}
my pom.xml file:
<plugin>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-maven_2.12</artifactId>
<version>3.6.7</version>
<configuration>
<serviceProviders>
<serviceProvider>
<name>wProvider</name>
<requestFilter>
request.addHeader('Authorization', 'auth value')
</requestFilter>
<stateChangeRequestFilter>
request.addHeader('Authorization', 'auth value')
</stateChangeRequestFilter>
<stateChangeUrl>http://mywebsite.com/myservice/myaction
</stateChangeUrl>
<stateChangeUsesBody>true</stateChangeUsesBody>
<protocol>http</protocol>
<host>http://localhost</host>
<path></path>
<port>443</port>
<pactBroker>
<url>https://mypactbroker</url>
<authentication>
<username>my_usrname</username>
<password>my_pwd</password>
</authentication>
</pactBroker>
<insecure>true</insecure>
</serviceProvider>
</serviceProviders>
</plugin>
my pact file:
{
"provider": {
"name": "wProvider"
},
"consumer": {
"name": "tConsumer"
},
"interactions": [
{
"description": "A new interaction with wProvider",
"request": {
"method": "POST",
"path": "/somePath",
"headers": {
"Content-Type": "application/json"
},
"body": ""
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": " ",
"matchingRules": {
"body": {
// some matching rules
}
}
},
"providerStates": [
{
"name": "wProvider will create new stuff"
}
]
}
],
"metadata": {
"pactSpecification": {
"version": "3.0.0"
},
"pact-jvm": {
"version": "3.6.7"
}
}
}
When I execute mvn pact:verify -X command I see in console:
Given Wprovider will generate new stuff
[DEBUG] Invoked state change http://mywebsite.com/myservice/myaction
-> HTTP/1.1 200 OK [DEBUG] State Change: "ProviderState(name=http://mywebsite.com/myservice/myaction,
params={})" -> Ok(value={})
I am missing some settings related to #State with mvn pact:verify?
It looks like the #State annotation isn't supported for the Maven plugin (unlike the JUnit setup).
The docs have the following to say about this:
For each provider you can specify a state change URL to use to switch the state of the provider. This URL will receive the providerState description and parameters from the pact file before each interaction via a POST.
So you may need to add a dynamic endpoint (e.g. /_pact/state) that can take the request and setup the given state.
The Maven plugin (as well as the Gradle one) execute the Pact verification against a running provider when you execute pact:verify. The #State method you have defined is for a JUnit test. The Maven plugin does not execute JUnit tests, you run them as part of the test Maven phase which is executed by the Maven Surefire plugin.
The documentation link that Matt provided above will let you know how to execute state changes with pact:verify, but if you have written a JUnit test you don't need to use that.

Groovy SwingBuilder() apple.awt.CToolkit exception

I am using newest Mac OS X and I am creating a GUI element inside a Gradle file. I am currently using jdk1.7.0_55 and I have imported groovy.swing.SwingBuilder, when I run the project I am getting the following error:
java.awt.AWTError: "Toolkit not found: apple.awt.CToolkit
I have tried running the script as a headless server using System.setProperty('java.awt.headless', 'true')
I would like to have a solution that I can include directly in the Gradle project file, instead of trying to figure out what is in my accesibilities.properties file (that may not exist on a particular system, like it does not on my system).
Also the project must use an internal solution, external libraries are not allowed.
Would really appreciate any help on this matter.
Edited: Sample Code
gradle.taskGraph.whenReady { taskGraph ->
if(taskGraph.hasTask(':CustomApp:assembleRelease')) {
def pass = ''
if(System.console() == null) {
new SwingBuilder().edt { // Error occurs here.
dialog(modal: true,
alwaysOnTop: true,
resizable: false,
locationRelativeTo: null,
pack: true,
show: true
)
{
vbox {
label(text: "Enter password:")
input = passwordField()
button(defaultButton: true, text: 'OK', actionPerformed: {
pass = input.password;
dispose();
})
}
}
}
}
}
I've faced same issue with Android Studio 0.8.6 and solved it with custom gradle installation.
Just downloaded gradle 1.12 and set path to it in preferences.
The question is a few years old, but with the following gradle build file (which is essentially the same as the OPs):
import groovy.swing.SwingBuilder
task doit {}
gradle.taskGraph.whenReady { taskGraph ->
if(taskGraph.hasTask(doit)) {
def pass = ''
new SwingBuilder().edt { // Error occurs here.
dialog(modal: true,
alwaysOnTop: true,
resizable: false,
locationRelativeTo: null,
pack: true,
show: true)
{ vbox
{ label(text: "Enter password:")
input = passwordField()
button(defaultButton: true, text: 'OK', actionPerformed: {
pass = input.password;
dispose();
})
}
}
}
}
}
executing:
~> gradle doit
results in the following screen:
in other words, at least with this version of gradle, operating system, java etc this seems to work.

Gant: Copy with filtering

I have a 'doc' directory containing HTML documentation and each HTML contains placeholders for the application version and the SVN revision:
Welcome to the ... V${version} r${buildNumber}
In my Grails/Gant build script we create a doc package for which we first copy the doc directory to a staging area before zipping it up. I now wanna replace these placeholders with values like this (assume the variables appVersion and svnRevision are set properly:
ant.mkdir(dir: "${baseDocDir}")
ant.copy(todir: "${baseDocDir}") {
fileset(dir: "./src/main/doc", includes: '*.html')
filterset {
filter ( token : 'version' , value: appVersion )
filter ( token : 'buildNumber' , value : svnRevision )
}
}
The copy works but somehow the filter does not!
I can answer the question myself now. The following code works:
ant.copy(todir: "${baseDocDir}") {
filterset(begintoken: "\${", endtoken: "}") {
filter(token: "version", value: appVersion)
filter(token: "buildNumber", value: svnRevision)
}
fileset(dir: "./src/main/doc/", includes: "**/*.html")
}

Resources