misc/migration/bootstrapmigration_repository.py
branchstable
changeset 3315 59220b704562
parent 3305 abae9045d2e4
child 3369 7b88d12b4ee2
child 3788 3d5abcd7c852
equal deleted inserted replaced
3298:caef98aa4a98 3315:59220b704562
    28     isession.commit()
    28     isession.commit()
    29     repo.hm.register_hook(uniquecstrcheck_before_modification, 'before_add_entity', '')
    29     repo.hm.register_hook(uniquecstrcheck_before_modification, 'before_add_entity', '')
    30     repo.hm.register_hook(uniquecstrcheck_before_modification, 'before_update_entity', '')
    30     repo.hm.register_hook(uniquecstrcheck_before_modification, 'before_update_entity', '')
    31     session.set_shared_data('do-not-insert-cwuri', False)
    31     session.set_shared_data('do-not-insert-cwuri', False)
    32 
    32 
       
    33 if applcubicwebversion < (3, 5, 0) and cubicwebversion >= (3, 5, 0):
       
    34     add_entity_type('Workflow')
       
    35     add_entity_type('BaseTransition')
       
    36     add_entity_type('WorkflowTransition')
       
    37     add_entity_type('SubWorkflowExitPoint')
       
    38     # drop explicit 'State allowed_transition Transition' since it should be
       
    39     # infered due to yams inheritance.  However we've to disable the schema
       
    40     # sync hook first to avoid to destroy existing data...
       
    41     from cubicweb.server.schemahooks import after_del_relation_type
       
    42     repo.hm.unregister_hook(after_del_relation_type,
       
    43                             'after_delete_relation', 'relation_type')
       
    44     try:
       
    45         drop_relation_definition('State', 'allowed_transition', 'Transition')
       
    46     finally:
       
    47         repo.hm.register_hook(after_del_relation_type,
       
    48                               'after_delete_relation', 'relation_type')
       
    49     schema.rebuild_infered_relations() # need to be explicitly called once everything is in place
       
    50 
       
    51     for et in rql('DISTINCT Any ET,ETN WHERE S state_of ET, ET name ETN',
       
    52                   ask_confirm=False).entities():
       
    53         wf = add_workflow(u'default %s workflow' % et.name, et.name,
       
    54                           ask_confirm=False)
       
    55         rql('SET S state_of WF WHERE S state_of ET, ET eid %(et)s, WF eid %(wf)s',
       
    56             {'et': et.eid, 'wf': wf.eid}, 'et', ask_confirm=False)
       
    57         rql('SET T transition_of WF WHERE T transition_of ET, ET eid %(et)s, WF eid %(wf)s',
       
    58             {'et': et.eid, 'wf': wf.eid}, 'et', ask_confirm=False)
       
    59         rql('SET WF initial_state S WHERE ET initial_state S, ET eid %(et)s, WF eid %(wf)s',
       
    60             {'et': et.eid, 'wf': wf.eid}, 'et', ask_confirm=False)
       
    61 
       
    62 
       
    63     rql('DELETE TrInfo TI WHERE NOT TI from_state S')
       
    64     rql('SET TI by_transition T WHERE TI from_state FS, TI to_state TS, '
       
    65         'FS allowed_transition T, T destination_state TS')
       
    66     checkpoint()
       
    67 
       
    68     drop_relation_definition('State', 'state_of', 'CWEType')
       
    69     drop_relation_definition('Transition', 'transition_of', 'CWEType')
       
    70     drop_relation_definition('CWEType', 'initial_state', 'State')
       
    71 
       
    72     sync_schema_props_perms()
       
    73 
    33 if applcubicwebversion < (3, 2, 2) and cubicwebversion >= (3, 2, 1):
    74 if applcubicwebversion < (3, 2, 2) and cubicwebversion >= (3, 2, 1):
    34     from base64 import b64encode
    75     from base64 import b64encode
    35     for table in ('entities', 'deleted_entities'):
    76     for table in ('entities', 'deleted_entities'):
    36         for eid, extid in sql('SELECT eid, extid FROM %s WHERE extid is NOT NULL'
    77         for eid, extid in sql('SELECT eid, extid FROM %s WHERE extid is NOT NULL'
    37                               % table, ask_confirm=False):
    78                               % table, ask_confirm=False):
    39                 {'extid': b64encode(extid), 'eid': eid}, ask_confirm=False)
    80                 {'extid': b64encode(extid), 'eid': eid}, ask_confirm=False)
    40     checkpoint()
    81     checkpoint()
    41 
    82 
    42 if applcubicwebversion < (3, 2, 0) and cubicwebversion >= (3, 2, 0):
    83 if applcubicwebversion < (3, 2, 0) and cubicwebversion >= (3, 2, 0):
    43     add_cube('card', update_database=False)
    84     add_cube('card', update_database=False)
    44 
       
    45 if applcubicwebversion < (2, 47, 0) and cubicwebversion >= (2, 47, 0):
       
    46      from cubicweb.server import schemaserial
       
    47      schemaserial.HAS_FULLTEXT_CONTAINER = False
       
    48      session.set_shared_data('do-not-insert-is_instance_of', True)
       
    49      add_attribute('CWRType', 'fulltext_container')
       
    50      schemaserial.HAS_FULLTEXT_CONTAINER = True
       
    51 
       
    52 
       
    53 
       
    54 if applcubicwebversion < (2, 50, 0) and cubicwebversion >= (2, 50, 0):
       
    55      session.set_shared_data('do-not-insert-is_instance_of', True)
       
    56      add_relation_type('is_instance_of')
       
    57      # fill the relation using an efficient sql query instead of using rql
       
    58      sql('INSERT INTO is_instance_of_relation '
       
    59          '  SELECT * from is_relation')
       
    60      checkpoint()
       
    61      session.set_shared_data('do-not-insert-is_instance_of', False)
       
    62 
       
    63 if applcubicwebversion < (2, 42, 0) and cubicwebversion >= (2, 42, 0):
       
    64      sql('ALTER TABLE entities ADD COLUMN mtime TIMESTAMP')
       
    65      sql('UPDATE entities SET mtime=CURRENT_TIMESTAMP')
       
    66      sql('CREATE INDEX entities_mtime_idx ON entities(mtime)')
       
    67      sql('''CREATE TABLE deleted_entities (
       
    68   eid INTEGER PRIMARY KEY NOT NULL,
       
    69   type VARCHAR(64) NOT NULL,
       
    70   source VARCHAR(64) NOT NULL,
       
    71   dtime TIMESTAMP NOT NULL,
       
    72   extid VARCHAR(256)
       
    73 )''')
       
    74      sql('CREATE INDEX deleted_entities_type_idx ON deleted_entities(type)')
       
    75      sql('CREATE INDEX deleted_entities_dtime_idx ON deleted_entities(dtime)')
       
    76      sql('CREATE INDEX deleted_entities_extid_idx ON deleted_entities(extid)')
       
    77      checkpoint()