Skip to content

Commit

Permalink
Add test for db schema with a UNIQUE constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-farries committed Jan 18, 2024
1 parent 5b7a2f3 commit a0bf665
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pkg/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
},
},
},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a0bf665

Please sign in to comment.