# Create table with UNIQUE constraint. i.e. implicit unique index.
execsql 'CREATE TABLE script_index_unique_constraint.users (name text, last text, nickname text UNIQUE, UNIQUE(name, last))'
cmphcl 1.inspect.hcl

# Dropping the unique index on the "nickname" column should drop the constraint as well.
apply 2.hcl
cmpshow users 2.sql

apply 3.hcl
cmpshow users 3.sql

-- 1.inspect.hcl --
table "users" {
  schema = schema.script_index_unique_constraint
  column "name" {
    null = true
    type = text
  }
  column "last" {
    null = true
    type = text
  }
  column "nickname" {
    null = true
    type = text
  }
  index "users_name_last_key" {
    unique  = true
    columns = [column.name, column.last]
  }
  index "users_nickname_key" {
    unique  = true
    columns = [column.nickname]
  }
}
schema "script_index_unique_constraint" {
}

-- 2.hcl --
table "users" {
  schema = schema.script_index_unique_constraint
  column "name" {
    null = true
    type = text
  }
  column "last" {
    null = true
    type = text
  }
  column "nickname" {
    null = true
    type = text
  }
  index "users_name_last_key" {
    unique  = true
    columns = [column.name, column.last]
  }
}
schema "script_index_unique_constraint" {
}

-- 2.sql --
   Table "script_index_unique_constraint.users"
  Column  | Type | Collation | Nullable | Default
----------+------+-----------+----------+---------
 name     | text |           |          |
 last     | text |           |          |
 nickname | text |           |          |
Indexes:
    "users_name_last_key" UNIQUE CONSTRAINT, btree (name, last)

-- 3.hcl --
table "users" {
  schema = schema.script_index_unique_constraint
  column "name" {
    null = true
    type = text
  }
  column "last" {
    null = true
    type = text
  }
  column "nickname" {
    null = true
    type = text
  }
}
schema "script_index_unique_constraint" {
}

-- 3.sql --
   Table "script_index_unique_constraint.users"
  Column  | Type | Collation | Nullable | Default
----------+------+-----------+----------+---------
 name     | text |           |          |
 last     | text |           |          |
 nickname | text |           |          |