Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameterize schema in which migration tests run via PGROLL_TEST_SCHEMA env var #276

Merged
merged 3 commits into from
Feb 5, 2024

Conversation

andrew-farries
Copy link
Collaborator

Parameterize the migration tests so that the schema in which migrations are applied is taken from the PGROLL_TEST_SCHEMA environment variable, or public if unset.

#273 highlights an area in which there is a lack of test coverage: migration tests apply migrations only in the public schema. #273 is an error that is only reproducible when running migrations in a non-public schema and there are currently also other problems with migration validation in non-public schema.

This PR makes repetitive changes to all tests:

  • Update the afterStart, afterComplete and afterRollback hooks to take a schema string parameter.
  • Update all hard-coded occurences of "public" in those hooks with the schema parameter.

Later PRs will fix the issues with running migrations in non-public schema and run non-public migration tests in CI. For now, to run migration tests in a non-public schema run:

PGROLL_TEST_SCHEMA=foo go test ./...

Part of #273

No need to specify `TestCase` here.
Default to running tests in the 'public' schema, but allow this to be
overridded via the `PGROLL_TEST_SCHEMA` env var.
@andrew-farries andrew-farries force-pushed the parameterize-schema-in-migration-tests branch from 8f2279f to 9d38e6f Compare February 5, 2024 12:31
@andrew-farries andrew-farries merged commit c95bc78 into main Feb 5, 2024
26 checks passed
@andrew-farries andrew-farries deleted the parameterize-schema-in-migration-tests branch February 5, 2024 12:41
andrew-farries added a commit that referenced this pull request Feb 7, 2024
Remove the schema component from index names in the internal schema
representation.

A `pgroll` migration is always run in the context of a a specific schema
so the extra qualification is redundant.

Removing the schema component from the index names makes it easy to
identify duplicated indexes by name when temporary columns and
associated attributes are renamed on migration completion.

Tests for this change are already in place (#276, #277). As of this PR,
migration tests run in a non-public schema will pass:

```bash
PGROLL_TEST_SCHEMA=foo go test ./...
```

Part of #273
andrew-farries added a commit that referenced this pull request Feb 7, 2024
Add another dimension to the test matrix so that migration tests are run
in both the `public` and a non-`public` schema.

#276 made it possible to run
migration tests in schema other than `public`. Doing so highlighted some
issues that are fixed by #278.

Fixes #273.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants