Skip to content

Commit

Permalink
docs: EXPOSED-207 Add link to SQLite ALTER TABLE restrictions in Sche…
Browse files Browse the repository at this point in the history
…maUtils Kdocs

- Minor edits
- Add missing KDocs from previous PR
- Auto-correct with Detekt
  • Loading branch information
bog-walk committed Dec 18, 2024
1 parent 9d42b0c commit e552358
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
17 changes: 14 additions & 3 deletions exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Alias.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class Alias<out T : Table>(val delegate: T, val alias: String) : Table() {
override val columns: List<Column<*>> = fields.filterIsInstance<Column<*>>()

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")

Expand Down Expand Up @@ -107,13 +109,19 @@ class Alias<out T : Table>(val delegate: T, val alias: String) : Table() {
.orEmpty()
}

/** Interface common to all [Expression]s with temporary SQL identifiers. */
interface IExpressionAlias<T> {
/** The aliased expression. */
val delegate: Expression<T>

/** 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)"
Expand All @@ -135,7 +143,10 @@ interface IExpressionAlias<T> {
}

/** Represents a temporary SQL identifier, [alias], for a [delegate] expression. */
class ExpressionAlias<T>(override val delegate: Expression<T>, override val alias: String) : Expression<T>(), IExpressionAlias<T> {
class ExpressionAlias<T>(
override val delegate: Expression<T>,
override val alias: String
) : Expression<T>(), IExpressionAlias<T> {
override fun toQueryBuilder(queryBuilder: QueryBuilder) = this.queryBuilder(queryBuilder)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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`.
Expand Down
10 changes: 6 additions & 4 deletions exposed-migration/src/main/kotlin/MigrationUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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<String> {
if (tables.isEmpty()) return emptyList()
Expand Down

0 comments on commit e552358

Please sign in to comment.