1 |
Benjamin Blazke wrote: |
2 |
> Hi, |
3 |
> |
4 |
> I'm looking for a tool that given an existing (base) |
5 |
> database schema and an 'update patch' DDL .sql script |
6 |
> on input would produce a 'reverse' script that could |
7 |
> be used to undo the changes done by the patch. For |
8 |
> example: |
9 |
> |
10 |
> base.sql: |
11 |
> CREATE TABLE xxx (...); |
12 |
> |
13 |
> patch.sql: |
14 |
> CREATE TABLE yyy (...); |
15 |
> ALTER TABLE xxx ADD COLUMN aaa ...; |
16 |
> ALTER TABLE xxx CHANGE column bbb ... |
17 |
> |
18 |
> reverse.sql: |
19 |
> DROP TABLE yyy; |
20 |
> ALTER TABLE xxx DROP column aaa; |
21 |
> ALTER TABLE xxx CHANGE column bbb <get this from the |
22 |
> original base schema> |
23 |
> |
24 |
> The purpose of this exercise is to have a production |
25 |
> database (MySQL) server that needs to update its |
26 |
> schema once in a while to reflect the changes in the |
27 |
> related application without the need to recreate the |
28 |
> schema from scratch (and possibly losing data). The |
29 |
> reverse.sql script could be later used to rollback the |
30 |
> schema changes at any time, even rollback multiple |
31 |
> patches. |
32 |
> |
33 |
> How do people generally solve this? I'm sure this must |
34 |
> be a fairly common problem. |
35 |
|
36 |
The tool you're looking for is called a DBA. :-) |
37 |
|
38 |
On a more serious note: |
39 |
I normally do the schema changes and table updates followed by updating |
40 |
the code on the servers. Once the code is live we're pretty much stuck |
41 |
with it because it often relies on the new fields or uses the new data |
42 |
we populated. I could revert back to the original data, but we'd lose |
43 |
any new data that came in after the upgrade. |
44 |
|
45 |
If your changes were minor it wouldn't be too hard to manually reverse. |
46 |
On the other hand anything very complicated to reverse where you'd want |
47 |
a tool to do it is likely going to fall into my situation where the new |
48 |
data isn't going to work in the old tables, the old application isn't |
49 |
going to like the new data or tables, and so on. |
50 |
|
51 |
We get around it by doing lots and lots of testing. I probably run |
52 |
through the schema and data updates five or so times depending on the |
53 |
complexity on the changes along with continual QA as the new application |
54 |
is being built in the staging environment. |
55 |
|
56 |
kashani |
57 |
-- |
58 |
gentoo-user@g.o mailing list |