8000 New option for columns: `generated` by kvch · Pull Request #605 · xataio/pgroll · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

New option for columns: generated #605

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 8000 account

Merged
merged 15 commits into from
Jan 22, 2025
Merged

Conversation

kvch
Copy link
Contributor
@kvch kvch commented Jan 17, 2025

This PR adds support for generated columns in create_table and add_column operations.

The column definition is extended with the setting named generated.

Define a stored column:

...
"generated": {
  "expression": "upper(name)"
}

Define a generated identity column:

...
"generated": {
  "identity": {
    "user_specified_values": "ALWAYS",
    "sequence_options": "start 5"
}

Identity columns are marked not null by default, so setting nullable is unnecessary.

I changed the existing fruits table to use a generated identity column as a primary key.

{
  "name": "08_create_fruits_table",
  "operations": [
    {
      "create_table": {
        "name": "fruits",
        "columns": [
          {
            "name": "id",
            "type": "bigint",
            "pk": true,
            "generated": {
              "identity": {
                "user_specified_values": "BY DEFAULT"
              }
            }
          },
          {
            "name": "name",
            "type": "varchar(255)",
            "unique": true
          },
          {
            "name": "price",
            "type": "decimal(10,2)"
          }
        ]
      }
    }
  ]
}

The PR also contains the transformation required by sql2pgroll project.

Requires xataio/pg_query_go#7

@kvch kvch marked this pull request as ready for review January 17, 2025 15:28
@kvch kvch requested a review from andrew-farries January 17, 2025 15:29
kvch and others added 5 commits January 20, 2025 11:30
Co-authored-by: Andrew Farries <andyrb@gmail.com>
…ataio#603)

Remove the ability to rename columns with `alter_column` operations.

xataio#602 added the `rename_column` operation as the preferred way to rename
columns:

```json
{
  "name": "13_rename_column",
  "operations": [
    {
      "rename_column": {
        "table": "employees",
        "from": "role",
        "to": "job_title"
      }
    }
  ]
}
```

As of this PR, `rename_column` operations are the only way to rename
columns, with the ability to do so using `alter_column` operations
removed.

This is a breaking change to the `pgroll` migrations format.

This is the second (and final) part of xataio#601 

Closes xataio#601
@kvch kvch marked this pull request as draft January 20, 2025 10:44
@kvch
Copy link
Contributor Author
kvch commented Jan 20, 2025

Converting into draft until required changes are merged in https://github.com/xataio/pg_query_go.

@kvch
Copy link
Contributor Author
kvch commented Jan 22, 2025

pg_query_go PR: xataio/pg_query_go#7

@kvch kvch marked this pull request as ready for review January 22, 2025 13:42
@kvch kvch requested a review from andrew-farries January 22, 2025 13:42
@kvch kvch merged commit de56b35 into xataio:main Jan 22, 2025
27 checks passed
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
0