Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions atlas.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ env "local" {
dev = "docker://postgres/17/dev"
src = "file://schema.sql"
url = "postgres://user:password@localhost:5434/migration_db?sslmode=disable"
schemas = ["public"]

migration {
dir = "file://migrations"
revisions_schema = "public"
}
format {
migrate {
Expand All @@ -17,9 +19,11 @@ env "ci" {
dev = "docker://postgres/17/dev"
src = "file://schema.sql"
url = "postgres://user:password@localhost:5435/migration_db?sslmode=disable"
schemas = ["public"]

migration {
dir = "file://migrations"
revisions_schema = "public"
}
format {
migrate {
Expand All @@ -29,8 +33,17 @@ env "ci" {
}

env "production" {
dev = "docker://postgres/17/dev"
src = "file://schema.sql"
url = getenv("DATABASE_URL")
schemas = ["public"]
migration {
dir = "file://migrations"
revisions_schema = "public"
}
format {
migrate {
diff = "{{ sql . \" \" }}"
}
}
}
11 changes: 11 additions & 0 deletions migrations/20251022061054_add_posts_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Create "posts" table
CREATE TABLE "public"."posts" (
"id" serial NOT NULL,
"title" text NOT NULL,
"content" text NULL,
"user_id" integer NULL,
"created_at" timestamp NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY ("id"),
CONSTRAINT "posts_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION
);
5 changes: 3 additions & 2 deletions migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
h1:P2HsavWs6nVx7zdLY57utEn3ZMvc4v8C05SXfWIzHrY=
20251021101913.sql h1:vvxc7ox7cRoCCQSuBWTgLxGJQqiIFmPnTmVKURdL25Y=
h1:CWrrZREY7FuOmiet8ZWS2HwcK3hniW2zG5RuJe9NGxg=
20251022055312_initial_schema.sql h1:s/NyxFMd8WpSscK5YUiW9zIb1M+Jyso+tL5+DUNPofQ=
20251022061054_add_posts_table.sql h1:Okb+6BHSA1IKoxXC/Q6r8UkY7gHJ2ViK9KN7wGWb71g=
9 changes: 9 additions & 0 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ CREATE TABLE users (
address text,
sports text
);

CREATE TABLE posts (
id serial PRIMARY KEY,
title text NOT NULL,
content text,
user_id integer REFERENCES users (id),
created_at timestamp DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp DEFAULT CURRENT_TIMESTAMP
);