Lucas,

I was very interested in the new DDLDatabase, but when I read the docs, it 
sounded like it doesn't yet support reading in a directory of migration 
scripts like what you'd find in a typical Flyway-enabled project.
Is this actually supported in 3.10.0?  Currently, we have been reading the 
PostgresDB and outputting to an XMLDatabase, but of course, this requires 
creating the DB with the migrations first.  Would be great to eliminate 
that step.

-Daniel

On Wednesday, October 4, 2017 at 5:49:04 AM UTC-4, Lukas Eder wrote:
>
> Hi Edgar,
>
> Thanks for your message.
>
> I don't think that the "H2 in PostgreSQL mode" really goes "all in" on the 
> PostgreSQL mode, including switching all the dictionary views to what would 
> be expected in PostgreSQL. Instead, it simply accepts PostgreSQL style SQL 
> query syntax.
>
> So, the correct approach here would be to turn off PostgreSQL mode when 
> reverse engineering the schema with jOOQ (because the PostgreSQL mode is no 
> longer useful, once you've loaded the schema), and to use the H2Database 
> instead of the PostgresDatabase, like with any other ordinary H2 schema.
>
> Note that since jOOQ 3.10, we now have a DDLDatabase for the code 
> generator as well, which uses jOOQ's new parser internally to reverse 
> engineer any dialect:
> https://www.jooq.org/doc/latest/manual/code-generation/codegen-ddl
>
> It internally applies a set of migration scripts (translated from any 
> dialect to H2) to a fresh, in-memory H2 database, and then reverse 
> engineers it again. Perhaps that works for you. We'd be very happy to get 
> any feedback on this new feature.
>
> I hope this helps,
> Lukas
>
> 2017-10-03 14:05 GMT+02:00 <[email protected] <javascript:>>:
>
>> Here's my workflow:
>>
>> - I have a folder of db migration scripts
>> - Flyway runs them all on an h2 database in Postgres mode, then dumps the 
>> final schema
>> - There's a gradle task that makes sure that the db migrations -> schema 
>> mapping is always up-to-date
>> - I'd like to slurp this schema into an h2 in Postgres mode, and use that 
>> to generate code with jOOQ.
>>
>> The problem is, jOOQ barfs when generating code against the h2 db in 
>> Postgres mode.  Here's the jOOQ config:
>>
>> jooq {
>>
>> version = '3.9.5'
>>
>> edition = 'OSS'
>>
>> models(sourceSets.main) {
>>
>> generator {
>>
>> name = 'org.jooq.util.DefaultGenerator'
>>
>> database {
>>
>> driver = 'org.h2.Driver'
>>
>> url = 'jdbc:h2:mem:;MODE=PostgreSQL;INIT=runscript from 
>> '/abs/path/init.sql'"'
>>
>> schema = 'public'
>>
>> }
>>
>> strategy {
>>
>> name = 'org.jooq.util.DefaultGeneratorStrategy'
>>
>> }
>>
>> database {
>>
>> name = 'org.jooq.util.postgres.PostgresDatabase'
>>
>> inputSchema = 'public'
>>
>> }
>>
>> generate {
>>
>> immutablePojos = true
>>
>> daos = true
>>
>> }
>>
>> target {
>>
>> packageName = 'models.db.gen'
>>
>> directory = 'src/main/jooq-generated'
>>
>> }
>>
>> }
>>
>> }
>>
>> }
>>
>>
>> And here's the error output:
>>
>>
>> 04:55:47.446 [main] DEBUG org.jooq.tools.LoggerListener - Executing query  
>>         : select 1 as "one"
>>
>> 04:55:47.473 [main] DEBUG org.jooq.tools.StopWatch - Query executed     
>>       : Total: 34.105ms
>>
>> 04:55:47.605 [main] DEBUG org.jooq.tools.LoggerListener - Fetched result   
>>         : +----+
>>
>> 04:55:47.605 [main] DEBUG org.jooq.tools.LoggerListener -                
>>           : | one|
>>
>> 04:55:47.605 [main] DEBUG org.jooq.tools.LoggerListener -                
>>           : +----+
>>
>> 04:55:47.605 [main] DEBUG org.jooq.tools.LoggerListener -                
>>           : |   1|
>>
>> 04:55:47.605 [main] DEBUG org.jooq.tools.LoggerListener -                
>>           : +----+
>>
>> 04:55:47.606 [main] DEBUG org.jooq.tools.StopWatch - Finishing          
>>       : Total: 169.54ms, +135.435ms
>>
>> 04:55:47.606 [main] DEBUG org.jooq.tools.LoggerListener - Executing query  
>>         : select "pg_catalog"."pg_namespace"."nspname" from 
>> "pg_catalog"."pg_namespace"
>>
>> 04:55:47.608 [main] WARN org.jooq.util.AbstractDatabase - SQL exception  
>>           : Exception while executing meta query: Schema "pg_catalog" 
>> not found; SQL statement:
>>
>> select "pg_catalog"."pg_namespace"."nspname" from 
>> "pg_catalog"."pg_namespace" [90079-196]
>>
>>
>> Any guesses for how I can trick jOOQ into generating PostgreSQL-style 
>> code from an h2 db in Postgres mode?
>>
>>
>> Thanks!
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "jOOQ User Group" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to