Skip to content

Commit

Permalink
Add a new database table for subjects
Browse files Browse the repository at this point in the history
We need to store basic information about the infrasture we store results
for. Create a table called `subjects` for this purpose. This partially
addresses #29.
  • Loading branch information
rhmdnd committed May 31, 2022
1 parent bb8c83c commit 3b2d322
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ configs/config.yaml
# Terraform
terraform/.terraform*
terraform/terraform.*

# Ignore the golang-migrate/migrate binary
migrate
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ $ terraform apply

Cleanup the resources using `terraform destroy`.

## Migrations

Please refer to the [migrations documentation](./migrations/README.md) for
instructions on creating and managing database migrations.

## gRPC API

This API is marked as **EXPERIMENTAL** and may change in backwards incompatible
Expand Down
1 change: 1 addition & 0 deletions migrations/000001_create_subject_table.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS subjects;
5 changes: 5 additions & 0 deletions migrations/000001_create_subject_table.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS subjects (
id serial PRIMARY KEY,
name VARCHAR(255),
type VARCHAR(50)
);
31 changes: 28 additions & 3 deletions migrations/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
# Database Migrations

This folder contains database migrations for the compliance service using
[golang-migrate/migrate](https://github.com/golang-migrate/migrate). Please
refer to migrate
[documentation](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate).
[golang-migrate/migrate](https://github.com/golang-migrate/migrate).

This project requires using the `migrate` CLI to change the database schema and
to add new migrations. Please refer to the
[documentation](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate)
for installation instructions.

## Examples

These examples assume you have a PostgreSQL server accessible with a database
named `compliance`, and you've properly
[escaped](https://github.com/golang-migrate/migrate#database-urls) the database
password. You can refer to the deployment documentation in the
[README.md](../README.md) for instructions on using terraform to deploy a
database using AWS RDS.

Apply all migrations:

```console
$ POSTGRESQL_URL="postgres://$USER:$PASSWORD@$DATABASE_ENDPOINT/compliance
$ ./migrate -database $POSTGRESQL_URL -path migrations up
```

Apply all down migrations:

```console
$ ./migrate -database $POSTGRESQL_URL -path migrations down
```

0 comments on commit 3b2d322

Please sign in to comment.