You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4fda08d
Browse filesBrowse the repository at this point in the historyBrowse files
fix(codegen-kotlin): emit imports for non-default Exposed column functions
KotlinExposedTableGenerator was emitting only `import org.jetbrains.exposed.sql.Table`,
so generated Tables that use column functions from non-default Exposed packages
(`date`, `time`, `datetime`, `timestamp`, `timestampWithTimeZone`, `duration` —
extension functions on Table that live in `org.jetbrains.exposed.sql.javatime.*`)
compile-fail with "unresolved reference" errors. Functions inherited from Table
(`varchar`, `integer`, `long`, `double`, `bool`, `text`, `uuid`, `enumerationByName`)
were unaffected; the bug only surfaces on tables with date/timestamp fields, which
is why the existing snapshot fixtures shipped with the bug latent.
Snapshot tests check text equality, not compilation — so the missing imports
silently rode along inside the fixtures. Downstream adopters that try to compile
the generated Tables hit the failure immediately.
The fix:
- New `KotlinTypeMapper.exposedColumnImport(field)` returns the FQN to import for
each field subtype that needs a non-default Exposed package (currently DateField
and TimestampField), or null when the column function is a Table member.
- `KotlinExposedTableGenerator.emit` walks the entity's MetaFields (including
flattened object sub-fields) and collects the required imports into a sorted set,
then emits them in the file header after the `Table` import.
- Snapshot fixture `single-entity-primitives/acme/demo/AuthorTable.kt` updated to
carry the now-correct javatime imports.
- Added three regression tests in `KotlinExposedTableGeneratorTest`:
`dateAndTimestampFieldsEmitJavatimeImports`,
`primitiveOnlyTableEmitsNoExtraImports` (no spurious imports), and
`flattenedSubFieldDateContributesImport` (sub-field imports propagate).
All 81 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinExposedTableGenerator.kt
+33Lines changed: 33 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -122,6 +122,36 @@ class KotlinExposedTableGenerator : MultiFileDirectGeneratorBase<MetaObject>() {
122
122
val needsJsonbImport = objectColumns.any { it.kind ==ObjectColumnKind.JSONB }
123
123
val needsRefOptForDecor = refDecorations.values.any { it.hasReferenceOption }
124
124
125
+
// Walk every field that will actually become a Table column and collect the
126
+
// imports its column function requires. Member functions on Table (varchar,
127
+
// integer, long, etc.) return null and are skipped; extension functions from
Copy file name to clipboardExpand all lines: server/java/codegen-kotlin/src/test/kotlin/com/metaobjects/generator/kotlin/KotlinExposedTableGeneratorTest.kt
+121Lines changed: 121 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -656,6 +656,127 @@ class KotlinExposedTableGeneratorTest {
0 commit comments