mirror of
https://github.com/ent/ent.git
synced 2026-05-06 01:20:56 +03:00
dialect/sql/schema: allow migrations from integer to string without size limit (#952)
* Allow migrations from integer to string without size limit * Update entc/integration/migrate/entv1/schema/user.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * run generate * Update entc/integration/migrate/entv2/schema/user.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
This commit is contained in:
@@ -186,6 +186,9 @@ func (c *Column) ConvertibleTo(d *Column) bool {
|
||||
case c.Type == field.TypeString && d.Type == field.TypeEnum ||
|
||||
c.Type == field.TypeEnum && d.Type == field.TypeString:
|
||||
return true
|
||||
// Allow conversions to arbitrary length strings
|
||||
case c.Type.Integer() && d.Type == field.TypeString && d.Size == 0:
|
||||
return true
|
||||
}
|
||||
return c.FloatType() && d.FloatType()
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ func TestColumn_ConvertibleTo(t *testing.T) {
|
||||
require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint8}))
|
||||
require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint16}))
|
||||
require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint32}))
|
||||
require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeString}))
|
||||
require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeString}))
|
||||
require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeString, Size: 1}))
|
||||
|
||||
c1 = &Column{Type: field.TypeInt}
|
||||
require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeInt}))
|
||||
@@ -51,7 +52,8 @@ func TestColumn_ConvertibleTo(t *testing.T) {
|
||||
require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint8}))
|
||||
require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint16}))
|
||||
require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint32}))
|
||||
require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeString}))
|
||||
require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeString}))
|
||||
require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeString, Size: 1}))
|
||||
}
|
||||
|
||||
func TestColumn_ScanDefault(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user