Skip to content

Commit 16173dd

Browse files
authored
Document new constraint type in create_constraint: primary_key (#839)
1 parent 9fb0548 commit 16173dd

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

docs/operations/create_constraint.mdx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: A create constraint operation adds a new constraint to an existing
55

66
## Structure
77

8-
`UNIQUE`, `CHECK` and `FOREIGN KEY` constraints are supported.
8+
`UNIQUE`, `CHECK`, `PRIMARY KEY` and `FOREIGN KEY` constraints are supported.
99

1010
Required fields: `name`, `table`, `type`, `up`, `down`.
1111

@@ -15,7 +15,7 @@ create_constraint:
1515
table: name of table
1616
name: my_unique_constraint
1717
columns: [column1, column2]
18-
type: unique | check | foreign_key
18+
type: unique | check | primary_key | foreign_key
1919
check: SQL expression for CHECK constraint
2020
no_inherit: true|false
2121
references:
@@ -103,6 +103,15 @@ Add a check constraint on the `sellers_name` and `sellers_zip` fields on the `ti
103103

104104
<ExampleSnippet example="45_add_table_check_constraint.yaml" languange="yaml" />
105105

106+
### Add a `PRIMARY KEY` constraint
107+
108+
Add a primary key constraint to the the `tasks` table:
109+
110+
<ExampleSnippet
111+
example="55_add_primary_key_constraint_to_table.yaml"
112+
languange="yaml"
113+
/>
114+
106115
### Add a `FOREIGN KEY` constraint
107116

108117
Add a multi-column foreign key constraint to the the `tickets` table. The `up` SQL expressions here don't do any data transformation:

examples/.ledger

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@
5252
52_create_table_with_exclusion_constraint.yaml
5353
53_add_column_with_volatile_default.yaml
5454
54_create_index_with_opclass.yaml
55+
55_add_primary_key_constraint_to_table.yaml
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
operations:
2+
- create_table:
3+
name: tasks
4+
columns:
5+
- name: id
6+
type: serial
7+
- name: title
8+
type: varchar(255)
9+
nullable: false
10+
- name: description
11+
type: varchar(255)
12+
- name: deadline
13+
type: time with time zone
14+
- create_constraint:
15+
name: tasks_pkey
16+
table: tasks
17+
columns: [id]
18+
type: primary_key
19+
up:
20+
id: id
21+
down:
22+
id: id

0 commit comments

Comments
 (0)