[jOOQ/jOOQ#18043] Add MySQL and MariaDB support for ALTER TABLE .. SET

NOT NULL / DROP NOT NULL
This commit is contained in:
Lukas Eder 2025-02-26 16:19:53 +01:00
parent 176588668f
commit 65bb46d315
3 changed files with 28 additions and 2 deletions

View File

@ -167,13 +167,13 @@ public interface AlterTableAlterStep<T> {
* Make the column <code>NOT NULL</code>.
*/
@NotNull @CheckReturnValue
@Support({ DERBY, DUCKDB, FIREBIRD, H2, HSQLDB, POSTGRES, YUGABYTEDB })
@Support({ DERBY, DUCKDB, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, YUGABYTEDB })
AlterTableFinalStep setNotNull();
/**
* Make the column nullable.
*/
@NotNull @CheckReturnValue
@Support({ DERBY, DUCKDB, FIREBIRD, H2, HSQLDB, POSTGRES, YUGABYTEDB })
@Support({ DERBY, DUCKDB, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, YUGABYTEDB })
AlterTableFinalStep dropNotNull();
}

View File

@ -251,6 +251,10 @@ public interface AlterTableStep {
* Add an <code>ALTER COLUMN</code> clause to the <code>ALTER TABLE</code>
* statement.
* <p>
* Note that in some RDBMS, the current column type is required in order to
* alter a column, so for best results, better pass it explicitly with
* {@link #alter(Field)}.
* <p>
* This is an alias for {@link #alterColumn(Name)}
*/
@NotNull @CheckReturnValue
@ -261,6 +265,10 @@ public interface AlterTableStep {
* Add an <code>ALTER COLUMN</code> clause to the <code>ALTER TABLE</code>
* statement.
* <p>
* Note that in some RDBMS, the current column type is required in order to
* alter a column, so for best results, better pass it explicitly with
* {@link #alter(Field)}.
* <p>
* This is an alias for {@link #alterColumn(String)}
*/
@NotNull @CheckReturnValue
@ -278,6 +286,10 @@ public interface AlterTableStep {
/**
* Add an <code>ALTER COLUMN</code> clause to the <code>ALTER TABLE</code>
* statement.
* <p>
* Note that in some RDBMS, the current column type is required in order to
* alter a column, so for best results, better pass it explicitly with
* {@link #alterColumn(Field)}.
*/
@NotNull @CheckReturnValue
@Support({ CLICKHOUSE, CUBRID, DERBY, DUCKDB, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, TRINO, YUGABYTEDB })
@ -286,6 +298,10 @@ public interface AlterTableStep {
/**
* Add an <code>ALTER COLUMN</code> clause to the <code>ALTER TABLE</code>
* statement.
* <p>
* Note that in some RDBMS, the current column type is required in order to
* alter a column, so for best results, better pass it explicitly with
* {@link #alterColumn(Field)}.
*/
@NotNull @CheckReturnValue
@Support({ CLICKHOUSE, CUBRID, DERBY, DUCKDB, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, TRINO, YUGABYTEDB })

View File

@ -1622,6 +1622,16 @@ implements
// [#18043] Assuming users provide explicit data types of the existing column, we can reference it again
case MARIADB:
case MYSQL:
ctx.sql(' ');
toSQLDDLTypeDeclaration(ctx, alterColumn.getDataType());
ctx.sql(' ').visit(alterColumnNullability.nullable() ? K_NULL : K_NOT_NULL);
break;
default:
ctx.sql(' ').visit(alterColumnNullability.nullable() ? K_DROP_NOT_NULL : K_SET_NOT_NULL);
break;