[server] use sqls_create_multicol_unique_index to index entities.extid
authorJulien Cristau <julien.cristau@logilab.fr>
Tue, 29 Sep 2015 15:15:03 +0200
changeset 10626 93f8d239c708
parent 10625 684dbf6722ef
child 10627 ffef8ac383f4
[server] use sqls_create_multicol_unique_index to index entities.extid SQL Server's UNIQUE is not standards compliant, it doesn't accept two NULL values. Related to #7173702.
misc/migration/3.21.0_Any.py
server/sources/native.py
--- a/misc/migration/3.21.0_Any.py	Tue Sep 29 15:11:29 2015 +0200
+++ b/misc/migration/3.21.0_Any.py	Tue Sep 29 15:15:03 2015 +0200
@@ -103,7 +103,10 @@
 helper = repo.system_source.dbhelper
 
 helper.drop_index(cu, 'entities', 'extid', False)
-helper.create_index(cu, 'entities', 'extid', True)
+# don't use create_index because it doesn't work for columns that may be NULL
+# on sqlserver
+for query in helper.sqls_create_multicol_unique_index('entities', ['extid']):
+    cu.execute(query)
 
 if 'moved_entities' not in helper.list_tables(cu):
     sql('''
--- a/server/sources/native.py	Tue Sep 29 15:11:29 2015 +0200
+++ b/server/sources/native.py	Tue Sep 29 15:15:03 2015 +0200
@@ -1400,7 +1400,7 @@
   eid INTEGER PRIMARY KEY NOT NULL,
   type VARCHAR(64) NOT NULL,
   asource VARCHAR(128) NOT NULL,
-  extid VARCHAR(256) UNIQUE
+  extid VARCHAR(256)
 );;
 CREATE INDEX entities_type_idx ON entities(type);;
 CREATE TABLE moved_entities (
@@ -1458,18 +1458,22 @@
     DELETE FROM tx_relation_actions WHERE tx_uuid=OLD.tx_uuid;
 END;;
 '''
+    schema += ';;'.join(helper.sqls_create_multicol_unique_index('entities', ['extid']))
+    schema += ';;\n'
     return schema
 
 
 def sql_drop_schema(driver):
     helper = get_db_helper(driver)
     return """
+%s;
 %s
 DROP TABLE entities;
 DROP TABLE tx_entity_actions;
 DROP TABLE tx_relation_actions;
 DROP TABLE transactions;
-""" % helper.sql_drop_numrange('entities_id_seq')
+""" % (';'.join(helper.sqls_drop_multicol_unique_index('entities', ['extid'])),
+       helper.sql_drop_numrange('entities_id_seq'))
 
 
 def grant_schema(user, set_owner=True):