Implementing id = uuid.uuid4() on an existing database

108 views
Skip to first unread message

Johann Spies

unread,
Apr 14, 2011, 4:03:40 AM4/14/11
to web...@googlegroups.com
I want to syncrhonize a database to another computer using the method indicated in the book (http://web2py.com/book/default/chapter/06?search=sync#CSV-and-Remote-Database-Synchronization).  Unfortunately the database was not designed from the beginning to use uuid.  Is it possible to modify the existing database and update it without losing foreign keys to use uuid's?  I am using Postgresql.

Regards
Johann

--
 May grace and peace be yours in abundance through the full knowledge of God and of Jesus our Lord!  His divine power has given us everything we need for life and godliness through the full knowledge of the one who called us by his own glory and excellence.
                                                    2 Pet. 1:2b,3a

howesc

unread,
Apr 14, 2011, 12:26:51 PM4/14/11
to web...@googlegroups.com
Johann,

the steps as i see it:
 - add new uuid field for your new primary key, don't drop old one yet
 - fill in the uuid field
 - add a new foreign key field that will store UUID
 - use the old foreign key to lookup the uuid of the reference
 - store that uuid
 - alter tables to make the uuid fields the primary and foreign keys from the database's perspective
 - drop the old id columns

you'll have to do that with some sql scripting, and then update your web2py model files accordingly.

good luck!

christian

Johann Spies

unread,
Apr 15, 2011, 2:29:23 AM4/15/11
to web...@googlegroups.com

Thanks Christian.  That sounds doable.

Regards
Johann
Reply all
Reply to author
Forward
0 new messages