misc/migration/3.21.0_Any.py
author Julien Cristau <julien.cristau@logilab.fr>
Mon, 01 Dec 2014 16:50:41 +0100
changeset 10314 8f3783dc6358
parent 10209 4c64a41c0a1d
child 10316 4ce8b8437838
permissions -rw-r--r--
Don't pass an encoding to rqlst.as_string()
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10208
249126034c0e Add unique index on entities.extid
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     1
249126034c0e Add unique index on entities.extid
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     2
helper = repo.system_source.dbhelper
249126034c0e Add unique index on entities.extid
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     3
sql('DROP INDEX entities_extid_idx')
249126034c0e Add unique index on entities.extid
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     4
sql(helper.sql_create_index('entities', 'extid', True))
10209
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
     5
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
     6
sql('''
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
     7
CREATE TABLE moved_entities (
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
     8
  eid INTEGER PRIMARY KEY NOT NULL,
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
     9
  extid VARCHAR(256) UNIQUE
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
    10
)
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
    11
''')
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
    12
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
    13
moved_entities = sql('SELECT -eid, extid FROM entities WHERE eid < 0')
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
    14
cu = session.cnxset.cu
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
    15
cu.executemany('INSERT INTO moved_entities (eid, extid) VALUES (%s, %s)',
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
    16
               moved_entities)
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
    17
sql('DELETE FROM entities WHERE eid < 0')
4c64a41c0a1d Use a moved_entities table to record external entities moved to the system source
Julien Cristau <julien.cristau@logilab.fr>
parents: 10208
diff changeset
    18
10208
249126034c0e Add unique index on entities.extid
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    19
commit()