From fc15309c0041ff20aed9e6db7a63315a4b7e7d50 Mon Sep 17 00:00:00 2001 From: andream16 Date: Mon, 9 Dec 2024 14:35:29 +0000 Subject: [PATCH] Adding Makefile to deal with migrations and documenting the process. --- sdk/Makefile | 24 ++++++++++++++++++++++++ sdk/README.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 sdk/Makefile diff --git a/sdk/Makefile b/sdk/Makefile new file mode 100644 index 000000000..af2d90a49 --- /dev/null +++ b/sdk/Makefile @@ -0,0 +1,24 @@ +.PHONY: pull-migrator-image new-migration + +pull-migrator-image: + docker pull --platform linux/amd64 arigaio/atlas:latest-alpine + +new-migration: pull-migrator-image + docker run \ + --platform linux/amd64 \ + -v ./component/store/remote/postgresql/sqlc/migrations:/migrations \ + --rm \ + -it arigaio/atlas:latest-alpine \ + migrate \ + new $(migration_name) \ + --dir "file://migrations" + +update-migrations-sum: pull-migrator-image + docker run \ + --platform linux/amd64 \ + -v ./component/store/remote/postgresql/sqlc/migrations:/migrations \ + --rm \ + -it arigaio/atlas:latest-alpine \ + migrate \ + hash \ + --dir "file://migrations" diff --git a/sdk/README.md b/sdk/README.md index 03e4cfe98..5a073e315 100644 --- a/sdk/README.md +++ b/sdk/README.md @@ -288,3 +288,33 @@ if err := component.RunReporter( log.Fatalf("unexpected run error: %v", err) } ``` + +### Contributing + +#### Database Schemas + +They are generated using [sqlc](https://sqlc.dev/) from real SQL schemas and queries. + +##### Generation + +You can generate types mapping schemas and queries by leveraging the `go:generate` entries in `tools.go`. + +#### Migrations + +Components require a common database/tables setup to function properly. + +This is achieved with migrations. + +##### SQLite + +TBD. + +##### Postgresql + +Postgresql migrations live in `./component/store/remote/postgresql/sqlc/migrations`. + +In order to create a new migration, you can follow these steps: + +* run `$ make new-migration migration_name=my_migration` +* edit the migration +* run `$ update-migrations-sum` to update `atlas.sum`