Add foreign key for inline relations
authorJulien Cristau <julien.cristau@logilab.fr>
Thu, 15 Jan 2015 16:49:32 +0100
changeset 10201 989bbadbcd8d
parent 10200 cceb2c7c02f4
child 10202 aaabcb64f77f
Add foreign key for inline relations Related to #4846892
hooks/syncschema.py
server/schema2sql.py
server/test/unittest_schema2sql.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:
--- 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:
--- 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);