diff --git a/.gitignore b/.gitignore index b164604a..d29456d6 100644 --- a/.gitignore +++ b/.gitignore @@ -103,6 +103,7 @@ hs_err_pid* /build/ /common/build /discord-wrapper/build +/database-codegen/build # Ignore Gradle GUI config gradle-app.setting diff --git a/.travis.yml b/.travis.yml index f41e397a..eb2d8d05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ services: - docker addons: + postgresql: "10" sonarcloud: organization: "napstr-github" @@ -14,6 +15,7 @@ env: - secure: "TibOvGlMn0dBK97rMpvHtk17iEQszuZJkL6rqc8FoKOmMb36CFdHK7lGUCGHEoYwCl2Cs4OSICWyLhmYwfP623vYLrXfd5fdBbHWaSO1RtQkGK9+roomb80tkYleKBUArWrteYk+uevWA7HxWoQXmoVKD/DvppF6tZsJq2sv8BFQZSE2XDtiQ5QvotD0j4ypSwatZFT73AAGJlxbT3fBrx5gNw6bLJd8ZEdjRTEL+bHPAh+iqURVg3181RcEJQA3N+uAn2dkdByn4TENBLvsr4HuQmkeG0W7yTWIhZZS+t2sbp4i2PrGmEVaGeqc4DqqVSAR522NLOzwfpxXJcRr9xmfQXnt2qPyfK7cZQET/QuRvUIBw1IQo42Bae2Kk0Xhvm45FSOmgYY1YyFNFhdaK/pCbHd5jmp6djTeajeiEaH7Th6LBcDfTrNK8dmL2THvSxsodH2FRwlks+9t3KY7ZwwxXbpwbPb95qYpR8bDqlf9aIE5awNf6LXTi4l97mMNeLoN9e9yXtmDUdjPGkqZqi1nTdFfJH1Qx3RNwufFRVoIfJ7wNQG1W14hTaw6JGXCbEyJkQ5cHFzSW0T+7KH53IicnXbLDneenViDuw21vBwgT+53aHENhgwR5ZpdbhIyUVdGPvxF8udmp2NCmW3ePJrVKwWHKjj+F9I+5g4F49I=" - DOCKER_USERNAME: napstr - secure: "RFvBcJzgPu2wvPuhxAgYNowqD4UsbgEzG06/DzWcDeRZEemnexCJr46ppL1Q7HDdYE4ftxh5H4g4O92SfNVdo0NZZGfm0E1/aHDurA40+OVML80akkwbxevU+FgXe8qofvhaF+byHgxj5m6VUAuANTV/oA3boyDbFazth8QA2+oOHLKmoTkJG0w/bBqad5q8U99rS+gwJE6tXce02X7Z4Bz7YNbl/luEJoWDVbbCv8jPoHB/RJ+OEQx3/WTKgiSjIpt70eYsjnzgW5ZJ0eWteWwwTACUX254tIUty81rkRvmPUtOEYDakVx4MeqPpsDtFmu/dffJ4ofQXkEX2cW36Y8VOPYP1dBO++iYaPZtInw2xIptIi9xCEJO1Wh1VmEK8Fb2xjFsaFzPTCVz+M0+MZxn7JuGcK1ZHN960zRkkVXP68b+YcGVUgVTJV7DyRQbhyrZY/bD/osJ695KeFx7b9SIus/FH0D2ONqp9Z5gvvA0u+Gt7ChMLY6TJTXVRThzpGOuU203cTZGysBHPfoFKMW4yR2bCFrSHG4ADw8eLFwFiYHwc0EERm8/8Cif3xvE2dTxNAONMbK0zXPGAy42D3dOt7eXT0EDQLQDQjkwGgnlv7lV8FhpEne78V8BdVr+UIUeK0IaNU0DDN/aLW52gLMlrBCYvAX7u4u7A937GYg=" + - WOLFIA_CODEGEN_JDBC: "jdbc:postgresql://localhost:5432/codegen?user=postgres" language: java @@ -32,6 +34,9 @@ jobs: before_script: #for sonar cloud blame information - git fetch --unshallow + #init codegen db + - "psql -c 'CREATE DATABASE codegen;' -U postgres" + - "psql -c 'CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA pg_catalog;' -d codegen -U postgres" script: - java -Xmx32m -version - ./gradlew build --info diff --git a/build.gradle b/build.gradle index 11b6c2f8..218e5fb5 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,8 @@ buildscript { springBootVersion = '2.1.3.RELEASE' sonarQubeVersion = '2.7' bintrayVersion = '1.8.4' + flywayVersion = '5.2.4' + jooqPluginVersion = '3.0.3' //@formatter:on } @@ -27,6 +29,8 @@ buildscript { classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:${sonarQubeVersion}" classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:${bintrayVersion}" + classpath "gradle.plugin.com.boxfuse.client:gradle-plugin-publishing:${flywayVersion}" + classpath "nu.studer:gradle-jooq-plugin:${jooqPluginVersion}" } } @@ -54,7 +58,10 @@ ext { sqlsauceVersion = '0.4.2' jaxbApiVersion = '2.3.1' dsProxyVersion = '1.5.1' - flywayVersion = '5.2.4' + flywayVersion = "$flywayVersion" + jooqVersion = '3.11.11' + postgresqlVersion = '42.2.5' + javaxAnnotationsVersion = '1.3.2' //@formatter:on @@ -90,6 +97,71 @@ allprojects { } } +project('database-codegen') { + apply plugin: 'org.flywaydb.flyway' + apply plugin: 'nu.studer.jooq' + + configurations { + flywayMigration + } + + ext { + codegenJdbcUrl = System.getenv('WOLFIA_CODEGEN_JDBC') == null + ? "jdbc:postgresql://localhost:5434/codegen?user=codegen" + : System.getenv('WOLFIA_CODEGEN_JDBC') + } + + dependencies { + implementation "org.jooq:jooq:$jooqVersion" // object oriented sql queries + implementation "org.jooq:jooq-meta:$jooqVersion" // object oriented sql queries + implementation "org.jooq:jooq-codegen:$jooqVersion" // object oriented sql queries + // java cruft, can be removed with jooq 3.12+ + implementation "javax.annotation:javax.annotation-api:$javaxAnnotationsVersion" + flywayMigration "org.postgresql:postgresql:$postgresqlVersion" // access db during codegen + jooqRuntime "org.postgresql:postgresql:$postgresqlVersion" // access db during codegen + } + + flyway { + flywayMigrate.dependsOn(flywayClean) + url = "$codegenJdbcUrl" + locations = ['filesystem:database-codegen/src/main/resources/db/migrations'] + configurations = ['flywayMigration'] + } + + jooq { + version = jooqVersion + edition = 'OSS' + wolfia(sourceSets.main) { + jdbc { + driver = 'org.postgresql.Driver' + url = "$codegenJdbcUrl" + } + generator { + name = 'org.jooq.codegen.DefaultGenerator' + strategy { + name = 'org.jooq.codegen.DefaultGeneratorStrategy' + } + database { + name = 'org.jooq.meta.postgres.PostgresDatabase' + inputSchema = 'public' + } + target { + packageName = 'space.npstr.wolfia.db.gen' + directory = 'build/classes/generated/java' + } + } + } + } + + generateWolfiaJooqSchemaSource { + dependsOn(flywayMigrate) + } + + test { + dependsOn(flywayMigrate) + } +} + project('discord-wrapper') { dependencies { @@ -123,6 +195,7 @@ configurations { } dependencies { + implementation project(':database-codegen') implementation project(':discord-wrapper') implementation "ch.qos.logback:logback-classic:$logbackVersion" diff --git a/src/main/resources/db/migrations/V1__Initial.sql b/database-codegen/src/main/resources/db/migrations/V1__Initial.sql similarity index 100% rename from src/main/resources/db/migrations/V1__Initial.sql rename to database-codegen/src/main/resources/db/migrations/V1__Initial.sql diff --git a/docker/codegen/docker-compose.yaml b/docker/codegen/docker-compose.yaml new file mode 100644 index 00000000..38d64245 --- /dev/null +++ b/docker/codegen/docker-compose.yaml @@ -0,0 +1,13 @@ +# Required services to run jOOQ's codegen + +version: '3.7' + +services: + codegen-postgres: + image: napstr/wolfia-postgres:master + restart: always + ports: + - 127.0.0.1:5434:5432 + environment: + - ROLE=codegen + - DB=codegen diff --git a/settings.gradle b/settings.gradle index 2d45752a..90acd2d8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,5 @@ rootProject.name = 'Wolfia' include 'common' +include 'database-codegen' include 'discord-wrapper'