Skip to content

Commit

Permalink
Test adding a test_field for versioned migration changes
Browse files Browse the repository at this point in the history
  • Loading branch information
james03160927 committed May 28, 2024
1 parent e426869 commit 931346d
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 49 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/db-migration-presubmit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Database schema migration check
on:
# Run whenever code is changed in the main branch,
push:
branches:
- main
# Run on PRs where something changed under the `ent/migrate/migrations/` directory.
pull_request:
paths:
- 'ent/**'
jobs:
migration-check:
services:
# Spin up a postgres:10 container to be used as the dev-database for analysis.
postgres:
image: postgres:10
env:
POSTGRES_DB: test
POSTGRES_PASSWORD: pass
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0 # Mandatory unless "latest" is set below.

# doesn't seem to work - does not recognize migrations files.
# - uses: ariga/[email protected]
# with:
# dir: ent/migrate/migrations
# dir-format: golang-migrate # Or: atlas, goose, dbmate
# dev-url: postgres://postgres:pass@localhost:5432/test?sslmode=disable

- name: Check for migration changes
id: check_migrations
run: |
# List files changed in the PR
echo "Checking for changes between ${{ github.event.pull_request.base.sha }} and ${{ github.sha }}"
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
echo "Changed files: $changed_files"
# Check for changes in 'ent/schema'
schema_changes=$(echo "$changed_files" | grep '^ent/schema' || true)
echo "Schema changes: $schema_changes"
# Check for changes in 'ent/migrate/migrations'
migration_changes=$(echo "$changed_files" | grep '^ent/migrate/migrations' || true)
echo "Migration changes: $migration_changes"
# If there are schema changes but no migration changes, fail the check
if [ -n "$schema_changes" ] && [ -z "$migration_changes" ]; then
echo "::error::Changes in 'ent/schema' require corresponding changes in 'ent/migrate/migrations'"
exit 1
else
echo "Check passed: Schema changes are accompanied by migration changes."
fi
2 changes: 1 addition & 1 deletion .github/workflows/logging-presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: semgrep
name: Logging check
on:
push:
branches:
Expand Down
37 changes: 0 additions & 37 deletions .github/workflows/migration-ci.yaml

This file was deleted.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ Or manually run:

`go run -mod=mod entgo.io/ent/cmd/ent generate --feature sql/upsert --feature sql/lock ./ent/schema`

### Generate Migration Files

Run this command to generate migration files needed for staging/prod database schema changes:

```shell
atlas migrate diff migration \
--dir "file://ent/migrate/migrations" \
--to "ent://ent/schema" \
--dev-url "docker://postgres/15/test?search_path=public"
```

## API Spec Change (openapi.yml)

### Regenerate code
Expand Down
2 changes: 2 additions & 0 deletions ent/migrate/migrations/20240528220411_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Modify "nodes" table
ALTER TABLE "nodes" ADD COLUMN "test_field" text NOT NULL;
3 changes: 2 additions & 1 deletion ent/migrate/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
h1:N8EzSLepKv1NCdsdGortcG5sDpeTVBxeIo5ANvXdktU=
h1:qDiQeVaeKVjOjw5Yv9X/s3l4bU33dQ3QstZ/g8MJky0=
20240526144817_migration.sql h1:sP6keX+oMyLL2qpIFx0Ns0WYfWM5hJ4zkFPmLWT68fM=
20240528220411_migration.sql h1:MWbTfx95zDNhc3BL0B4bSC959NKyxzLYGHxreKO9D2M=
3 changes: 2 additions & 1 deletion ent/migrate/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 71 additions & 1 deletion ent/mutation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion ent/node.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions ent/node/node.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 931346d

Please sign in to comment.