# HG changeset patch # User Julien Cristau # Date 1421336972 -3600 # Node ID 989bbadbcd8d6bf2c4a928e63a0b65bdd6fcade2 # Parent cceb2c7c02f44c1a11c667287d2e4fa032991599 Add foreign key for inline relations Related to #4846892 diff -r cceb2c7c02f4 -r 989bbadbcd8d hooks/syncschema.py --- a/hooks/syncschema.py Thu Jan 15 16:44:36 2015 +0100 +++ b/hooks/syncschema.py Thu Jan 15 16:49:32 2015 +0100 @@ -72,7 +72,7 @@ table = SQL_PREFIX + etype column = SQL_PREFIX + rtype try: - cnx.system_sql(str('ALTER TABLE %s ADD %s integer' % (table, column)), + cnx.system_sql(str('ALTER TABLE %s ADD %s integer REFERENCES entities (eid)' % (table, column)), rollback_on_failure=False) cnx.info('added column %s to table %s', column, table) except Exception: diff -r cceb2c7c02f4 -r 989bbadbcd8d server/schema2sql.py --- a/server/schema2sql.py Thu Jan 15 16:44:36 2015 +0100 +++ b/server/schema2sql.py Thu Jan 15 16:49:32 2015 +0100 @@ -117,8 +117,7 @@ sqltype = aschema2sql(dbhelper, eschema, rschema, attrschema, indent=' ') else: # inline relation - # XXX integer is ginco specific - sqltype = 'integer' + sqltype = 'integer REFERENCES entities (eid)' if i == len(attrs) - 1: w(' %s%s %s' % (prefix, rschema.type, sqltype)) else: diff -r cceb2c7c02f4 -r 989bbadbcd8d server/test/unittest_schema2sql.py --- a/server/test/unittest_schema2sql.py Thu Jan 15 16:44:36 2015 +0100 +++ b/server/test/unittest_schema2sql.py Thu Jan 15 16:49:32 2015 +0100 @@ -37,7 +37,7 @@ CREATE TABLE Affaire( sujet varchar(128), ref varchar(12), - inline_rel integer + inline_rel integer REFERENCES entities (eid) ); CREATE INDEX affaire_inline_rel_idx ON Affaire(inline_rel); @@ -68,7 +68,7 @@ description text, meta boolean, final boolean, - initial_state integer + initial_state integer REFERENCES entities (eid) ); CREATE INDEX eetype_name_idx ON Eetype(name); CREATE INDEX eetype_initial_state_idx ON Eetype(initial_state);