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 support for creating tables and columns with comments #224

Merged
merged 5 commits into from
Jan 10, 2024

Conversation

andrew-farries
Copy link
Collaborator

Update the create table and add column operations so that they support adding Postgres comments:

  • create table: comments can be added to the table itself and to each of its columns.
  • add column: a comment can be added to the column.

A create table migration that includes a comment on the table itself and on one of its columns looks like this:

{
  "name": "12_create_employees_table",
  "operations": [
    {
      "create_table": {
        "name": "employees",
        "comment": "This is a comment for the employees table",
        "columns": [
          {
            "name": "id",
            "type": "serial",
            "pk": true
          },
          {
            "name": "role",
            "type": "varchar(255)",
            "comment": "This is a comment for the role column"
          }
        ]
      }
    }
  ]
}

and an add column migration that includes a comment looks like this:

{
  "name": "30_add_column_simple_up",
  "operations": [
    {
      "add_column": {
        "table": "people",
        "up": "'temporary-description'",
        "column": {
          "name": "description",
          "type": "varchar(255)",
          "nullable": false,
          "comment": "This is a comment for the description column"
        }
      }
    }
  ]
}

This allows new tables and columns to be created with comments.

Deletion and modification of comments should still be performed with a raw SQL migration. Until we see a use case that requires versioned modification/removal of comments, these operations are best performed directly on the base table with raw SQL.

Add `Comment` fields to the `Column` and `OpCreateTable` types.
Cover the cases:
* a column with a comment is added via a create table migration
* a column with a comment is added via an add column migration.
* A new table is added with a comment on the table itself.
Add the `comment` field to the documentation.
@andrew-farries andrew-farries merged commit 61cc53a into main Jan 10, 2024
24 checks passed
@andrew-farries andrew-farries deleted the comments-on-columns branch January 10, 2024 15:58
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