mirror of
https://github.com/ent/ent.git
synced 2026-05-03 08:00:58 +03:00
dialect/sql/schema: initial work for incremental migration (#428)
This is a WIP PR and should be ignored this moment. It's based on PR #221 created by Erik Hollensbe (He should get his credit for his work before we land this).
This commit is contained in:
@@ -382,3 +382,21 @@ func (d *Postgres) renameIndex(t *Table, old, new *Index) sql.Querier {
|
||||
func (d *Postgres) tableSchema() sql.Querier {
|
||||
return sql.Raw("(CURRENT_SCHEMA())")
|
||||
}
|
||||
|
||||
// alterColumns returns the queries for applying the columns change-set.
|
||||
func (d *Postgres) alterColumns(table string, add, modify, drop []*Column) sql.Queries {
|
||||
b := sql.Dialect(dialect.Postgres).AlterTable(table)
|
||||
for _, c := range add {
|
||||
b.AddColumn(d.addColumn(c))
|
||||
}
|
||||
for _, c := range modify {
|
||||
b.ModifyColumns(d.alterColumn(c)...)
|
||||
}
|
||||
for _, c := range drop {
|
||||
b.DropColumn(sql.Dialect(dialect.Postgres).Column(c.Name))
|
||||
}
|
||||
if len(b.Queries) == 0 {
|
||||
return nil
|
||||
}
|
||||
return sql.Queries{b}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user