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

sql2pgroll: Ignore IF NOT EXISTS in CREATE TABLE statement conversion #754

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

andrew-farries
Copy link
Collaborator

@andrew-farries andrew-farries commented Mar 26, 2025

Convert CREATE TABLE IF NOT EXISTS statements to create_table operations as though the IF NOT EXISTS clause was not present.

A CREATE TABLE statement like this:

CREATE TABLE IF NOT EXISTS "dogs" (
        "id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "dogs_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
        "name" varchar(255) NOT NULL,
        "age" integer NOT NULL
);

is now converted to:

{
  "operations": [
    {
      "create_table": {
        "columns": [
          {
            "generated": {
              "identity": {
                "sequence_options": "SEQUENCE NAME dogs_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 ",
                "user_specified_values": "ALWAYS"
              }
            },
            "name": "id",
            "pk": true,
            "type": "int"
          },
          {
            "name": "name",
            "type": "varchar(255)"
          },
          {
            "name": "age",
            "type": "int"
          }
        ],
        "name": "dogs"
      }
    }
  ]
}

rather than a raw SQL migration.

See the discussion on #719 for the rationale behind this change.

Convert `CREATE TABLE IF NOT EXISTS` statements to `create_table`
operations as though the `IF NOT EXISTS` clause was not present.

See the discussion:

#719

For the rationale behind this change.
@github-actions github-actions bot temporarily deployed to Docs Preview March 26, 2025 15:55 Inactive
@andrew-farries andrew-farries marked this pull request as ready for review March 26, 2025 16:00
@andrew-farries andrew-farries requested a review from kvch March 26, 2025 16:00
@andrew-farries andrew-farries merged commit 47a7a71 into main Mar 26, 2025
30 checks passed
@andrew-farries andrew-farries deleted the convert-create-table-if-not-exists branch March 26, 2025 16:55
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