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 sql2pgroll package to convert SQL to pgroll migrations #502

Merged
merged 3 commits into from
Dec 3, 2024

Conversation

andrew-farries
Copy link
Collaborator

@andrew-farries andrew-farries commented Dec 3, 2024

Add a sql2pgroll package to convert SQL to pgroll migrations.

Add a (hidden for now) pgroll sql command that uses the package to convert SQL strings on the command line to pgroll migrations.

The sql2pgroll package is incomplete, with almost all SQL falling back to conversion using raw SQL migrations. Only some CREATE TABLE statements and the ALTER TABLE ... ALTER COLUMN ... SET NOT NULL statement are currently handled.

$ pgroll sql "create table foo(a serial primary key, b text unique)" 
[
  {
    "create_table": {
      "columns": [
        {
          "name": "a",
          "pk": true,
          "type": "serial"
        },
        {
          "name": "b",
          "nullable": true,
          "type": "text",
          "unique": true
        }
      ],
      "name": "foo"
    }
  }
]

Part of #504

Add `pg_query_go` dependency to the `go.mod` file.
@andrew-farries andrew-farries marked this pull request as ready for review December 3, 2024 08:31
@andrew-farries
Copy link
Collaborator Author

Issue tracking the work remaining on sql2pgroll: #504

Copy link
Member

@exekias exekias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome feature! looking forward to seing it progressing.

On the command name, I'm unsure about sql but don't have a better proposal, so let's go for it and see how it goes

@andrew-farries andrew-farries merged commit 1f6f49b into main Dec 3, 2024
27 checks passed
@andrew-farries andrew-farries deleted the add-sql2pgroll-package branch December 3, 2024 11:29
@andrew-farries andrew-farries added the sql2pgroll Issues relating to the sql2pgroll package label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sql2pgroll Issues relating to the sql2pgroll package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants