mirror of
https://github.com/ent/ent.git
synced 2026-04-28 05:30:56 +03:00
schema/field: add the Unique option to the UUID field builder (#579)
* add the Unique option to the UUID field builder * Update schema/field/field_test.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:
committed by
GitHub
parent
0ebb0f5e13
commit
902b29d9bf
@@ -663,6 +663,12 @@ func (b *uuidBuilder) Optional() *uuidBuilder {
|
||||
return b
|
||||
}
|
||||
|
||||
// Unique makes the field unique within all vertices of this type.
|
||||
func (b *uuidBuilder) Unique() *uuidBuilder {
|
||||
b.desc.Unique = true
|
||||
return b
|
||||
}
|
||||
|
||||
// Immutable indicates that this field cannot be updated.
|
||||
func (b *uuidBuilder) Immutable() *uuidBuilder {
|
||||
b.desc.Immutable = true
|
||||
|
||||
@@ -342,9 +342,11 @@ func TestField_Enums(t *testing.T) {
|
||||
|
||||
func TestField_UUID(t *testing.T) {
|
||||
fd := field.UUID("id", uuid.UUID{}).
|
||||
Unique().
|
||||
Default(uuid.New).
|
||||
Descriptor()
|
||||
assert.Equal(t, "id", fd.Name)
|
||||
assert.True(t, fd.Unique)
|
||||
assert.Equal(t, "uuid.UUID", fd.Info.String())
|
||||
assert.Equal(t, "github.com/google/uuid", fd.Info.PkgPath)
|
||||
assert.NotNil(t, fd.Default)
|
||||
|
||||
Reference in New Issue
Block a user