diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go index 043f824b..c2bbe93f 100644 --- a/pkg/state/state_test.go +++ b/pkg/state/state_test.go @@ -107,6 +107,12 @@ func TestReadSchema(t *testing.T) { Name: "id_unique", }, }, + UniqueConstraints: map[string]schema.UniqueConstraint{ + "id_unique": { + Name: "id_unique", + Columns: []string{"id"}, + }, + }, }, }, }, @@ -193,6 +199,47 @@ func TestReadSchema(t *testing.T) { }, }, }, + { + name: "unique constraint", + createStmt: "CREATE TABLE public.table1 (id int PRIMARY KEY, name TEXT, CONSTRAINT name_unique UNIQUE(name) );", + wantSchema: &schema.Schema{ + Name: "public", + Tables: map[string]schema.Table{ + "table1": { + Name: "table1", + Columns: map[string]schema.Column{ + "id": { + Name: "id", + Type: "integer", + Nullable: false, + Unique: true, + }, + "name": { + Name: "name", + Type: "text", + Unique: true, + Nullable: true, + }, + }, + PrimaryKey: []string{"id"}, + Indexes: map[string]schema.Index{ + "table1_pkey": { + Name: "table1_pkey", + }, + "name_unique": { + Name: "name_unique", + }, + }, + UniqueConstraints: map[string]schema.UniqueConstraint{ + "name_unique": { + Name: "name_unique", + Columns: []string{"name"}, + }, + }, + }, + }, + }, + }, } // init the state