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.

Generate a rollback preview script

See original GitHub issue

To generate full migration script, I can use the following:

dotnet fm migrate -p SqlServer2016 --no-connection -a Migrations.dll --preview -o="mgr.sql"

and it works fine.

But when I attempt to generate a rollback script the same way:

dotnet fm rollback all -p SqlServer2016 --no-connection -a Migrations.dll --preview -o="mgr.sql"

it spits out an error Unrecognized option '-p'

So, I looked at some examples and found out that I need to move the parameters to the back of the command line (somewhat unintuitive; I expected migrate down and rollback to be written together).

So tried with all to the end:

dotnet fm rollback -p SqlServer2016 --no-connection -a Migrations.dll --preview -o="mgr.sql" all

This time no error, but the generated script only drops VersionInfo table and doesn’t include Down from my migrations. Tried also by 5 and to 499 at the end - the same results. Tried also migrate ... down -t 499 and still got empty mgr.sql file.

Ideally, I would like to be able to generate a rollback script for all migrations that belong to specific version. In my project conventions (enforced with custom migration attribute) it means all migrations that start with given version number and include three last digits with ascending sequence numbers for individual migrations for the specific version of my website.

Of course, I would like to also be able to generate migrate SQL script the same way for the latest project version (which includes multiple migrations), but for now I’ve managed to extract the needed portion out of the full script using command line tools (sed, grep etc.)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
progmarscommented, Sep 4, 2019

Thank you for the advice.

For now, we deliver often enough, so, fortunately, our “patch batches” are not very large; usually about 20 - 50 SQL statements in 10-20 migration files in total.

I guess, we are abusing the fourth version field in our migration attribute. While in our CI, it is used more “by the books” - as an incremental build number and is never reset to 0 (so that might easily go past 3 digit limit indeed); however, in migrations we are resetting it to 0 every time when we increase any other version component. During development, every team member announces in our team chat that they are increasing the migration counter to reserve a slot for their migration file, and so it grows till its time to release a stable build for delivery.

I’m looking forward to the release 4.0. So far, experience with FluentMigrator has been great for me - it’s simple, reliable and straight-forward to use. No dependency on model state, SQL generation and custom naming conventions and behaviors were the main reasons why I chose FluentMigrator instead of Entity Framework code-first migrations.

0reactions
jzabroskicommented, Sep 24, 2019

Summary:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Demo: Automatically Create SQL Rollback Scripts - YouTube
How a SQL rollback script can be automatically generated.
Read more >
Visual Studio Database Project Rollback Script
I'm using the Database project in visual studio 2010 to generate a script to deploy my database (and it's changes). This works great....
Read more >
Creating a rollback script - SQL Compare 15
Creating a rollback script · In the main window, right click in the Direction Bar, and click Switch deployment direction. · Use the...
Read more >
Liquibase Rollback Workflow
Liquibase provides commands to allow you to undo changes you have made to your database, either automatically or with a custom rollback command....
Read more >
Rolling back transactions via the ROLLBACK SQL query
In this article, you will see what a transaction is and how it can be rollbacked both manually and automatically. First, let's create...
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