-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework jooq codegen for consistent clean builds
- Loading branch information
1 parent
ce0530c
commit c927142
Showing
9 changed files
with
230 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.Directory | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.* | ||
import org.flywaydb.core.Flyway | ||
|
||
// For various reasons, don't use the flyway gradle plugin | ||
// https://github.com/flyway/flyway/issues/3550 | ||
@CacheableTask | ||
abstract class FlywayMigrateTask : DefaultTask() { | ||
|
||
@get:Input | ||
abstract val driver: Property<String> | ||
|
||
@get:Input | ||
abstract val url: Property<String> | ||
|
||
@get:InputDirectory | ||
@get:PathSensitive(PathSensitivity.RELATIVE) | ||
abstract var migrationsLocation: Directory | ||
|
||
// Output is required to make the task cacheable | ||
@OutputFile | ||
val outputFile: RegularFileProperty = project.objects.fileProperty().convention( | ||
project.layout.buildDirectory.file(url.map { it.substringAfterLast(":") }) | ||
) | ||
|
||
@TaskAction | ||
fun run() { | ||
Flyway.configure() | ||
.driver(driver.get()) | ||
.dataSource(url.get(), null, null) | ||
.locations("filesystem:${migrationsLocation.asFile}") | ||
.load() | ||
.migrate() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import org.jooq.meta.jaxb.Configuration | ||
import org.jooq.meta.jaxb.ForcedType | ||
import org.jooq.meta.jaxb.Logging | ||
|
||
|
||
fun Configuration.anystreamConfig(dbUrl: String) { | ||
logging = Logging.DEBUG | ||
jdbc.apply { | ||
driver = "org.sqlite.JDBC" | ||
url = dbUrl | ||
} | ||
generator.apply { | ||
name = "Generator" | ||
strategy.name = "JooqStrategy" | ||
target.packageName = "anystream.db" | ||
generate.apply { | ||
isDaos = false | ||
isRecords = true | ||
isKotlinNotNullRecordAttributes = true | ||
isKotlinNotNullInterfaceAttributes = true | ||
isJavaTimeTypes = false | ||
// Pojos as simple data classes | ||
isSerializablePojos = false | ||
isImmutablePojos = true | ||
isPojosToString = false | ||
isPojosEqualsAndHashCode = false | ||
isPojosAsKotlinDataClasses = true | ||
isKotlinNotNullPojoAttributes = true | ||
} | ||
database.apply { | ||
name = "org.jooq.meta.sqlite.SQLiteDatabase" | ||
excludes = listOf( | ||
// Exclude flyway migration tables | ||
"flyway_.*", | ||
// Exclude search meta tables | ||
"searchable_content_.*", | ||
).joinToString("|") | ||
forcedTypes.addAll(forcedTypes()) | ||
} | ||
} | ||
} | ||
|
||
fun forcedType( | ||
userType: String, | ||
includeExpression: String, | ||
converter: String? = null, | ||
isEnumConverter: Boolean = false | ||
): ForcedType = | ||
ForcedType().apply { | ||
this.userType = userType | ||
this.includeExpression = includeExpression | ||
this.isEnumConverter = isEnumConverter | ||
this.converter = converter | ||
} | ||
|
||
fun forcedTypeEnum( | ||
userType: String, | ||
includeExpression: String, | ||
): ForcedType = forcedType(userType, includeExpression, isEnumConverter = true) | ||
|
||
fun forcedTypes(): List<ForcedType> = listOf( | ||
ForcedType().apply { | ||
includeTypes = "DATETIME" | ||
userType = "kotlinx.datetime.Instant" | ||
binding = "anystream.db.converter.JooqInstantBinding" | ||
//generator = "anystream.db.converter.JooqInstantGenerator" | ||
}, | ||
forcedType( | ||
userType = "anystream.models.Permission", | ||
includeExpression = "user_permission.value", | ||
converter = "anystream.db.converter.PermissionConverter" | ||
), | ||
forcedType( | ||
userType = "anystream.models.Permission", | ||
includeExpression = "user_permission.value", | ||
converter = "anystream.db.converter.PermissionConverter" | ||
), | ||
forcedType( | ||
userType = "anystream.models.Permission", | ||
includeExpression = "user_permission.value", | ||
converter = "anystream.db.converter.PermissionConverter" | ||
), | ||
forcedType( | ||
userType = "kotlin.Set<anystream.models.Permission>", | ||
includeExpression = "invite_code.permissions", | ||
converter = "anystream.db.converter.PermissionSetConverter" | ||
), | ||
forcedTypeEnum("anystream.models.StreamEncodingType", "stream_encoding.type"), | ||
forcedTypeEnum("anystream.models.MediaType", "media_type"), | ||
forcedTypeEnum("anystream.models.MediaLinkType", "media_link.type"), | ||
forcedTypeEnum("anystream.models.MediaKind", "media_kind"), | ||
forcedTypeEnum("anystream.models.Descriptor", "descriptor"), | ||
forcedType("kotlin.String", "searchable_content.id"), | ||
forcedType("kotlin.String", "searchable_content.content"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import org.gradle.api.JavaVersion | ||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
|
||
val JAVA_TARGET = JavaVersion.VERSION_17 | ||
val JAVA_TARGET = JavaVersion.VERSION_17 | ||
val JVM_TARGET = JvmTarget.JVM_17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.