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

Allow for testing migration down functions #1584

Open
moore3071 opened this Issue Mar 3, 2018 · 1 comment

Comments

Projects
None yet
1 participant
@moore3071

moore3071 commented Mar 3, 2018

It's currently very easy to run into a poorly written migration where the down function doesn't correctly undo the migration. Diesel's documentation suggests the use of redo for testing this, but unless a project is testing this via CI, it's likely that faulty down functions will only be noticed when they're run. Even worse, it may be difficult to track down which migration was faulty. It would be cool if Diesel could include a command that starts with two blank databases, runs through the migrations step by step while redoing the migrations on the first database and checking that it is equivalent to the second database. A naive bit of pseudocode:

let db1 = get("database1")
let db2 = get("database2")
for x in migrations:
        db1.run_migration(x)
        db2.run_migration(x)
        db1.redo(x)
        assert_eq(db1,db2) # e.g. for Postgres, diff the pg_dump of the two
  • I have already looked over the issue tracker for similar issues.
@moore3071

This comment has been minimized.

moore3071 commented Mar 30, 2018

Instead of using two databases and dumping database info, it would make a lot more sense to use Diesel's ability to print the schema. This only gives table structure, but would be much easier to implement.

An obviously needed feature in a binary implementing this would be the ability to exclude the testing of specified migrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment