I'm trying to use jOOQ as a schema generator to generate DDL statements, and later to generate SQL insert statements.
The underlying data is coming from static CSV files and I basically want to write a static SQL script which includes statements to create the schema and insert the data; merely a dump file.
For example I have this Groovy class containing the table deifnition:
class ContinentTable extends CustomTable<Record> {
static ContinentTable CONTINENT = new ContinentTable()
static UniqueKey<Record> CONTINENT_PK = createUniqueKey(CONTINENT, name("continent_pk"), [CONTINENT.ID] as TableField[], true)
TableField<Record, String> ID = createField(name("id"), VARCHAR(255).nullable(false))
TableField<Record, String> CODE = createField(name("code"), VARCHAR(2).nullable(false))
TableField<Record, String> NAME = createField(name("name"), VARCHAR(255).nullable(false))
TableField<Record, String> DEMONYM = createField(name("demonym"), VARCHAR(255).nullable(false))
private ContinentTable() {
super(name("continent"))
}
@Override
Class<? extends Record> getRecordType() {
return Record
}
@Override
UniqueKey<Record> getPrimaryKey() {
return CONTINENT_PK
}
}
It contains the fields and the PK, but when I use jOOQ to create the SQL statement with:
dsl.createTable(ContinentTable.CONTINENT)
it only generates:
create table "continent";
without the columns. Off course I could do something like:
dsl.createTable(ContinentTable.CONTINENT).columns(ContinentTable.CONTINENT.fields())
but it seems a bit of unnecessary as I already pass in the table??
It gets more complex if I want to add primary keys and possible foreign keys, indexes etc.
Is it expected behaviour that these are all not added when calling dsl.createTable(ContinentTable.CONTINENT)
?
Note: I'm creating the ContinentTable
manually as I'm not using codegen as I have no source database.