From 86e7fa40b45afd491cbe0555c6c05a2e1994b8e4 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Tue, 12 Nov 2019 17:04:31 +0100 Subject: [PATCH] [jOOQ/jOOQ#9534] Add support ALTER TABLE .. DROP UNIQUE --- .../main/java/org/jooq/AlterTableStep.java | 40 +++++++++++++++++++ .../java/org/jooq/impl/AlterTableImpl.java | 25 ++++++++++++ 2 files changed, 65 insertions(+) diff --git a/jOOQ/src/main/java/org/jooq/AlterTableStep.java b/jOOQ/src/main/java/org/jooq/AlterTableStep.java index 554154ad8c..433edb21ee 100644 --- a/jOOQ/src/main/java/org/jooq/AlterTableStep.java +++ b/jOOQ/src/main/java/org/jooq/AlterTableStep.java @@ -638,6 +638,46 @@ public interface AlterTableStep { @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) AlterTableDropStep dropPrimaryKey(String constraint); + /** + * Add a DROP UNIQUE clause to the ALTER TABLE + * statement. + *

+ * Some dialects (e.g. {@link SQLDialect#COCKROACHDB}) may not be able to + * drop constraints by name. If users specify the constraint type + * and the name, however, then the syntax can be emulated, e.g. + * using DROP INDEX .. CASCADE. + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + AlterTableDropStep dropUnique(Constraint constraint); + + /** + * Add a DROP UNIQUE clause to the ALTER TABLE + * statement. + *

+ * Some dialects (e.g. {@link SQLDialect#COCKROACHDB}) may not be able to + * drop constraints by name. If users specify the constraint type + * and the name, however, then the syntax can be emulated, e.g. + * using DROP INDEX .. CASCADE. + * + * @see DSL#constraint(Name) + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + AlterTableDropStep dropUnique(Name constraint); + + /** + * Add a DROP UNIQUE clause to the ALTER TABLE + * statement. + *

+ * Some dialects (e.g. {@link SQLDialect#COCKROACHDB}) may not be able to + * drop constraints by name. If users specify the constraint type + * and the name, however, then the syntax can be emulated, e.g. + * using DROP INDEX .. CASCADE. + * + * @see DSL#constraint(String) + */ + @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + AlterTableDropStep dropUnique(String constraint); + /** * Add a DROP FOREIGN KEY clause to the ALTER TABLE * statement. diff --git a/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java b/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java index e186266337..21487bb1f9 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java @@ -76,6 +76,7 @@ import static org.jooq.impl.Cascade.CASCADE; import static org.jooq.impl.Cascade.RESTRICT; import static org.jooq.impl.ConstraintType.FOREIGN_KEY; import static org.jooq.impl.ConstraintType.PRIMARY_KEY; +import static org.jooq.impl.ConstraintType.UNIQUE; import static org.jooq.impl.DSL.begin; import static org.jooq.impl.DSL.commentOnTable; import static org.jooq.impl.DSL.condition; @@ -826,6 +827,23 @@ final class AlterTableImpl extends AbstractRowCountQuery implements return dropPrimaryKey(constraint(constraint)); } + @Override + public final AlterTableImpl dropUnique(Constraint constraint) { + dropConstraint = constraint; + dropConstraintType = UNIQUE; + return this; + } + + @Override + public final AlterTableImpl dropUnique(Name constraint) { + return dropUnique(constraint(constraint)); + } + + @Override + public final AlterTableImpl dropUnique(String constraint) { + return dropUnique(constraint(constraint)); + } + @Override public final AlterTableImpl dropForeignKey(Constraint constraint) { dropConstraint = constraint; @@ -1009,6 +1027,13 @@ final class AlterTableImpl extends AbstractRowCountQuery implements + + + + + + +