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

pgroll usage with object relational mappers (ORM) #166

Open
deeprobin opened this issue Oct 3, 2023 · 9 comments
Open

pgroll usage with object relational mappers (ORM) #166

deeprobin opened this issue Oct 3, 2023 · 9 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@deeprobin
Copy link

pgroll looks very interesting to me.
It solves a persistent problem.

I usually use EFCore in the .NET environment as ORM.
Also in the Node environment there are ORMs like typeorm, mikroorm & more.

Is there a good approach here that works well with pgroll?

@endigma
Copy link

endigma commented Oct 3, 2023

+1 for entgo support

@exekias
Copy link
Member

exekias commented Oct 4, 2023

Thank you for opening the first issue from the community! 🌟

We want to look into supporting ORMs to automatically integrate with pgroll, the kind of integration we are looking into is for the ORMs that execute migrations on their own, we could potentially integrate pgroll so that instead of directly executing the migration against Postgres, they would use pgroll for that job.

As of today, things should work by following a few steps, in my mind this is the workflow you would need to leverage pgroll together with an ORM like EFCore & friends, moving the migration execution to pgroll instead of having it managed by the ORM:

  1. Configure your ORM/client to use pgroll version schemas, this is explained in the docs, for some clients this could also be just adding a parameter to the connection string
  2. Define & start a migration with pgroll
  3. Adapt your app to use the new schema
    • Update the schema definitions for your ORM
    • Update the client to use the new version schema created by pgroll start
  4. Deploy your new version of the app using the new schema
  5. Once the deploy is done and there are no older versions running, call pgroll complete so the only schema available is the new one

@exekias exekias added enhancement New feature or request question Further information is requested labels Oct 4, 2023
@ben-pr-p
Copy link

ben-pr-p commented Oct 8, 2023

What do you think about creating a pgroll-rest server, distributed as a Docker container with an OpenAPI API?

You could do HTTP requests to get the current schema name to use, submit migrations, rollback, etc.

Translation the migration object specification to OpenAPI would also make it easy to create translation layers for other languages.

@endigma
Copy link

endigma commented Oct 9, 2023

Another server to run in docker just to migrate my DB? I think having it not be basically in-place replacement for other migration tools would basically kill adoption.

@ben-pr-p
Copy link

ben-pr-p commented Oct 9, 2023

I see the options as:

  1. Go FFI from pgroll to runtime of choice (hard, creates extra unique complications per each new environment)
  2. Expect pgroll binary to be on deployed system and interact via sys call (requires users to customize their own Docker container and install an extra binary)
  3. Interact over the network and deploy another container

Definitely not ideal, but I think 1 and 2 are worse for adoption, most likely.

@endigma
Copy link

endigma commented Oct 10, 2023

Well you don't necessarily have to instrument the pgroll binary itself, it takes schema no? Lots of ORMs have code for generating migrations in SQL, they could likely support similar facilities for generating the pgroll JSON, which could then be run externally.

@exekias
Copy link
Member

exekias commented Nov 30, 2023

Wondering if it will help here, next release will bring an official docker image for pgroll: #209

@ben-pr-p
Copy link

ben-pr-p commented Dec 1, 2023

@exekias how are you imagining the Docker image will help?

I think we either need the Docker image to have a REST/HTTP API, or we need an easy way to install the pgroll binary into images built for deploying Node/Python/Ruby, etc.

@endigma
Copy link

endigma commented Dec 3, 2023

Yeah a docker image doesn't really make pgroll programmable

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

No branches or pull requests

4 participants