Skip to content

Commit 80ad9c4

Browse files
committed
fix(schema): tweak column types
Signed-off-by: Theo Bob Massard <tbobm@protonmail.com>
1 parent 97858a3 commit 80ad9c4

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,53 @@ It supports both local development and cloud deployment with CI/CD workflows.
2727
```console
2828
$ docker compose up -d --wait --quiet-pull db
2929
$ docker compose run -it atlas schema inspect -u "postgres://user:pass@db:5432/local_db?sslmode=disable"
30+
...
31+
$ docker compose run -it atlas schema apply -u "postgres://user:pass@db:5432/local_db?sslmode=disable" --file file://schema/schema.hcl --auto-approve
32+
[+] Creating 1/1
33+
✔ Container bootstrapping-databases-for-local-and-prod-db-1 Running 0.0s
34+
Planning migration statements (2 in total):
35+
36+
-- create "papers" table:
37+
-> CREATE TABLE "public"."papers" (
38+
"id" serial NOT NULL,
39+
"title" character varying(255) NOT NULL,
40+
PRIMARY KEY ("id")
41+
);
42+
-- create "mentions" table:
43+
-> CREATE TABLE "public"."mentions" (
44+
"id" serial NOT NULL,
45+
"paper_id" integer NOT NULL,
46+
"document" text NOT NULL,
47+
PRIMARY KEY ("id"),
48+
CONSTRAINT "mentions_paper_fk" FOREIGN KEY ("paper_id") REFERENCES "public"."papers" ("id") ON DELETE CASCADE
49+
);
50+
51+
-------------------------------------------
52+
53+
Applying approved migration (2 statements in total):
54+
55+
-- create "papers" table
56+
-> CREATE TABLE "public"."papers" (
57+
"id" serial NOT NULL,
58+
"title" character varying(255) NOT NULL,
59+
PRIMARY KEY ("id")
60+
);
61+
-- ok (24.597527ms)
62+
63+
-- create "mentions" table
64+
-> CREATE TABLE "public"."mentions" (
65+
"id" serial NOT NULL,
66+
"paper_id" integer NOT NULL,
67+
"document" text NOT NULL,
68+
PRIMARY KEY ("id"),
69+
CONSTRAINT "mentions_paper_fk" FOREIGN KEY ("paper_id") REFERENCES "public"."papers" ("id") ON DELETE CASCADE
70+
);
71+
-- ok (5.336047ms)
72+
73+
-------------------------
74+
-- 10.896794ms
75+
-- 1 migration
76+
-- 2 sql statements
3077
```
3178

3279
## Production deployment

schema/schema.hcl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
schema "public" {
2-
charset = "UTF8"
3-
collate = "en_US.utf8"
42
}
53

64
table "papers" {
75
schema = schema.public
86
column "id" {
97
type = serial
10-
primary_key = true
118
}
129
column "title" {
1310
type = varchar(255)
1411
null = false
1512
}
13+
primary_key {
14+
columns = [column.id]
15+
}
1616
}
1717

1818
table "mentions" {
1919
schema = schema.public
2020
column "id" {
2121
type = serial
22-
primary_key = true
2322
}
2423
column "paper_id" {
2524
type = int
@@ -29,11 +28,13 @@ table "mentions" {
2928
type = text
3029
null = false
3130
}
31+
primary_key {
32+
columns = [column.id]
33+
}
3234

3335
foreign_key "mentions_paper_fk" {
3436
columns = [column.paper_id]
35-
ref_table = table.papers
36-
ref_columns = [column.id]
37+
ref_columns = [table.papers.column.id]
3738
on_delete = "CASCADE"
3839
}
3940
}

0 commit comments

Comments
 (0)