diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c3b9dc2..a881d5a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,10 +5,11 @@ ], "service": "vscode", "runServices": [ - "vscode" + "vscode", + "db" ], "shutdownAction": "stopCompose", - "postCreateCommand": "go mod download && go mod tidy", + // "postCreateCommand": "go mod download && go mod tidy", "workspaceFolder": "/workspace", // "overrideCommand": "", "customizations": { diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 00dad8b..f05b518 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -24,4 +24,22 @@ services: security_opt: # For debugging with dlv - seccomp:unconfined - entrypoint: [ "zsh", "-c", "while sleep 1000; do :; done" ] \ No newline at end of file + entrypoint: [ "zsh", "-c", "while sleep 1000; do :; done" ] + + db: + image: postgres + restart: always + # set shared memory limit when using docker-compose + shm_size: 128mb + # or set shared memory limit when deploy via swarm stack + #volumes: + # - type: tmpfs + # target: /dev/shm + # tmpfs: + # size: 134217728 # 128*2^20 bytes = 128Mb + environment: + - POSTGRES_USER=${POSTGRES_USER:-postgres} + - POSTGRES_PORT=${POSTGRES_PORT:-5432} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres} + - POSTGRES_DB=${POSTGRES_DB:-chronicle} + - POSTGRES_HOST=${POSTGRES_HOST:-db} \ No newline at end of file diff --git a/README.md b/README.md index de3c3b7..8b51b45 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,33 @@ For now setting this up as monorepo of services but might only have one. ## .devcontainer See + +## DB + +### Migration Scripts + + + +Inspect database + +`atlas schema inspect -u "postgres://postgres:postgres@db:5432/chronicle?sslmode=disable"` + +Inspect schema + +`atlas schema inspect -u "postgres://postgres:postgres@db:5432/chronicle?search_path=public&sslmode=disable"` + +``` +atlas schema apply \ + -u "postgres://postgres:postgres@db:5432/chronicle?sslmode=disable" \ + --to file://schema.sql \ + --dev-url "postgres://postgres:postgres@db:5432/chronicle?sslmode=disable" +``` + +Initialize + +``` +atlas migrate diff initial \ + --to file://schema.sql \ + --dev-url "postgres://postgres:postgres@db:5432/chronicle?sslmode=disable" \ + --format '{{ sql . " " }}' +``` diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 0000000..ca5183b --- /dev/null +++ b/go.work.sum @@ -0,0 +1,26 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= +github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/chronicle/adapter/persistence/postgres/sqlc/migrations/20240731025606_initial.sql b/internal/chronicle/adapter/persistence/postgres/sqlc/migrations/20240731025606_initial.sql new file mode 100644 index 0000000..e611aae --- /dev/null +++ b/internal/chronicle/adapter/persistence/postgres/sqlc/migrations/20240731025606_initial.sql @@ -0,0 +1,7 @@ +-- Create "game" table +CREATE TABLE "public"."game" ( + "id" bigserial NOT NULL, + "name" text NOT NULL, + "type" text NOT NULL, + PRIMARY KEY ("id") +); diff --git a/internal/chronicle/adapter/persistence/postgres/sqlc/migrations/atlas.sum b/internal/chronicle/adapter/persistence/postgres/sqlc/migrations/atlas.sum new file mode 100644 index 0000000..04891ef --- /dev/null +++ b/internal/chronicle/adapter/persistence/postgres/sqlc/migrations/atlas.sum @@ -0,0 +1,2 @@ +h1:CEf8zGVDRoCvO8j5wNVaiUdVZPS797qdvMjjBfH0mx8= +20240731025606_initial.sql h1:/w26l6f+1wdv92vWPNgQL7T0nF+ldS2hLbYKhwij0rQ=