mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
dialect/sql/schema: alter column for postgres
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/117 Reviewed By: alexsn Differential Revision: D18083914 fbshipit-source-id: a5f6993cfe9a260a84c0d4ab868e3e797b3a5776
This commit is contained in:
committed by
Facebook Github Bot
parent
a0c7ee77dc
commit
c414cd9a82
@@ -54,10 +54,10 @@ func (c *ColumnBuilder) Attr(attr string) *ColumnBuilder {
|
||||
// Query returns query representation of a Column.
|
||||
func (c *ColumnBuilder) Query() (string, []interface{}) {
|
||||
c.Ident(c.name)
|
||||
if c.postgres() && c.modify {
|
||||
c.Pad().WriteString("TYPE")
|
||||
}
|
||||
if c.typ != "" {
|
||||
if c.postgres() && c.modify {
|
||||
c.Pad().WriteString("TYPE")
|
||||
}
|
||||
c.Pad().WriteString(c.typ)
|
||||
}
|
||||
if c.attr != "" {
|
||||
@@ -225,7 +225,7 @@ func (t *TableAlter) AddColumn(c *ColumnBuilder) *TableAlter {
|
||||
return t
|
||||
}
|
||||
|
||||
// Modify appends the `MODIFY COLUMN` clause to the given `ALTER TABLE` statement.
|
||||
// Modify appends the `MODIFY/ALTER COLUMN` clause to the given `ALTER TABLE` statement.
|
||||
func (t *TableAlter) ModifyColumn(c *ColumnBuilder) *TableAlter {
|
||||
switch {
|
||||
case t.postgres():
|
||||
@@ -237,6 +237,14 @@ func (t *TableAlter) ModifyColumn(c *ColumnBuilder) *TableAlter {
|
||||
return t
|
||||
}
|
||||
|
||||
// ModifyColumns calls ModifyColumn with each of the given builders.
|
||||
func (t *TableAlter) ModifyColumns(cs ...*ColumnBuilder) *TableAlter {
|
||||
for _, c := range cs {
|
||||
t.ModifyColumn(c)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// DropColumn appends the `DROP COLUMN` clause to the given `ALTER TABLE` statement.
|
||||
func (t *TableAlter) DropColumn(c *ColumnBuilder) *TableAlter {
|
||||
t.Queries = append(t.Queries, &Wrapper{"DROP COLUMN %s", c})
|
||||
|
||||
Reference in New Issue
Block a user