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

Add a 'set comment' sub-operation to 'alter column' #344

Merged
merged 6 commits into from
Apr 29, 2024

Conversation

andrew-farries
Copy link
Collaborator

@andrew-farries andrew-farries commented Apr 22, 2024

Allow 'alter column' operations to set the comment on a column:

{
  "name": "02_change_comment",
  "operations": [
    {
      "alter_column": {
        "table": "events",
        "column": "name",
        "comment": "The full name of the event"
      }
    }
  ]
}

This is a versioned migration so the column to which the comment is applied is duplicated and backfilled according to the up and down SQL supplied with the 'alter column' operation. up and down default to a simple copy of the field between new and old columns.

The intention is that this can be combined with a 'change type' sub-operation if there is some column metadata that should be updated as part of the type change:

{
  "name": "35_alter_column_multiple",
  "operations": [
    {
      "alter_column": {
        "table": "events",
        "column": "name",
        "name": "event_name",
        "type": "text",
        "comment": "{type: some-metadata}",
        "up": "name",
        "down": "name"
      }
    }
  ]
}

Fixes #328

@andrew-farries andrew-farries requested review from exekias and removed request for exekias April 22, 2024 14:27
@andrew-farries andrew-farries marked this pull request as draft April 23, 2024 08:05
@andrew-farries andrew-farries force-pushed the add-alter-column-comment-sub-op branch from f7406cd to 8f800e2 Compare April 23, 2024 08:46
@andrew-farries andrew-farries changed the base branch from main to allow-setting-comment-to-null April 23, 2024 08:46
@andrew-farries andrew-farries force-pushed the add-alter-column-comment-sub-op branch from 8f800e2 to 2780150 Compare April 24, 2024 10:10
@andrew-farries andrew-farries changed the base branch from allow-setting-comment-to-null to add-alter-column-default-sub-op April 24, 2024 10:10
@andrew-farries andrew-farries force-pushed the add-alter-column-comment-sub-op branch 2 times, most recently from cf7bf3c to 722b92f Compare April 24, 2024 10:30
@andrew-farries andrew-farries marked this pull request as ready for review April 24, 2024 10:33
Base automatically changed from add-alter-column-default-sub-op to main April 25, 2024 10:47
@andrew-farries andrew-farries force-pushed the add-alter-column-comment-sub-op branch from 722b92f to 0a02c05 Compare April 25, 2024 10:48
@andrew-farries andrew-farries merged commit 4fbfdf7 into main Apr 29, 2024
44 checks passed
@andrew-farries andrew-farries deleted the add-alter-column-comment-sub-op branch April 29, 2024 09:40
andrew-farries added a commit that referenced this pull request Apr 29, 2024
Build on #344 to allow removing column comments by setting them to
`null`.

Make use of omissis/go-jsonschema#220 and use
the [nullable](https://github.com/oapi-codegen/nullable) package so that
it's possible to distingush between a missing `comment` field and one
that is explicitly set to `null`.

With omissis/go-jsonschema#220 not being part of
a release yet, use a custom build of `go-jsonschema`. It should be
possible to switch back to the official release images once
omissis/go-jsonschema#220 is part of a release.

Without this change it becomes impossible to remove a comment from a
column using the 'set comment' 'alter column' sub-operation
(#344).
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.

Support changing a column comment
2 participants