diff --git a/.gitignore b/.gitignore index 355e1f5..c061dd8 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ go.work.sum # Custom /_output +/deployment/db_data diff --git a/README.md b/README.md index b789af1..95f0647 100644 --- a/README.md +++ b/README.md @@ -195,3 +195,5 @@ type User struct { ID int } ``` + +Use Buffalo pop `Soda CLI` to create database migrations. diff --git a/database.yml b/database.yml new file mode 100644 index 0000000..75a8552 --- /dev/null +++ b/database.yml @@ -0,0 +1,7 @@ +development: + dialect: postgres + database: howmuch + user: postgres + password: example + host: 127.0.0.1 + pool: 5 diff --git a/deployment/docker-compose.yml b/deployment/docker-compose.yml new file mode 100644 index 0000000..2e01dbb --- /dev/null +++ b/deployment/docker-compose.yml @@ -0,0 +1,22 @@ +services: + + postgres: + image: postgres + restart: always + ports: + - "5432:5432" + deploy: + mode: replicated + replicas: 1 + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: example + POSTGRES_DB: howmuch + volumes: + - ./db_data/postgres/:/var/lib/postgresql/data + + adminer: + image: adminer + restart: always + ports: + - 8080:8080 diff --git a/migrations/20241004191351_create_user_table.postgres.down.sql b/migrations/20241004191351_create_user_table.postgres.down.sql new file mode 100644 index 0000000..6a03647 --- /dev/null +++ b/migrations/20241004191351_create_user_table.postgres.down.sql @@ -0,0 +1,3 @@ +DROP TABLE IF EXISTS "user"; +DROP SEQUENCE IF EXISTS user_id_seq; + diff --git a/migrations/20241004191351_create_user_table.postgres.up.sql b/migrations/20241004191351_create_user_table.postgres.up.sql new file mode 100644 index 0000000..2e36e25 --- /dev/null +++ b/migrations/20241004191351_create_user_table.postgres.up.sql @@ -0,0 +1,14 @@ +CREATE SEQUENCE user_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1; + +CREATE TABLE "public"."user" ( + "id" integer DEFAULT nextval('user_id_seq') NOT NULL, + "email" character varying(255) NOT NULL UNIQUE, + "first_name" character varying(255) NOT NULL, + "last_name" character varying(255) NOT NULL, + "password" character varying(60) NOT NULL, + "created_at" timestamp NOT NULL, + "updated_at" timestamp NOT NULL, + CONSTRAINT "user_pkey" PRIMARY KEY ("id") +) WITH (oids = false); + +