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

Option to execute the migration using an SQL file #184

Open
althaf004 opened this issue Oct 11, 2023 · 5 comments
Open

Option to execute the migration using an SQL file #184

althaf004 opened this issue Oct 11, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@althaf004
Copy link

Hello,

I really appreciate how well pgroll works with JSON files. It would be even more convenient if there was an option to specify an SQL file for migration.

For instance, it would be great if you could use the following command:

./pgroll --postgres-url "postgres://{user}:{password}@{IP}:{port}/{DB}" start 01_create_table.sql --label create_table_11102023 --schema stateless_user_info

This way, you could create a schema named 'stateless_user_info_create_table_11102023' while keeping everything else the same.

Best regards,
Althaf

@althaf004 althaf004 changed the title Option to run the migration from sql file Option to execute the migration using an SQL file Oct 11, 2023
@exekias
Copy link
Member

exekias commented Oct 11, 2023

++ It would be nice to have a conversion layer that is able to reads raw SQL migrations and outputs the same thing expressed as pgroll operations.

btw what we have as of today is a way to execute any SQL migration, it's just we don't guarantee zero downtime for those: https://github.com/xataio/pgroll/tree/main/docs#raw-sql

@exekias exekias added the enhancement New feature or request label Oct 11, 2023
@mobinni
Copy link

mobinni commented Oct 20, 2023

In a scenario where you want to switch migration suites the raw SQL option although nice doesn't allow to have an initializer migration to run an idempotent schema migration.

Is there a way to do something along the lines of:

{
  "sql": {
    "script": "<file.sql>"
  }
}

@exekias
Copy link
Member

exekias commented Oct 23, 2023

We have a raw SQL operation that allows you to run any arbitrary SQL for the migration: https://github.com/xataio/pgroll/tree/main/docs#raw-sql. It requires inlining the SQL statements, but otherwise, it looks pretty similar to what you are describing 🙂

@EmadMokhtar
Copy link

I've a crazy idea. What about creating an LLM prompt to translate the SQL statement into the JSON file format? If you like the idea, I can give it a try.

@exekias
Copy link
Member

exekias commented Apr 22, 2024

@EmadMokhtar That's an interesting idea! We recently discussed the possibility of doing something like this. If we are able to convert any arbitrary SQL DDL to pgroll format it would be a step forward. In some cases, it's possible that the user still needs to provide some extra info (like the up/down functions), but overall it would make for a better story.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants