cubicweb/misc/migration/bootstrapmigration_repository.py
author Julien Cristau <julien.cristau@logilab.fr>
Wed, 17 Feb 2016 14:03:56 +0100
changeset 11245 20b2e7ceecf6
parent 11057 0b59724cb3f2
child 11246 ceb0e8e9129e
permissions -rw-r--r--
[migration] move CWComputedRType later The ordering in this file is a mess, and things don't actually work this way (when upgrading from 3.17).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9163
fe4c1c1982e7 [3.17 migration] when some cube is missing, add_cube raise ConfigurationError, not ImportError. Closes #2981477
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8830
diff changeset
     1
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4944
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
"""allways executed before all others in server migration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
it should only include low level schema changes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
"""
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10553
diff changeset
    22
from __future__ import print_function
4944
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
    23
10684
7e9c9a32f24f [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10663
diff changeset
    24
from six import text_type
7e9c9a32f24f [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10663
diff changeset
    25
9163
fe4c1c1982e7 [3.17 migration] when some cube is missing, add_cube raise ConfigurationError, not ImportError. Closes #2981477
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8830
diff changeset
    26
from cubicweb import ConfigurationError
4944
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
    27
from cubicweb.server.session import hooks_control
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
    28
from cubicweb.server import schemaserial as ss
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    30
applcubicwebversion, cubicwebversion = versions_map['cubicweb']
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    31
4570
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    32
def _add_relation_definition_no_perms(subjtype, rtype, objtype):
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    33
    rschema = fsschema.rschema(rtype)
4944
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
    34
    rdef = rschema.rdefs[(subjtype, objtype)]
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
    35
    rdef.rtype = schema.rschema(rtype)
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
    36
    rdef.subject = schema.eschema(subjtype)
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
    37
    rdef.object = schema.eschema(objtype)
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
    38
    ss.execschemarql(rql, rdef, ss.rdef2rql(rdef, CSTRMAP, groupmap=None))
4570
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    39
    commit(ask_confirm=False)
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    40
9585
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    41
def replace_eid_sequence_with_eid_numrange(session):
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    42
    dbh = session.repo.system_source.dbhelper
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    43
    cursor = session.cnxset.cu
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    44
    try:
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    45
        cursor.execute(dbh.sql_sequence_current_state('entities_id_seq'))
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    46
        lasteid = cursor.fetchone()[0]
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    47
    except: # programming error, already migrated
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    48
        return
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    49
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    50
    cursor.execute(dbh.sql_drop_sequence('entities_id_seq'))
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    51
    cursor.execute(dbh.sql_create_numrange('entities_id_seq'))
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    52
    cursor.execute(dbh.sql_restart_numrange('entities_id_seq', initial_value=lasteid))
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    53
    session.commit()
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    54
10270
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    55
if applcubicwebversion <= (3, 13, 0) and cubicwebversion >= (3, 13, 1):
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    56
    sql('ALTER TABLE entities ADD asource VARCHAR(64)')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    57
    sql('UPDATE entities SET asource=cw_name  '
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    58
        'FROM cw_CWSource, cw_source_relation '
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    59
        'WHERE entities.eid=cw_source_relation.eid_from AND cw_source_relation.eid_to=cw_CWSource.cw_eid')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    60
    commit()
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    61
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    62
if applcubicwebversion <= (3, 14, 4) and cubicwebversion >= (3, 14, 4):
10301
729f36a1bcfa merge 3.20.6 into 3.21
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10272
diff changeset
    63
    from cubicweb.server import schema2sql as y2sql
10270
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    64
    dbhelper = repo.system_source.dbhelper
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    65
    rdefdef = schema['CWSource'].rdef('name')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    66
    attrtype = y2sql.type_from_constraints(dbhelper, rdefdef.object, rdefdef.constraints).split()[0]
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    67
    cursor = session.cnxset.cu
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    68
    sql('UPDATE entities SET asource = source WHERE asource is NULL')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    69
    dbhelper.change_col_type(cursor, 'entities', 'asource', attrtype, False)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    70
    dbhelper.change_col_type(cursor, 'entities', 'source', attrtype, False)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    71
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    72
    # we now have a functional asource column, start using the normal eid_type_source method
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    73
    if repo.system_source.eid_type_source == repo.system_source.eid_type_source_pre_131:
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    74
        del repo.system_source.eid_type_source
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    75
9585
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    76
if applcubicwebversion < (3, 19, 0) and cubicwebversion >= (3, 19, 0):
10058
d47c318f95b2 [migration/bootstrap] add explicit index removal for sqlserver, be tolerant to migration replay
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9708
diff changeset
    77
    try: 
d47c318f95b2 [migration/bootstrap] add explicit index removal for sqlserver, be tolerant to migration replay
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9708
diff changeset
    78
        # need explicit drop of the indexes on some database systems (sqlserver)
d47c318f95b2 [migration/bootstrap] add explicit index removal for sqlserver, be tolerant to migration replay
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9708
diff changeset
    79
        sql(repo.system_source.dbhelper.sql_drop_index('entities', 'mtime'))
d47c318f95b2 [migration/bootstrap] add explicit index removal for sqlserver, be tolerant to migration replay
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9708
diff changeset
    80
        sql('ALTER TABLE "entities" DROP COLUMN "mtime"')
d47c318f95b2 [migration/bootstrap] add explicit index removal for sqlserver, be tolerant to migration replay
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9708
diff changeset
    81
        sql('ALTER TABLE "entities" DROP COLUMN "source"')
d47c318f95b2 [migration/bootstrap] add explicit index removal for sqlserver, be tolerant to migration replay
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9708
diff changeset
    82
    except: # programming error, already migrated
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10553
diff changeset
    83
        print("Failed to drop mtime or source database columns")
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10553
diff changeset
    84
        print("'entities' table of the database has probably been already updated")
9708
b36bc18f6ef7 [migration] move 'entities' table changes from 3.19.0 to bootstrap script
Julien Cristau <julien.cristau@logilab.fr>
parents: 9585
diff changeset
    85
b36bc18f6ef7 [migration] move 'entities' table changes from 3.19.0 to bootstrap script
Julien Cristau <julien.cristau@logilab.fr>
parents: 9585
diff changeset
    86
    commit()
b36bc18f6ef7 [migration] move 'entities' table changes from 3.19.0 to bootstrap script
Julien Cristau <julien.cristau@logilab.fr>
parents: 9585
diff changeset
    87
9585
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    88
    replace_eid_sequence_with_eid_numrange(session)
3f5b59527d31 [source/native] allow many eid creation per .create_eid call (closes #3526594)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9543
diff changeset
    89
10270
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    90
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    91
if applcubicwebversion < (3, 18, 0) and cubicwebversion >= (3, 18, 0):
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    92
    driver = config.system_source_config['db-driver']
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    93
    if not (driver == 'postgres' or driver.startswith('sqlserver')):
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    94
        import sys
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10553
diff changeset
    95
        print('This migration is not supported for backends other than sqlserver or postgres (yet).', file=sys.stderr)
10270
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    96
        sys.exit(1)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    97
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    98
    add_relation_definition('CWAttribute', 'add_permission', 'CWGroup')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
    99
    add_relation_definition('CWAttribute', 'add_permission', 'RQLExpression')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   100
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   101
    # a bad defaultval in 3.13.8 schema was fixed in 3.13.9, but the migration was missed
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   102
    rql('SET ATTR defaultval NULL WHERE ATTR from_entity E, E name "CWSource", ATTR relation_type T, T name "in_synchronization"')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   103
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   104
    # the migration gets confused when we change rdefs out from under it.  So
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   105
    # explicitly remove this size constraint so it doesn't stick around and break
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   106
    # things later.
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   107
    rdefeid = schema['defaultval'].rdefs.values()[0].eid
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   108
    rql('DELETE CWConstraint C WHERE C cstrtype T, T name "SizeConstraint", R constrained_by C, R eid %(eid)s', {'eid': rdefeid})
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   109
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   110
    sync_schema_props_perms('defaultval')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   111
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   112
    def convert_defaultval(cwattr, default):
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   113
        from decimal import Decimal
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   114
        import yams
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   115
        from cubicweb import Binary
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   116
        if default is None:
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   117
            return
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   118
        if isinstance(default, Binary):
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   119
            # partially migrated instance, try to be idempotent
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   120
            return default
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   121
        atype = cwattr.to_entity[0].name
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   122
        if atype == 'Boolean':
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   123
            # boolean attributes with default=False were stored as ''
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   124
            assert default in ('True', 'False', ''), repr(default)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   125
            default = default == 'True'
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   126
        elif atype in ('Int', 'BigInt'):
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   127
            default = int(default)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   128
        elif atype == 'Float':
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   129
            default = float(default)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   130
        elif atype == 'Decimal':
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   131
            default = Decimal(default)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   132
        elif atype in ('Date', 'Datetime', 'TZDatetime', 'Time'):
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   133
            try:
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   134
                # handle NOW and TODAY, keep them stored as strings
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   135
                yams.KEYWORD_MAP[atype][default.upper()]
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   136
                default = default.upper()
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   137
            except KeyError:
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   138
                # otherwise get an actual date or datetime
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   139
                default = yams.DATE_FACTORY_MAP[atype](default)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   140
        else:
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   141
            assert atype == 'String', atype
10684
7e9c9a32f24f [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10663
diff changeset
   142
            default = text_type(default)
10270
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   143
        return Binary.zpickle(default)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   144
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   145
    dbh = repo.system_source.dbhelper
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   146
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   147
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   148
    sql('ALTER TABLE cw_cwattribute ADD new_defaultval %s' % dbh.TYPE_MAPPING['Bytes'])
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   149
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   150
    for cwattr in rql('CWAttribute X').entities():
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   151
        olddefault = cwattr.defaultval
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   152
        if olddefault is not None:
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   153
            req = "UPDATE cw_cwattribute SET new_defaultval = %(val)s WHERE cw_eid = %(eid)s"
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   154
            args = {'val': dbh.binary_value(convert_defaultval(cwattr, olddefault).getvalue()), 'eid': cwattr.eid}
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   155
            sql(req, args, ask_confirm=False)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   156
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   157
    sql('ALTER TABLE cw_cwattribute DROP COLUMN cw_defaultval')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   158
    if driver == 'postgres':
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   159
        sql('ALTER TABLE cw_cwattribute RENAME COLUMN new_defaultval TO cw_defaultval')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   160
    else: # sqlserver
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   161
        sql("sp_rename 'cw_cwattribute.new_defaultval', 'cw_defaultval', 'COLUMN'")
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   162
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   163
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   164
    # Set object type to "Bytes" for CWAttribute's "defaultval" attribute
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   165
    rql('SET X to_entity B WHERE X is CWAttribute, X from_entity Y, Y name "CWAttribute", '
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   166
        'X relation_type Z, Z name "defaultval", B name "Bytes", NOT X to_entity B')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   167
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   168
    oldrdef = schema['CWAttribute'].rdef('defaultval')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   169
    import yams.buildobjs as ybo
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   170
    newrdef = ybo.RelationDefinition('CWAttribute', 'defaultval', 'Bytes')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   171
    newrdef.eid = oldrdef.eid
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   172
    schema.add_relation_def(newrdef)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   173
    schema.del_relation_def('CWAttribute', 'defaultval', 'String')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   174
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   175
    commit()
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   176
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   177
    sync_schema_props_perms('defaultval')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   178
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   179
    for rschema in schema.relations():
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   180
        if rschema.symmetric:
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   181
            subjects = set(repr(e.type) for e in rschema.subjects())
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   182
            objects = set(repr(e.type) for e in rschema.objects())
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   183
            assert subjects == objects
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   184
            martians = set(str(eid) for eid, in sql('SELECT eid_to FROM %s_relation, entities WHERE eid_to = eid AND type NOT IN (%s)' %
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   185
                                               (rschema.type, ','.join(subjects))))
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   186
            martians |= set(str(eid) for eid, in sql('SELECT eid_from FROM %s_relation, entities WHERE eid_from = eid AND type NOT IN (%s)' %
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   187
                                                (rschema.type, ','.join(subjects))))
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   188
            if martians:
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   189
                martians = ','.join(martians)
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10553
diff changeset
   190
                print('deleting broken relations %s for eids %s' % (rschema.type, martians))
10270
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   191
                sql('DELETE FROM %s_relation WHERE eid_from IN (%s) OR eid_to IN (%s)' % (rschema.type, martians, martians))
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   192
            with session.deny_all_hooks_but():
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   193
                rql('SET X %(r)s Y WHERE Y %(r)s X, NOT X %(r)s Y' % {'r': rschema.type})
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   194
            commit()
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   195
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   196
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   197
    # multi columns unique constraints regeneration
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   198
    from cubicweb.server import schemaserial
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   199
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   200
    # syncschema hooks would try to remove indices but
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   201
    # 1) we already do that below
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   202
    # 2) the hook expects the CWUniqueTogetherConstraint.name attribute that hasn't
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   203
    #    yet been added
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   204
    with session.allow_all_hooks_but('syncschema'):
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   205
        rql('DELETE CWUniqueTogetherConstraint C')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   206
    commit()
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   207
    add_attribute('CWUniqueTogetherConstraint', 'name')
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   208
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   209
    # low-level wipe code for postgres & sqlserver, plain sql ...
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   210
    if driver == 'postgres':
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   211
        for indexname, in sql('select indexname from pg_indexes'):
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   212
            if indexname.startswith('unique_'):
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10553
diff changeset
   213
                print('dropping index', indexname)
10270
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   214
                sql('DROP INDEX %s' % indexname)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   215
        commit()
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   216
    elif driver.startswith('sqlserver'):
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   217
        for viewname, in sql('select name from sys.views'):
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   218
            if viewname.startswith('utv_'):
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10553
diff changeset
   219
                print('dropping view (index should be cascade-deleted)', viewname)
10270
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   220
                sql('DROP VIEW %s' % viewname)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   221
        commit()
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   222
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   223
    # recreate the constraints, hook will lead to low-level recreation
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   224
    for eschema in sorted(schema.entities()):
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   225
        if eschema._unique_together:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10553
diff changeset
   226
            print('recreate unique indexes for', eschema)
10270
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   227
            rql_args = schemaserial.uniquetogether2rqls(eschema)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   228
            for rql, args in rql_args:
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   229
                args['x'] = eschema.eid
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   230
                session.execute(rql, args)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   231
    commit()
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   232
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   233
    # all attributes perms have to be refreshed ...
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   234
    for rschema in sorted(schema.relations()):
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   235
        if rschema.final:
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   236
            if rschema.type in fsschema:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10553
diff changeset
   237
                print('sync perms for', rschema.type)
10270
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   238
                sync_schema_props_perms(rschema.type, syncprops=False, ask_confirm=False, commit=False)
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   239
            else:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10553
diff changeset
   240
                print('WARNING: attribute %s missing from fs schema' % rschema.type)
10270
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   241
    commit()
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   242
8800
8ca1a0da5a29 [web/views] extract cube sioc (closes #1916018)
Simon Chabot <simon.chabot@logilab.fr>
parents: 8696
diff changeset
   243
if applcubicwebversion < (3, 17, 0) and cubicwebversion >= (3, 17, 0):
8ca1a0da5a29 [web/views] extract cube sioc (closes #1916018)
Simon Chabot <simon.chabot@logilab.fr>
parents: 8696
diff changeset
   244
    try:
8ca1a0da5a29 [web/views] extract cube sioc (closes #1916018)
Simon Chabot <simon.chabot@logilab.fr>
parents: 8696
diff changeset
   245
        add_cube('sioc', update_database=False)
9163
fe4c1c1982e7 [3.17 migration] when some cube is missing, add_cube raise ConfigurationError, not ImportError. Closes #2981477
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8830
diff changeset
   246
    except ConfigurationError:
8800
8ca1a0da5a29 [web/views] extract cube sioc (closes #1916018)
Simon Chabot <simon.chabot@logilab.fr>
parents: 8696
diff changeset
   247
        if not confirm('In cubicweb 3.17 sioc views have been moved to the sioc '
8ca1a0da5a29 [web/views] extract cube sioc (closes #1916018)
Simon Chabot <simon.chabot@logilab.fr>
parents: 8696
diff changeset
   248
                       'cube, which is not installed.  Continue anyway?'):
8ca1a0da5a29 [web/views] extract cube sioc (closes #1916018)
Simon Chabot <simon.chabot@logilab.fr>
parents: 8696
diff changeset
   249
            raise
8803
47dd517d6c6f [web/views] extract cube embed (closes #1916015)
Vladimir Popescu <vladimir.popescu@logilab.fr>
parents: 8800
diff changeset
   250
    try:
47dd517d6c6f [web/views] extract cube embed (closes #1916015)
Vladimir Popescu <vladimir.popescu@logilab.fr>
parents: 8800
diff changeset
   251
        add_cube('embed', update_database=False)
9163
fe4c1c1982e7 [3.17 migration] when some cube is missing, add_cube raise ConfigurationError, not ImportError. Closes #2981477
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8830
diff changeset
   252
    except ConfigurationError:
8803
47dd517d6c6f [web/views] extract cube embed (closes #1916015)
Vladimir Popescu <vladimir.popescu@logilab.fr>
parents: 8800
diff changeset
   253
        if not confirm('In cubicweb 3.17 embedding views have been moved to the embed '
47dd517d6c6f [web/views] extract cube embed (closes #1916015)
Vladimir Popescu <vladimir.popescu@logilab.fr>
parents: 8800
diff changeset
   254
                       'cube, which is not installed.  Continue anyway?'):
47dd517d6c6f [web/views] extract cube embed (closes #1916015)
Vladimir Popescu <vladimir.popescu@logilab.fr>
parents: 8800
diff changeset
   255
            raise
8830
7fd6c52ef878 [web/views] extract cube geocoding (closes #353000)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8803
diff changeset
   256
    try:
7fd6c52ef878 [web/views] extract cube geocoding (closes #353000)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8803
diff changeset
   257
        add_cube('geocoding', update_database=False)
9163
fe4c1c1982e7 [3.17 migration] when some cube is missing, add_cube raise ConfigurationError, not ImportError. Closes #2981477
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8830
diff changeset
   258
    except ConfigurationError:
8830
7fd6c52ef878 [web/views] extract cube geocoding (closes #353000)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8803
diff changeset
   259
        if not confirm('In cubicweb 3.17 geocoding views have been moved to the geocoding '
7fd6c52ef878 [web/views] extract cube geocoding (closes #353000)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8803
diff changeset
   260
                       'cube, which is not installed.  Continue anyway?'):
7fd6c52ef878 [web/views] extract cube geocoding (closes #353000)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8803
diff changeset
   261
            raise
8800
8ca1a0da5a29 [web/views] extract cube sioc (closes #1916018)
Simon Chabot <simon.chabot@logilab.fr>
parents: 8696
diff changeset
   262
7543
570522300e22 [ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   263
7797
a71618a75b53 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7782
diff changeset
   264
if applcubicwebversion <= (3, 14, 0) and cubicwebversion >= (3, 14, 0):
a71618a75b53 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7782
diff changeset
   265
    if 'require_permission' in schema and not 'localperms'in repo.config.cubes():
a71618a75b53 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7782
diff changeset
   266
        from cubicweb import ExecutionError
a71618a75b53 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7782
diff changeset
   267
        try:
a71618a75b53 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7782
diff changeset
   268
            add_cube('localperms', update_database=False)
9163
fe4c1c1982e7 [3.17 migration] when some cube is missing, add_cube raise ConfigurationError, not ImportError. Closes #2981477
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8830
diff changeset
   269
        except ConfigurationError:
7797
a71618a75b53 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7782
diff changeset
   270
            raise ExecutionError('In cubicweb 3.14, CWPermission and related stuff '
a71618a75b53 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7782
diff changeset
   271
                                 'has been moved to cube localperms. Install it first.')
a71618a75b53 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7782
diff changeset
   272
10270
1ae64186af94 [migration] reorder system tables / meta-schema migration into bootstrap_migration
Erica Marco <erica.marco@logilab.fr>
parents: 10058
diff changeset
   273
4570
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   274
if applcubicwebversion == (3, 6, 0) and cubicwebversion >= (3, 6, 0):
4944
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   275
    CSTRMAP = dict(rql('Any T, X WHERE X is CWConstraintType, X name T',
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   276
                       ask_confirm=False))
4570
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   277
    _add_relation_definition_no_perms('CWAttribute', 'update_permission', 'CWGroup')
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   278
    _add_relation_definition_no_perms('CWAttribute', 'update_permission', 'RQLExpression')
4835
13b0b96d7982 [repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4834
diff changeset
   279
    rql('SET X update_permission Y WHERE X is CWAttribute, X add_permission Y')
4570
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   280
    drop_relation_definition('CWAttribute', 'delete_permission', 'CWGroup')
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   281
    drop_relation_definition('CWAttribute', 'delete_permission', 'RQLExpression')
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   282
ede247bbbf62 follow yams api change: attributes permissions are now defined for
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   283
elif applcubicwebversion < (3, 6, 0) and cubicwebversion >= (3, 6, 0):
4944
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   284
    CSTRMAP = dict(rql('Any T, X WHERE X is CWConstraintType, X name T',
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   285
                       ask_confirm=False))
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6896
diff changeset
   286
    session.set_cnxset()
4011
394f853bb653 [migration] write migration instructions for permissions handling on relation definition
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3890
diff changeset
   287
    permsdict = ss.deserialize_ertype_permissions(session)
394f853bb653 [migration] write migration instructions for permissions handling on relation definition
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3890
diff changeset
   288
4944
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   289
    with hooks_control(session, session.HOOKS_ALLOW_ALL, 'integrity'):
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   290
        for rschema in repo.schema.relations():
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   291
            rpermsdict = permsdict.get(rschema.eid, {})
10663
54b8a1f249fb [py3k] dict.itervalues → dict.values
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10589
diff changeset
   292
            for rdef in rschema.rdefs.values():
4944
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   293
                for action in rdef.ACTIONS:
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   294
                    actperms = []
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   295
                    for something in rpermsdict.get(action == 'update' and 'add' or action, ()):
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   296
                        if isinstance(something, tuple):
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   297
                            actperms.append(rdef.rql_expression(*something))
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   298
                        else: # group name
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   299
                            actperms.append(something)
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   300
                    rdef.set_action_permissions(action, actperms)
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   301
        for action in ('read', 'add', 'delete'):
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   302
            _add_relation_definition_no_perms('CWRelation', '%s_permission' % action, 'CWGroup')
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   303
            _add_relation_definition_no_perms('CWRelation', '%s_permission' % action, 'RQLExpression')
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   304
        for action in ('read', 'update'):
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   305
            _add_relation_definition_no_perms('CWAttribute', '%s_permission' % action, 'CWGroup')
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   306
            _add_relation_definition_no_perms('CWAttribute', '%s_permission' % action, 'RQLExpression')
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   307
        for action in ('read', 'add', 'delete'):
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   308
            rql('SET X %s_permission Y WHERE X is CWRelation, '
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   309
                'RT %s_permission Y, X relation_type RT, Y is CWGroup' % (action, action))
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   310
            rql('INSERT RQLExpression Y: Y exprtype YET, Y mainvars YMV, Y expression YEX, '
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   311
                'X %s_permission Y WHERE X is CWRelation, '
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   312
                'X relation_type RT, RT %s_permission Y2, Y2 exprtype YET, '
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   313
                'Y2 mainvars YMV, Y2 expression YEX' % (action, action))
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   314
        rql('SET X read_permission Y WHERE X is CWAttribute, '
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   315
            'RT read_permission Y, X relation_type RT, Y is CWGroup')
4011
394f853bb653 [migration] write migration instructions for permissions handling on relation definition
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3890
diff changeset
   316
        rql('INSERT RQLExpression Y: Y exprtype YET, Y mainvars YMV, Y expression YEX, '
4944
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   317
            'X read_permission Y WHERE X is CWAttribute, '
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   318
            'X relation_type RT, RT read_permission Y2, Y2 exprtype YET, '
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   319
            'Y2 mainvars YMV, Y2 expression YEX')
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   320
        rql('SET X update_permission Y WHERE X is CWAttribute, '
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   321
            'RT add_permission Y, X relation_type RT, Y is CWGroup')
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   322
        rql('INSERT RQLExpression Y: Y exprtype YET, Y mainvars YMV, Y expression YEX, '
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   323
            'X update_permission Y WHERE X is CWAttribute, '
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   324
            'X relation_type RT, RT add_permission Y2, Y2 exprtype YET, '
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   325
            'Y2 mainvars YMV, Y2 expression YEX')
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   326
        for action in ('read', 'add', 'delete'):
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   327
            drop_relation_definition('CWRType', '%s_permission' % action, 'CWGroup', commit=False)
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   328
            drop_relation_definition('CWRType', '%s_permission' % action, 'RQLExpression')
6222
21772f4e41d9 [migration] attempt to fix pre 3.6 migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   329
    sync_schema_props_perms('read_permission', syncperms=False) # fix read_permission cardinality
21772f4e41d9 [migration] attempt to fix pre 3.6 migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   330
7549
465009397d91 [migration] don't add CWUniqueConstraint if already there (may occurs when running a migration in multiple times
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6896
diff changeset
   331
if applcubicwebversion < (3, 9, 6) and cubicwebversion >= (3, 9, 6) and not 'CWUniqueTogetherConstraint' in schema:
6222
21772f4e41d9 [migration] attempt to fix pre 3.6 migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   332
    add_entity_type('CWUniqueTogetherConstraint')
4011
394f853bb653 [migration] write migration instructions for permissions handling on relation definition
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3890
diff changeset
   333
6896
784d5df35af1 [migration] cwunique constraint schema fix must be done in bootstrap migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6222
diff changeset
   334
if not ('CWUniqueTogetherConstraint', 'CWRType') in schema['relations'].rdefs:
784d5df35af1 [migration] cwunique constraint schema fix must be done in bootstrap migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6222
diff changeset
   335
    add_relation_definition('CWUniqueTogetherConstraint', 'relations', 'CWRType')
784d5df35af1 [migration] cwunique constraint schema fix must be done in bootstrap migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6222
diff changeset
   336
    rql('SET C relations RT WHERE C relations RDEF, RDEF relation_type RT')
784d5df35af1 [migration] cwunique constraint schema fix must be done in bootstrap migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6222
diff changeset
   337
    commit()
784d5df35af1 [migration] cwunique constraint schema fix must be done in bootstrap migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6222
diff changeset
   338
    drop_relation_definition('CWUniqueTogetherConstraint', 'relations', 'CWAttribute')
784d5df35af1 [migration] cwunique constraint schema fix must be done in bootstrap migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6222
diff changeset
   339
    drop_relation_definition('CWUniqueTogetherConstraint', 'relations', 'CWRelation')
784d5df35af1 [migration] cwunique constraint schema fix must be done in bootstrap migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6222
diff changeset
   340
784d5df35af1 [migration] cwunique constraint schema fix must be done in bootstrap migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6222
diff changeset
   341
2463
5200c0f7d2d5 add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2462
diff changeset
   342
if applcubicwebversion < (3, 4, 0) and cubicwebversion >= (3, 4, 0):
2892
7ae3d62a8328 hooks have been refactored, call [re|de]activate_verification_hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2696
diff changeset
   343
4944
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   344
    with hooks_control(session, session.HOOKS_ALLOW_ALL, 'integrity'):
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   345
        session.set_shared_data('do-not-insert-cwuri', True)
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   346
        add_relation_type('cwuri')
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   347
        base_url = session.base_url()
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   348
        for eid, in rql('Any X', ask_confirm=False):
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   349
            type, source, extid = session.describe(eid)
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   350
            if source == 'system':
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   351
                rql('SET X cwuri %(u)s WHERE X eid %(x)s',
9515
b0dd5b57d2d8 [dataimport, migration] more fixes in the spirit of a6c32edabc8d:
Dimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
parents: 9163
diff changeset
   352
                    {'x': eid, 'u': u'%s%s' % (base_url, eid)})
4944
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   353
        isession.commit()
65533aee8d0a fix migration when upgrading from cw < 3.6 to cw 3.7
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4843
diff changeset
   354
        session.set_shared_data('do-not-insert-cwuri', False)
2463
5200c0f7d2d5 add migration script for the new cwuri metadata attribute
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2462
diff changeset
   355
2965
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   356
if applcubicwebversion < (3, 5, 0) and cubicwebversion >= (3, 5, 0):
3788
3d5abcd7c852 [migration] warn if 3.5 workflow migration is going to fail
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3305
diff changeset
   357
    # check that migration is not doomed
3d5abcd7c852 [migration] warn if 3.5 workflow migration is going to fail
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3305
diff changeset
   358
    rset = rql('Any X,Y WHERE X transition_of E, Y transition_of E, '
3d5abcd7c852 [migration] warn if 3.5 workflow migration is going to fail
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3305
diff changeset
   359
               'X name N, Y name N, NOT X identity Y',
3d5abcd7c852 [migration] warn if 3.5 workflow migration is going to fail
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3305
diff changeset
   360
               ask_confirm=False)
3d5abcd7c852 [migration] warn if 3.5 workflow migration is going to fail
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3305
diff changeset
   361
    if rset:
3d5abcd7c852 [migration] warn if 3.5 workflow migration is going to fail
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3305
diff changeset
   362
        from logilab.common.shellutils import ASK
3d5abcd7c852 [migration] warn if 3.5 workflow migration is going to fail
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3305
diff changeset
   363
        if not ASK.confirm('Migration will fail because of transitions with the same name. '
3d5abcd7c852 [migration] warn if 3.5 workflow migration is going to fail
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3305
diff changeset
   364
                           'Continue anyway ?'):
3d5abcd7c852 [migration] warn if 3.5 workflow migration is going to fail
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3305
diff changeset
   365
            import sys
3d5abcd7c852 [migration] warn if 3.5 workflow migration is going to fail
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3305
diff changeset
   366
            sys.exit(1)
3d5abcd7c852 [migration] warn if 3.5 workflow migration is going to fail
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3305
diff changeset
   367
    # proceed with migration
2965
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   368
    add_entity_type('Workflow')
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   369
    add_entity_type('BaseTransition')
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   370
    add_entity_type('WorkflowTransition')
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   371
    add_entity_type('SubWorkflowExitPoint')
3218
2a4bbe3fa4f3 [3.5 migration] avoid removing defined transitions...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2965
diff changeset
   372
    # drop explicit 'State allowed_transition Transition' since it should be
2a4bbe3fa4f3 [3.5 migration] avoid removing defined transitions...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2965
diff changeset
   373
    # infered due to yams inheritance.  However we've to disable the schema
2a4bbe3fa4f3 [3.5 migration] avoid removing defined transitions...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2965
diff changeset
   374
    # sync hook first to avoid to destroy existing data...
2a4bbe3fa4f3 [3.5 migration] avoid removing defined transitions...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2965
diff changeset
   375
    try:
3395
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   376
        from cubicweb.hooks import syncschema
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   377
        repo.vreg.unregister(syncschema.AfterDelRelationTypeHook)
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   378
        try:
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   379
            drop_relation_definition('State', 'allowed_transition', 'Transition')
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   380
        finally:
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   381
            repo.vreg.register(syncschema.AfterDelRelationTypeHook)
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   382
    except ImportError: # syncschema is in CW >= 3.6 only
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   383
        from cubicweb.server.schemahooks import after_del_relation_type
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   384
        repo.hm.unregister_hook(after_del_relation_type,
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   385
                                'after_delete_relation', 'relation_type')
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   386
        try:
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   387
            drop_relation_definition('State', 'allowed_transition', 'Transition')
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   388
        finally:
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   389
            repo.hm.register_hook(after_del_relation_type,
405f393bcac0 [migration] fix bootstrap migration of 3.5 : need to support old-style and new-style hooks to migrate from 3.4 to 3.6
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3369
diff changeset
   390
                                  'after_delete_relation', 'relation_type')
2965
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   391
    schema.rebuild_infered_relations() # need to be explicitly called once everything is in place
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   392
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   393
    for et in rql('DISTINCT Any ET,ETN WHERE S state_of ET, ET name ETN',
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   394
                  ask_confirm=False).entities():
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   395
        wf = add_workflow(u'default %s workflow' % et.name, et.name,
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   396
                          ask_confirm=False)
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   397
        rql('SET S state_of WF WHERE S state_of ET, ET eid %(et)s, WF eid %(wf)s',
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   398
            {'et': et.eid, 'wf': wf.eid}, 'et', ask_confirm=False)
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   399
        rql('SET T transition_of WF WHERE T transition_of ET, ET eid %(et)s, WF eid %(wf)s',
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   400
            {'et': et.eid, 'wf': wf.eid}, 'et', ask_confirm=False)
3305
abae9045d2e4 [migration] fix initial_state migration: at this point, S state_of ET is no more true (but we don't need it...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3218
diff changeset
   401
        rql('SET WF initial_state S WHERE ET initial_state S, ET eid %(et)s, WF eid %(wf)s',
2965
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   402
            {'et': et.eid, 'wf': wf.eid}, 'et', ask_confirm=False)
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   403
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   404
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   405
    rql('DELETE TrInfo TI WHERE NOT TI from_state S')
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   406
    rql('SET TI by_transition T WHERE TI from_state FS, TI to_state TS, '
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   407
        'FS allowed_transition T, T destination_state TS')
4042
f85a4c846aad 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4011
diff changeset
   408
    commit()
2965
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   409
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   410
    drop_relation_definition('State', 'state_of', 'CWEType')
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   411
    drop_relation_definition('Transition', 'transition_of', 'CWEType')
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   412
    drop_relation_definition('CWEType', 'initial_state', 'State')
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   413
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   414
    sync_schema_props_perms()
75ad5cb00b88 3.5 migration script
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2955
diff changeset
   415
1952
8e19c813750d fix extid handling: ensure encoded string is given, and store them as base64 (see note in native.py).
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1501
diff changeset
   416
if applcubicwebversion < (3, 2, 2) and cubicwebversion >= (3, 2, 1):
2462
9e670072884d fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2275
diff changeset
   417
    from base64 import b64encode
9450
af4b93bc38a5 [multi-sources-removal] Drop deleted_entities system table and entities.mtime column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9163
diff changeset
   418
    for eid, extid in sql('SELECT eid, extid FROM entities '
af4b93bc38a5 [multi-sources-removal] Drop deleted_entities system table and entities.mtime column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9163
diff changeset
   419
                          'WHERE extid is NOT NULL',
af4b93bc38a5 [multi-sources-removal] Drop deleted_entities system table and entities.mtime column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9163
diff changeset
   420
                          ask_confirm=False):
af4b93bc38a5 [multi-sources-removal] Drop deleted_entities system table and entities.mtime column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9163
diff changeset
   421
        sql('UPDATE entities SET extid=%(extid)s WHERE eid=%(eid)s',
af4b93bc38a5 [multi-sources-removal] Drop deleted_entities system table and entities.mtime column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9163
diff changeset
   422
            {'extid': b64encode(extid), 'eid': eid}, ask_confirm=False)
4042
f85a4c846aad 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4011
diff changeset
   423
    commit()
1952
8e19c813750d fix extid handling: ensure encoded string is given, and store them as base64 (see note in native.py).
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1501
diff changeset
   424
1501
c80ca83a382f migrate card cube in bootstrap migration
sylvain.thenault@logilab.fr
parents: 1399
diff changeset
   425
if applcubicwebversion < (3, 2, 0) and cubicwebversion >= (3, 2, 0):
2462
9e670072884d fix indentation problems in bootstrap_migration (use 4 spaces instead of 3)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2275
diff changeset
   426
    add_cube('card', update_database=False)
10015
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   427
11245
20b2e7ceecf6 [migration] move CWComputedRType later
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   428
if applcubicwebversion < (3, 20, 0) and cubicwebversion >= (3, 20, 0):
20b2e7ceecf6 [migration] move CWComputedRType later
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   429
    ss._IGNORED_PROPS.append('formula')
20b2e7ceecf6 [migration] move CWComputedRType later
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   430
    add_attribute('CWAttribute', 'formula', commit=False)
20b2e7ceecf6 [migration] move CWComputedRType later
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   431
    ss._IGNORED_PROPS.remove('formula')
20b2e7ceecf6 [migration] move CWComputedRType later
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   432
    commit()
20b2e7ceecf6 [migration] move CWComputedRType later
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   433
    add_entity_type('CWComputedRType')
20b2e7ceecf6 [migration] move CWComputedRType later
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   434
    commit()
20b2e7ceecf6 [migration] move CWComputedRType later
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   435
20b2e7ceecf6 [migration] move CWComputedRType later
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   436
if schema['TZDatetime'].eid is None:
20b2e7ceecf6 [migration] move CWComputedRType later
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   437
    add_entity_type('TZDatetime', auto=False)
20b2e7ceecf6 [migration] move CWComputedRType later
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   438
if schema['TZTime'].eid is None:
20b2e7ceecf6 [migration] move CWComputedRType later
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   439
    add_entity_type('TZTime', auto=False)
20b2e7ceecf6 [migration] move CWComputedRType later
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   440
10553
1d824df4f2bd Fix (de)serialization of ComputedRelation read permissions
Julien Cristau <julien.cristau@logilab.fr>
parents: 10301
diff changeset
   441
1d824df4f2bd Fix (de)serialization of ComputedRelation read permissions
Julien Cristau <julien.cristau@logilab.fr>
parents: 10301
diff changeset
   442
if applcubicwebversion < (3, 21, 1) and cubicwebversion >= (3, 21, 1):
1d824df4f2bd Fix (de)serialization of ComputedRelation read permissions
Julien Cristau <julien.cristau@logilab.fr>
parents: 10301
diff changeset
   443
    add_relation_definition('CWComputedRType', 'read_permission', 'CWGroup')
1d824df4f2bd Fix (de)serialization of ComputedRelation read permissions
Julien Cristau <julien.cristau@logilab.fr>
parents: 10301
diff changeset
   444
    add_relation_definition('CWComputedRType', 'read_permission', 'RQLExpression')
1d824df4f2bd Fix (de)serialization of ComputedRelation read permissions
Julien Cristau <julien.cristau@logilab.fr>
parents: 10301
diff changeset
   445
1d824df4f2bd Fix (de)serialization of ComputedRelation read permissions
Julien Cristau <julien.cristau@logilab.fr>
parents: 10301
diff changeset
   446
10015
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   447
def sync_constraint_types():
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   448
    """Make sure the repository knows about all constraint types defined in the code"""
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   449
    from cubicweb.schema import CONSTRAINTS
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   450
    repo_constraints = set(row[0] for row in rql('Any N WHERE X is CWConstraintType, X name N'))
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   451
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   452
    for cstrtype in set(CONSTRAINTS) - repo_constraints:
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   453
        if cstrtype == 'BoundConstraint':
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   454
            # was renamed to BoundaryConstraint, we don't need the old name
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   455
            continue
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   456
        rql('INSERT CWConstraintType X: X name %(name)s', {'name': cstrtype})
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   457
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   458
    commit()
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   459
57a16bef82c0 [migration] make sure the repo knows about all constraint types
Julien Cristau <julien.cristau@logilab.fr>
parents: 9708
diff changeset
   460
sync_constraint_types()