1

Closed

Schema Comparer for Database Objects

description

I have a need to compare a saved schema with a newly read (refreshed) schema from the same database. The comparer you have now is great, but I don't need a migration script, I need to update/remove/change objects (classes) in the saved schema based on any updates/removals/changes in the newly read schema.

I hope I'm explaining this correctly. I don't want to generate a script. I physically want to update objects in the saved schema with objects in the new schema.

Is there an easy way to do this. I looked at the code and may be able to do something with it, but I'm hoping you have a simpler solution.
Closed Aug 3, 2013 at 5:01 PM by Martinjw
Included in latest release

comments

Martinjw wrote Jul 26, 2013 at 1:31 PM

It might be more useful if the CompareSchemas returned a list of results rather than a script as a string.
Result objects are easier to display and manipulate.

To use them, you'll have to loop through and for each operation find the relevant table/column etc and apply the change (add, delete, change).

Quick idea for an API:
CompareSchemas.ExecuteResult(): IEnumerable<CompareResult>

CompareResult properties:
ObjectType: Enum of Table, View, Column, Constraint ...)
ObjectName: string (Name of database object= table name, etc)
TableName: string (for columns, constraints, triggers, we'll need table as well as Name)
ResultType: Enum of Add, Delete, Change
Script: string (the generated migration script for this operation)

Is this what you're looking for?

randerson1001 wrote Jul 26, 2013 at 2:33 PM

Yes, this is exactly what I'm looking for. I'm currently reading a database schema and saving the schema with a code generation project. I need the ability to update the saved schema with any changes in the new database schema. The script comes in extremely handy too, but the object comparison would help a lot.

I see the ExecuteResult returning an actionable set of Add/Delete/Change options that could be executed either with a single "Update/Fix" command or individually manipulated manually (via a treeview or listview control) based on user input (an option checkbox for do this update, but don't do this one, etc.).

Martinjw wrote Jul 28, 2013 at 5:36 PM

Initial commit 27953
It returns an IList<CompareResult> which gives maximum flexibility to delete items and even add them.
Loop through the list to build up a full script, or execute the Script property on each item.