Brant Harris wrote: > I now have a working solution to ticket #12. > > I've added some code to management.py that allows one to run: > >>django-admin.py transition <app>
... >>django-admin.py sqlupdate <app> > > > Now, sqlupdate looks at the "app.transition.py" file, and executes the > changes accordingly, spitting out: > BEGIN; > DROP TABLE `app_departments_users`; > DROP TABLE `app_medias`; > ALTER TABLE `app_documents` ADD COLUMN `rating` integer NOT NULL; Erm. Can you create a NOT NULL Column without a default in an ALTER Statement? I know you can't in MSSQL. > CREATE TABLE app_documents_attachments ( > id mediumint(9) unsigned auto_increment NOT NULL PRIMARY KEY, > document_id integer NOT NULL REFERENCES app_documents (id), > file_id integer NOT NULL REFERENCES app_files (id), > UNIQUE (document_id, file_id) > ); > COMMIT; > > I have only tested this with mysql, but it seems to be working well. > I'm still adding comments to the code, should I add a patch to #12 or > should I send it to someone? Not yet. It's still missing something. Well, two things, really. Plus the bit mentioned above, which is a technicality, though it's an important consideration. Let's take a use case: You create a FooApp for django. You fiddle with the tables, and eventually release FooApp 1.0. You find that for the next version you want two more tables: Bar and Baz, so you add a transition file to create Bar and Baz, and release FooApp 2.0 For the next version (3.0) you want a table Quux, and you find that rather than having a "price" field in Bar you actully want it to be in "net", "tax" and "commission", and not use the "price" field at all. Question number 1: How does your transition file cope with someone who *was* using FooApp 1.0 upgrading directly to 3.0? Question number 2: Assuming I can, as standard *calculate* the columns "net", "tax" and "commission" for the alreayd existing "price" column, how do I go about doing so at database upgrade time. My own particular take on this is up at <http://metamoof.net/blog/2005/07/26/well_i'll_be_django'd> but I haven't had the time to actually code up a patch, and I'm not certain it's the correct solution anyway. I'd appreciate thoughts, though. Moof -- Giles Antonio Radford, alias Moof "Too old to be a chicken and too young to be a dirty old man" Serving up my ego over at <http://metamoof.net/>
