Skip to content

Make name field in migration JSON optional #744

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 4 commits into from
Mar 26, 2025

Conversation

andrew-farries
Copy link
Collaborator

Make the name field in a migration JSON file optional.

If a name is not provided, the migration filename (minus the .json suffix) is used as the migration name.

{
  "name": "02_create_another_table",    <-- no longer required
  "operations": [
    {
      "create_table": {
        "name": "products",
        "columns": [
          {
            "name": "id",
            "type": "serial",
            "pk": true
          },
          {
            "name": "name",
            "type": "varchar(255)",
            "unique": true
          },
          {
            "name": "price",
            "type": "decimal(10,2)"
          }
        ]
      }
    }
  ]
}

The --name flag to pgroll convert is also changed to default to empty (rather than the current timestamp) as part of this change.

Closes #715

@github-actions github-actions bot temporarily deployed to Docs Preview March 24, 2025 17:01 Inactive
If the migration JSON does not specify a `name` field, the migration
name will be set to the base filename without the extension.
Ensure that using a migration file without the `name` field will use the
filename as the migration name.
It's ok to generate migrations without names now.
@andrew-farries andrew-farries force-pushed the make-migration-name-optional branch from 557c6d5 to 11f02d2 Compare March 24, 2025 17:05
@github-actions github-actions bot temporarily deployed to Docs Preview March 24, 2025 17:05 Inactive
@andrew-farries andrew-farries marked this pull request as ready for review March 24, 2025 17:11
@andrew-farries andrew-farries requested a review from kvch March 24, 2025 17:11
@andrew-farries andrew-farries merged commit 81daff6 into main Mar 26, 2025
30 checks passed
@andrew-farries andrew-farries deleted the make-migration-name-optional branch March 26, 2025 08:38
andrew-farries added a commit that referenced this pull request May 21, 2025
Remove support for specifying a `name` field in migration files:

```yaml
name: 01_some_migration # <-- no longer supported
operations:
  - create_table:
      name: products
      columns:
        - name: id
          type: serial
          pk: true
        - name: name
          type: varchar(255)
```

The migration filename is the source of truth for the migration name.
The `name` field was made optional and its use discouraged in the
documentation in #744. This PR removes support for it entirely.

⚠️ **Warning**

**This is a breaking change:** migration files that set the `name` field
will not be runnable by `pgroll` until the `name` field is removed.

Because of #812 `pgroll pull` and
`pgroll migrate` will still work with migration histories that contain
migrations with `name` fields.

The easiest way to remove the `name` fields from all migrations in the
history is to `pgroll pull` the migration history; this will serialize
all migrations in the remote history, removing the any `name` fields.

---

Closes #715 and #850
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.

Remove migration name from inside the JSON and rely on filename as source of truth.
2 participants