I have been looking for a way to apply and manage my model changes to my 
db schema. This came out of a brainstorm yesterday afternoon. Just 
wanted to pass the idea through the community to see where it fits, if 
anywhere, upstream.

The general idea is to save sqlall output from manage.py. You then 
maintain sql files named after your apps and their versions.  Then just 
run the script against two of your files with the sqlall content in it. 
It takes the diff of two files and generates sql statements that will 
upgrade your schema from one version to another.

I went back and captured sqlall from a couple previous releases and used 
them to write the code. The proof-of-concept can modify columns, create 
and drop tables and add contraints and indexes. All in mysql at the 
moment. Haven't investigated supporting other databases yet.

I realize that other tools can do this too. I just wanted something 
small that only generated syntax. Is there anything I've missed that 
already does this and is more mature? Does anyone else like the idea of 
this style of schema management?

General example of use:
$ ./manage.py syncdb # initial install
$ ./manage.py sqlall appname > schemas/appname-1.1.0.sql
###  make modifications to model ###
$ ./manage.py sqlall appname > schemas/appname-1.2.0.sql
$ cd schemas
$ ./gen-db-update-script.py appname-1.1.0.sql appname-1.2.0.sql > 
update-appname-1.1.0to1.2.0.sql
$ cat update-appname-1.1.0to1.2.0.sql
CREATE TABLE `appname_tableone` (
     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
     `group_id` integer NOT NULL,
     `content_type_id` integer NOT NULL,
     `object_id` integer UNSIGNED NOT NULL,
)
;
ALTER TABLE `appname_tabletwo` ADD COLUMN `prune_count` integer NOT NUL;
ALTER TABLE `appname_tabletwo` ADD COLUMN `prune_age` integer NOT NULL;
ALTER TABLE `appname_tabletwo` ADD COLUMN `prune_inactive` integer NOT NULL;
ALTER TABLE `appname_tablethree` MODIFY COLUMN `arch_id` integer NOT NULL;
$ mysql -u someuser -p databasename < update-appname-1.1.0to1.2.0.sql

Radez

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to