views:

34

answers:

2

Originally, the model (including tables, views, packages, etc.) was built from the DML scripts (generated by TOAD). The scripts look like:

DROP TABLE TABLESPACE.TABLENAME CASCADE CONSTRAINTS;
CREATE TABLE TABLESPACE.TABLENAME
...

Over time the model has changed - I've added new columns to the tables, altered some vews, added new methods to packages, etc.

What would be the easiest way (software, technique) to create migration scripts from the old model to the state of things I currently have. As a migration script I need to have a set of ALTERs, etc. that can be applied to the legacy model, so that it will be upgraded.

+3  A: 

When you say that you need UPDATE statements, do you mean that you want the data to be kept updated to what you have in your new database? If you want the data to match exactly then you can do that, but if you want the same logic applied to the existing DB to bring it up to the new DB then you will need to have saved off those UPDATE scripts to be able to do that. For example, if you needed to increment the sales_date for all orders in your system because you found a bug in the code somewhere, there is no way to determine that from just looking at a database.

To make one database match another, Red Gate has some good tools - SQL Compare and SQL Data Compare should be able to help you. The data compare tool will only make the data match exactly and isn't very efficient for extremely large tables. It's good for things like look-up tables though.

There are other similar products out there (SQL Examiner comes to mind).

Tom H.
No, the data shouldn't be migrated - only the schema.In other words -- I had a model (A) that I was changing during development (not tracking the changes), and now I need to have scripts that will reproduce all my actions.
Vasil Remeniuk
For example, originally I had a table with 3 columns. During development I've added 2 more nullable columns. I'm looking for a tool that will, for example, compare DMLs of two tables, and build a migration script altering the original table and adding the new 2 columns.
Vasil Remeniuk
SQL Compare should do that for you. It will find all differences between two database models and generate script(s) to synchronize in either direction. You can also filter out objects for syncing or sync some one way and others the other way.
Tom H.
+3  A: 

"Over time the model has changed - I've added new columns to the tables, altered some vews, added new methods to packages, etc.

What would be the easiest way (software, technique) to create migration scripts from the old model to the state of things"

Well, the easiest way of doing this would be to get all the DDL scripts you wrote to apply those changes from source control and run them against whatever database you need to.

I suppose the reason you're asking this question is because you haven't been doing things in that fashion. Tsk tsk.

The next easiest approach is to use the original scripts (I take ityou have those) and build a new schema (not the tablespaces obviously). Then compare your new schema against the modified schema to derive the differences.

If you have the DBA module for TOAD you can use its Schema Diff tool to generate a script which will apply all the necessary changes (if you dont have that requisite licence you can still use the Diff utility but you can't save the script as a file). There are other tools on the market which do this: most of them are either chargeable products in their own right (SQL Compare) or require additional licences (Oracle's free SQL Developer offers this functionality but you need to licence the Change Management Pack in order to use it).

If you have the time, a cheaper option is to generate your own scripts using the data dictionary to identify the changes. But that is a lot of effort.

APC