Hi all, we're playing with Foreign Key, trying to add them _after_ the database is created.
In the SVN there's the first implementation, based on hints from Joachim Selke and Timo Schulz. Actually it works (?) only with SQLAlchemy, and it requires the sqlalchemy-migrate extension (currently available only for SQLAlchemy 0.4, but a 0.5 version is on the way). This dependency is gracefully handled, and if not present... foreign keys are not created. In short: - added 'foreignKey' argument to dbschema.DBCol class, to specify the pointed column (two notations supported: 'TableName' and 'TableName.ColName', only the first one is used, and it defaults to 'TableName.id') - imdbpy2sql.py calls the dbschema.createForeignKeys function at the very end. This function calls the addForeignKeys method of every table). - so far _I THINK_ there's no need to prevent the creation of the indexes, on columns that will be "converted" to foreign keys: it looks like that database servers are smart enough to prevent the creation of useless indexes. But I'm not too sure about this, especially for Postgres. Needs to be tested on various db (actually I tried only MySQL and Postgres). A simple test: =========================================================== from imdb.parser.sql.dbschema import * #from imdb.parser.sql.objectadapter import * from imdb.parser.sql.alchemyadapter import * uri = 'DBSERVER://USERNAME:passw...@localhost/TESTDBNAME' TLIST = getDBTables(uri) setConnection(uri, TLIST, debug=True) dropTables(TLIST) createTables(TLIST) Title = TLIST[4] Title(title=u'A Title', kindID=2) Title(title=u'Another Title', kindID=1) createIndexes(TLIST) createForeignKeys(TLIST) =========================================================== -- Davide Alberani <davide.alber...@gmail.com> [PGP KeyID: 0x465BFD47] http://erlug.linux.it/~da/ ------------------------------------------------------------------------------ This SF.net email is sponsored by: SourcForge Community SourceForge wants to tell your story. http://p.sf.net/sfu/sf-spreadtheword _______________________________________________ Imdbpy-devel mailing list Imdbpy-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/imdbpy-devel