mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
dialect/sql: add drop-fk command to builder
This commit is contained in:
@@ -264,6 +264,12 @@ func (t *TableAlter) DropConstraint(ident string) *TableAlter {
|
||||
return t
|
||||
}
|
||||
|
||||
// DropForeignKey appends the `DROP FOREIGN KEY` clause to the given `ALTER TABLE` statement.
|
||||
func (t *TableAlter) DropForeignKey(ident string) *TableAlter {
|
||||
t.Queries = append(t.Queries, Raw(fmt.Sprintf("DROP FOREIGN KEY %s", t.Quote(ident))))
|
||||
return t
|
||||
}
|
||||
|
||||
// Query returns query representation of the `ALTER TABLE` statement.
|
||||
//
|
||||
// ALTER TABLE name
|
||||
|
||||
@@ -133,6 +133,11 @@ func TestBuilder(t *testing.T) {
|
||||
AddColumn(Column("name").Type("varchar(255)")),
|
||||
wantQuery: "ALTER TABLE `users` ADD COLUMN `age` int, ADD COLUMN `name` varchar(255)",
|
||||
},
|
||||
{
|
||||
input: AlterTable("users").
|
||||
DropForeignKey("users_parent_id"),
|
||||
wantQuery: "ALTER TABLE `users` DROP FOREIGN KEY `users_parent_id`",
|
||||
},
|
||||
{
|
||||
input: Dialect(dialect.Postgres).AlterTable("users").
|
||||
AddColumn(Column("age").Type("int")).
|
||||
|
||||
Reference in New Issue
Block a user