misc/migration/3.21.0_Any.py
author Nicolas Chauvat <nicolas.chauvat@logilab.fr>
Fri, 31 Oct 2014 17:17:26 +0100
changeset 10316 4ce8b8437838
parent 10209 4c64a41c0a1d
child 10371 88577b10b31e
permissions -rw-r--r--
[schemas] make CWEType.final default to False (closes #5049201)
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()
10316
4ce8b8437838 [schemas] make CWEType.final default to False (closes #5049201)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 10209
diff changeset
    20
4ce8b8437838 [schemas] make CWEType.final default to False (closes #5049201)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 10209
diff changeset
    21
sync_schema_props_perms('CWEType')