question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: idempotent schema migrations

See original GitHub issue

Hi folks, I love this library, and I’m trying to get it running in a project that uses Flyway for schema migrations.

I’ve managed to get it to work by migrating the DB to procrastinate, and then using Flyway to baseline and then migrate the schema over the top of it.

However, for the app, the Flyway migrations run every time the app starts, to ensure that the DB is always aligned to the app’s code. To force Procrastinate to work in the say way, I’m running procrastinate --app=tutorial.app schema --apply 2>&1 || true in my startup command to force success, even when it errors with:

Applying schema
Error: 
    Database error.
type "procrastinate_job_status" already exists

Ideally I’d love procrastinate schema --apply (or a different command) to succeed if the procrastinate tables already exist as-expected in the Postgres schema, and migrate them if not. Is that possible?

Thanks again!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dvasdekiscommented, Oct 11, 2022

Thanks for letting me know. I got it all working by integrating this file with my user-defined Flyway migrations, and running it as one process. Cheers!

1reaction
ewjoachimcommented, Sep 24, 2022

In a word, yes.

schema.sql describes the final schema. The migration files describe, version by version, how to go from the schema of the previous version to the schema of the current version. They won’t give you the exact schema because the migrations also need to handle details like backwards compat, but it’s mostly the same.

https://procrastinate.readthedocs.io/en/stable/howto/migrations.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating Idempotent DDL Scripts for Database Migrations
I'll demonstrate how to achieve this, using either the information schema views or system functions to check the required conditions, and then ...
Read more >
migrate/idempotent-examples.md at main - GitHub
Idempotency is an important concept in Graphile Migrate, if a migration is idempotent it means that you can run the migration multiple times...
Read more >
Understanding why and how to add idempotent requests to ...
Understanding why and how to add idempotent requests to your APIs ... It requires no additional models, schemas or migrations.
Read more >
Database Migration — Writing Scripts & Best Practices - Medium
Migrations are the version control for your database, allowing your team to easily modify and share the application's database schema. Basically, you affect...
Read more >
Applying Migrations - EF Core - Microsoft Learn
Idempotent SQL scripts. The SQL scripts generated above can only be applied to change your schema from one migration to another; it is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found