File: index-unique-constraint.txt

package info (click to toggle)
golang-ariga-atlas 0.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 5,676 kB
  • sloc: javascript: 592; sql: 404; makefile: 10
file content (100 lines) | stat: -rw-r--r-- 2,232 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# 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]
    type    = BTREE
  }
  index "users_nickname_key" {
    unique  = true
    columns = [column.nickname]
    type    = BTREE
  }
}
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]
    type    = BTREE
  }
}
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 |           |          |