misc/migration/3.21.0_Any.py
author Yann Voté <yann.vote@logilab.fr>
Fri, 26 Jun 2015 16:09:27 +0200
changeset 10460 d260722f2453
parent 10448 de5be53e2ea8
child 10482 88119421a09c
permissions -rw-r--r--
[dataimport] introduce the importer and extentity classes This introduces the ``ExtEntity`` class which is a transitional state between data at external source and the actual CubicWeb entities. ``ExtEntitiesImporter`` is then in charge to turn a bunch of ext entities into CW entities in repository, using a given store. This changeset also introduces ``SimpleImportLog`` and ``HTMLImportLog`` which implement the CW DataImportLog interface in order to show log messages in UI using simple text and HTML formats respectively, instead of storing these messages in database. Both have mostly been backported from cubes.skos.dataimport. Closes #5414753.
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')
10371
88577b10b31e [schema] add a unique index on cwuri
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10316
diff changeset
    22
88577b10b31e [schema] add a unique index on cwuri
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10316
diff changeset
    23
sync_schema_props_perms('cwuri')
10448
de5be53e2ea8 [migration] add sql constraints on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents: 10371
diff changeset
    24
de5be53e2ea8 [migration] add sql constraints on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents: 10371
diff changeset
    25
from cubicweb.server.schema2sql import check_constraint
de5be53e2ea8 [migration] add sql constraints on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents: 10371
diff changeset
    26
de5be53e2ea8 [migration] add sql constraints on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents: 10371
diff changeset
    27
for cwconstraint in rql('Any C WHERE R constrained_by C').entities():
de5be53e2ea8 [migration] add sql constraints on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents: 10371
diff changeset
    28
    cwrdef = cwconstraint.reverse_constrained_by[0]
de5be53e2ea8 [migration] add sql constraints on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents: 10371
diff changeset
    29
    rdef = cwrdef.yams_schema()
de5be53e2ea8 [migration] add sql constraints on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents: 10371
diff changeset
    30
    cstr = rdef.constraint_by_eid(cwconstraint.eid)
de5be53e2ea8 [migration] add sql constraints on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents: 10371
diff changeset
    31
    if cstr.type() not in ('BoundaryConstraint', 'IntervalBoundConstraint', 'StaticVocabularyConstraint'):
de5be53e2ea8 [migration] add sql constraints on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents: 10371
diff changeset
    32
        continue
de5be53e2ea8 [migration] add sql constraints on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents: 10371
diff changeset
    33
    cstrname, check = check_constraint(rdef.subject, rdef.object, rdef.rtype.type,
de5be53e2ea8 [migration] add sql constraints on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents: 10371
diff changeset
    34
            cstr, helper, prefix='cw_')
de5be53e2ea8 [migration] add sql constraints on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents: 10371
diff changeset
    35
    sql('ALTER TABLE %s%s ADD CONSTRAINT %s CHECK(%s)' % ('cw_', rdef.subject.type, cstrname, check))
de5be53e2ea8 [migration] add sql constraints on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents: 10371
diff changeset
    36
commit()