dialect/entsql: add support for table checks in schema/migration

This commit is contained in:
Ariel Mashraki
2021-06-17 23:11:12 +03:00
committed by Ariel Mashraki
parent b8f4614bfd
commit 42a2c67cc4
11 changed files with 111 additions and 6 deletions

View File

@@ -45,6 +45,9 @@ func TestMySQL(t *testing.T) {
clientv1 := entv1.NewClient(entv1.Driver(drv))
clientv2 := entv2.NewClient(entv2.Driver(drv))
V1ToV2(t, drv.Dialect(), clientv1, clientv2)
if version == "8" {
CheckConstraint(t, clientv2)
}
})
}
}
@@ -73,6 +76,7 @@ func TestPostgres(t *testing.T) {
clientv1 := entv1.NewClient(entv1.Driver(drv))
clientv2 := entv2.NewClient(entv2.Driver(drv))
V1ToV2(t, drv.Dialect(), clientv1, clientv2)
CheckConstraint(t, clientv2)
})
}
}
@@ -101,6 +105,7 @@ func TestSQLite(t *testing.T) {
require.NoError(t, err)
EqualFold(t, client)
ContainsFold(t, client)
CheckConstraint(t, client)
}
func TestStorageKey(t *testing.T) {
@@ -294,6 +299,15 @@ func SanityV2(t *testing.T, dbdialect string, client *entv2.Client) {
}
}
func CheckConstraint(t *testing.T, client *entv2.Client) {
ctx := context.Background()
t.Log("testing check constraints")
_, err := client.Media.Create().SetText("boring").Save(ctx)
require.Error(t, err)
_, err = client.Media.Create().SetSourceURI("entgo.io").Save(ctx)
require.Error(t, err)
}
func EqualFold(t *testing.T, client *entv2.Client) {
ctx := context.Background()
t.Log("testing equal-fold on sql specific dialects")