Skip to content

Add VersionSchema field to operation integration tests #886

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

Merged
merged 1 commit into from
Jun 13, 2025

Conversation

andrew-farries
Copy link
Collaborator

@andrew-farries andrew-farries commented Jun 12, 2025

Ensure that at least one test for every operation type sets a VersionSchema for the the migration.

This PR adds a VersionSchema field to one test for every operation type.


This PR is part of a stack:

@github-actions github-actions bot temporarily deployed to Docs Preview June 12, 2025 07:03 Inactive
@andrew-farries andrew-farries marked this pull request as ready for review June 12, 2025 07:23
@andrew-farries andrew-farries requested a review from kvch June 12, 2025 07:24
@andrew-farries
Copy link
Collaborator Author

Coverage job is failing because this is a stacked PR:

fgrosse/go-coverage-report#46

@andrew-farries andrew-farries force-pushed the update-tests-for-version-schema-field branch from 575ac16 to 9f86721 Compare June 13, 2025 07:41
@github-actions github-actions bot temporarily deployed to Docs Preview June 13, 2025 07:41 Inactive
andrew-farries added a commit that referenced this pull request Jun 13, 2025
#852 removed support for specifying a migration name via the `name`
field in a migration file. While having an unambiguous source of truth
for the migration name (the filename) is good, it is still often
desirable to decouple the filename from the name of the version schema
that the migration will create when applied because filenames:

* can be longer than the limit Postgres imposes on schema names
* can contain characters that are not legal in Postgres schema names
* must be named so that migration files are ordered lexicographically on
disk

This PR adds support for a new `version_schema` field in migration files
that allows the migration author to specify the name of the version
schema that the migration will create.

## Example

```yaml
# migration files can now specify the version schema 
# name to be created by the migration
version_schema: my_version_schema
operations:
  - create_table:
      name: items
      columns:
        - name: id
          type: serial
          pk: true
        - name: name
          type: varchar(255)
```

Running this migration:

```
$ pgroll start migrations/01_create_table.yaml --complete
```

Creates this version schema:

```
+-----------------------+-------------------+
| Name                  | Owner             |
|-----------------------+-------------------|
...
| public_my_version_schema | postgres       |
+-----------------------+-------------------+
```

Had the `version_schema` field not been specified in the migration file
the version schema would have been:

```
+-----------------------+-------------------+
| Name                  | Owner             |
|-----------------------+-------------------|
...
| public_01_create_table | postgres         |
+-----------------------+-------------------+
```

---

This PR is part of a stack:
* #884 (this PR)
* #886
* #887

Part of #882
Base automatically changed from add-version-schema-field to main June 13, 2025 08:16
Ensure that at least one test for every operation type sets a
`VersionSchema` for the the migration.
@andrew-farries andrew-farries force-pushed the update-tests-for-version-schema-field branch from 9f86721 to 5cfeff8 Compare June 13, 2025 08:18
@github-actions github-actions bot temporarily deployed to Docs Preview June 13, 2025 08:18 Inactive
Copy link

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/xataio/pgroll/pkg/migrations 74.08% (+0.05%) 👍

Coverage by file

Changed unit test files

  • github.com/xataio/pgroll/pkg/migrations/op_add_column_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_alter_column_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_change_type_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_create_constraint_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_create_index_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_create_table_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_drop_column_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_drop_constraint_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_drop_index_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_drop_multicolumn_constraint_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_drop_not_null_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_drop_table_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_raw_sql_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_rename_column_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_rename_constraint_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_rename_table_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_set_check_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_set_comment_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_set_default_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_set_fk_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_set_notnull_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_set_unique_test.go

@andrew-farries andrew-farries merged commit 050e2ea into main Jun 13, 2025
30 checks passed
@andrew-farries andrew-farries deleted the update-tests-for-version-schema-field branch June 13, 2025 08:28
andrew-farries added a commit that referenced this pull request Jun 13, 2025
Update documentation for the new `versionSchema` field and add an
example migration.

--- 

This PR is part of a stack:
* #884
* #886 
* #887 (this PR)
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.

2 participants