diff --git a/atlas.hcl b/atlas.hcl index 441fffd..23d623e 100644 --- a/atlas.hcl +++ b/atlas.hcl @@ -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 { @@ -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 { @@ -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 . \" \" }}" + } } } \ No newline at end of file diff --git a/migrations/20251021101913.sql b/migrations/20251022055312_initial_schema.sql similarity index 100% rename from migrations/20251021101913.sql rename to migrations/20251022055312_initial_schema.sql diff --git a/migrations/20251022061054_add_posts_table.sql b/migrations/20251022061054_add_posts_table.sql new file mode 100644 index 0000000..2521371 --- /dev/null +++ b/migrations/20251022061054_add_posts_table.sql @@ -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 +); diff --git a/migrations/atlas.sum b/migrations/atlas.sum index 7fd60a5..948ecae 100644 --- a/migrations/atlas.sum +++ b/migrations/atlas.sum @@ -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= diff --git a/schema.sql b/schema.sql index 96d3286..51eef1e 100644 --- a/schema.sql +++ b/schema.sql @@ -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 +);