Skip to content

Commit

Permalink
Adding Makefile to deal with migrations and documenting the process.
Browse files Browse the repository at this point in the history
  • Loading branch information
andream16 committed Dec 11, 2024
1 parent 31c3142 commit 9108193
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
24 changes: 24 additions & 0 deletions sdk/Makefile
Original file line number Diff line number Diff line change
@@ -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"
30 changes: 30 additions & 0 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

0 comments on commit 9108193

Please sign in to comment.