From e5523582c8573e4f5edf263fa12d285ee4168c3d Mon Sep 17 00:00:00 2001 From: Chantal Loncle <82039410+bog-walk@users.noreply.github.com> Date: Wed, 18 Dec 2024 07:01:51 -0500 Subject: [PATCH] docs: EXPOSED-207 Add link to SQLite ALTER TABLE restrictions in SchemaUtils Kdocs - Minor edits - Add missing KDocs from previous PR - Auto-correct with Detekt --- .../kotlin/org/jetbrains/exposed/sql/Alias.kt | 17 ++++++++++++++--- .../org/jetbrains/exposed/sql/SchemaUtils.kt | 13 ++++++++----- .../src/main/kotlin/MigrationUtils.kt | 10 ++++++---- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Alias.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Alias.kt index db49c31f76..4a8879572f 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Alias.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Alias.kt @@ -43,7 +43,9 @@ class Alias(val delegate: T, val alias: String) : Table() { override val columns: List> = fields.filterIsInstance>() override val primaryKey: PrimaryKey? = delegate.primaryKey?.columns - ?.firstNotNullOfOrNull { delegateColumn -> columns.find { it.name == delegateColumn.name } }?.let { PrimaryKey(it) } + ?.firstNotNullOfOrNull { delegateColumn -> + columns.find { it.name == delegateColumn.name } + }?.let { PrimaryKey(it) } override fun createStatement() = throw UnsupportedOperationException("Unsupported for aliases") @@ -107,13 +109,19 @@ class Alias(val delegate: T, val alias: String) : Table() { .orEmpty() } +/** Interface common to all [Expression]s with temporary SQL identifiers. */ interface IExpressionAlias { + /** The aliased expression. */ val delegate: Expression + /** The temporary SQL identifier string. */ val alias: String + /** Appends the SQL representation of this aliased expression to the specified [queryBuilder]. */ fun queryBuilder(queryBuilder: QueryBuilder) = queryBuilder { - if (delegate is ComparisonOp && (currentDialectIfAvailable is SQLServerDialect || currentDialectIfAvailable is OracleDialect)) { + if (delegate is ComparisonOp && + (currentDialectIfAvailable is SQLServerDialect || currentDialectIfAvailable is OracleDialect) + ) { +"(CASE WHEN " append(delegate) +" THEN 1 ELSE 0 END)" @@ -135,7 +143,10 @@ interface IExpressionAlias { } /** Represents a temporary SQL identifier, [alias], for a [delegate] expression. */ -class ExpressionAlias(override val delegate: Expression, override val alias: String) : Expression(), IExpressionAlias { +class ExpressionAlias( + override val delegate: Expression, + override val alias: String +) : Expression(), IExpressionAlias { override fun toQueryBuilder(queryBuilder: QueryBuilder) = this.queryBuilder(queryBuilder) } diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt index c2844270c2..49333a0caa 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SchemaUtils.kt @@ -318,7 +318,8 @@ object SchemaUtils { * This can be disabled by setting [withLogs] to `false`. * * **Note:** Some databases, like **SQLite**, only support `ALTER TABLE ADD COLUMN` syntax in very restricted cases, - * which may cause unexpected behavior when adding some missing columns. Please check the documentation. + * which may cause unexpected behavior when adding some missing columns. For more information, + * refer to the relevant documentation. * For SQLite, see [ALTER TABLE restrictions](https://www.sqlite.org/lang_altertable.html#alter_table_add_column). */ fun addMissingColumnsStatements(vararg tables: Table, withLogs: Boolean = true): List { @@ -574,8 +575,9 @@ object SchemaUtils { * (for example, when columns are nullable or have default values). * * **Note:** Some databases, like **SQLite**, only support `ALTER TABLE ADD COLUMN` syntax in very restricted cases, - * which may cause unexpected behavior when adding some missing columns. Please check the documentation. - * For SQLite, please see [ALTER TABLE restrictions](https://www.sqlite.org/lang_altertable.html#alter_table_add_column). + * which may cause unexpected behavior when adding some missing columns. For more information, + * refer to the relevant documentation. + * For SQLite, see [ALTER TABLE restrictions](https://www.sqlite.org/lang_altertable.html#alter_table_add_column). * * Also, if there is inconsistency between the database schema and table objects (for example, * excessive or missing indices), then SQL statements to fix this will be logged at the INFO level. @@ -628,8 +630,9 @@ object SchemaUtils { * the table objects defined using Exposed. * * **Note:** Some databases, like **SQLite**, only support `ALTER TABLE ADD COLUMN` syntax in very restricted cases, - * which may cause unexpected behavior when adding some missing columns. Please check the documentation. - * For SQLite, please see [ALTER TABLE restrictions](https://www.sqlite.org/lang_altertable.html#alter_table_add_column). + * which may cause unexpected behavior when adding some missing columns. For more information, + * refer to the relevant documentation. + * For SQLite, see [ALTER TABLE restrictions](https://www.sqlite.org/lang_altertable.html#alter_table_add_column). * * By default, a description for each intermediate step, as well as its execution time, is logged at the INFO level. * This can be disabled by setting [withLogs] to `false`. diff --git a/exposed-migration/src/main/kotlin/MigrationUtils.kt b/exposed-migration/src/main/kotlin/MigrationUtils.kt index f106e8c797..0ae685f1a0 100644 --- a/exposed-migration/src/main/kotlin/MigrationUtils.kt +++ b/exposed-migration/src/main/kotlin/MigrationUtils.kt @@ -62,8 +62,9 @@ object MigrationUtils { * included. * * **Note:** Some databases, like **SQLite**, only support `ALTER TABLE ADD COLUMN` syntax in very restricted cases, - * which may cause unexpected behavior when adding some missing columns. Please check the documentation. - * For SQLite, please see [ALTER TABLE restrictions](https://www.sqlite.org/lang_altertable.html#alter_table_add_column). + * which may cause unexpected behavior when adding some missing columns. For more information, + * refer to the relevant documentation. + * For SQLite, see [ALTER TABLE restrictions](https://www.sqlite.org/lang_altertable.html#alter_table_add_column). * * By default, a description for each intermediate step, as well as its execution time, is logged at the INFO level. * This can be disabled by setting [withLogs] to `false`. @@ -99,8 +100,9 @@ object MigrationUtils { * This can be disabled by setting [withLogs] to `false`. * * **Note:** Some databases, like **SQLite**, only support `ALTER TABLE DROP COLUMN` syntax in very restricted cases, - * which may cause unexpected behavior when dropping some unmapped columns. Please check the documentation. - * For SQLite, please see [ALTER TABLE restrictions](https://www.sqlite.org/lang_altertable.html#alter_table_drop_column). + * which may cause unexpected behavior when dropping some unmapped columns. For more information, + * refer to the relevant documentation. + * For SQLite, see [ALTER TABLE restrictions](https://www.sqlite.org/lang_altertable.html#alter_table_drop_column). */ fun dropUnmappedColumnsStatements(vararg tables: Table, withLogs: Boolean = true): List { if (tables.isEmpty()) return emptyList()