dialect/sql/entsql: support setting expression as column default value

Fixed https://github.com/ent/ent/issues/3069
This commit is contained in:
Ariel Mashraki
2022-11-11 21:47:10 +02:00
committed by Ariel Mashraki
parent 3b5a535801
commit 1e5f68646f
17 changed files with 744 additions and 33 deletions

View File

@@ -816,7 +816,15 @@ func (d *MySQL) atTable(t1 *Table, t2 *schema.Table) {
func (d *MySQL) supportsDefault(c *Column) bool {
_, maria := d.mariadb()
return c.supportDefault() || maria
switch c.Default.(type) {
case Expr, map[string]Expr:
if maria {
return compareVersions(d.version, "10.2.0") >= 0
}
return c.supportDefault() && compareVersions(d.version, "8.0.0") >= 0
default:
return c.supportDefault() || maria
}
}
func (d *MySQL) atTypeC(c1 *Column, c2 *schema.Column) error {