90 msg = 'enter login and password of the initial manager account' |
90 msg = 'enter login and password of the initial manager account' |
91 login, pwd = manager_userpasswd(msg=msg, confirm=True) |
91 login, pwd = manager_userpasswd(msg=msg, confirm=True) |
92 else: |
92 else: |
93 login, pwd = unicode(source['db-user']), source['db-password'] |
93 login, pwd = unicode(source['db-user']), source['db-password'] |
94 print '-> inserting default user and default groups.' |
94 print '-> inserting default user and default groups.' |
95 needisfix = [] |
|
96 for group in BASE_GROUPS: |
95 for group in BASE_GROUPS: |
97 rset = session.execute('INSERT CWGroup X: X name %(name)s', |
96 rset = session.execute('INSERT CWGroup X: X name %(name)s', |
98 {'name': unicode(group)}) |
97 {'name': unicode(group)}) |
99 needisfix.append( (rset.rows[0][0], rset.description[0][0]) ) |
|
100 rset = session.execute('INSERT CWUser X: X login %(login)s, X upassword %(pwd)s', |
98 rset = session.execute('INSERT CWUser X: X login %(login)s, X upassword %(pwd)s', |
101 {'login': login, 'pwd': pwd}) |
99 {'login': login, 'pwd': pwd}) |
102 needisfix.append( (rset.rows[0][0], rset.description[0][0]) ) |
|
103 session.execute('SET U in_group G WHERE G name "managers"') |
100 session.execute('SET U in_group G WHERE G name "managers"') |
104 session.commit() |
101 session.commit() |
105 # reloging using the admin user |
102 # reloging using the admin user |
106 config._cubes = None # avoid assertion error |
103 config._cubes = None # avoid assertion error |
107 repo, cnx = in_memory_cnx(config, login, pwd) |
104 repo, cnx = in_memory_cnx(config, login, pwd) |
108 assert len(repo.sources) == 1, repo.sources |
105 assert len(repo.sources) == 1, repo.sources |
109 handler = config.migration_handler(schema, interactive=False, |
106 handler = config.migration_handler(schema, interactive=False, |
110 cnx=cnx, repo=repo) |
107 cnx=cnx, repo=repo) |
111 initialize_schema(config, schema, handler) |
108 initialize_schema(config, schema, handler) |
112 # admin user and groups have been added before schema entities, fix the 'is' |
|
113 # relation |
|
114 for eid, etype in needisfix: |
|
115 handler.session.unsafe_execute('SET X is E WHERE X eid %(x)s, E name %(name)s', |
|
116 {'x': eid, 'name': etype}, 'x') |
|
117 handler.session.unsafe_execute('SET X is_instance_of E WHERE X eid %(x)s, E name %(name)s', |
|
118 {'x': eid, 'name': etype}, 'x') |
|
119 # insert versions |
109 # insert versions |
120 handler.cmd_add_entity('CWProperty', pkey=u'system.version.cubicweb', |
110 handler.cmd_add_entity('CWProperty', pkey=u'system.version.cubicweb', |
121 value=unicode(config.cubicweb_version())) |
111 value=unicode(config.cubicweb_version())) |
122 for cube in config.cubes(): |
112 for cube in config.cubes(): |
123 handler.cmd_add_entity('CWProperty', |
113 handler.cmd_add_entity('CWProperty', |
124 pkey=u'system.version.%s' % cube.lower(), |
114 pkey=u'system.version.%s' % cube.lower(), |
125 value=unicode(config.cube_version(cube))) |
115 value=unicode(config.cube_version(cube))) |
|
116 # some entities have been added before schema entities, fix the 'is' and |
|
117 # 'is_instance_of' relations |
|
118 for rtype in ('is', 'is_instance_of'): |
|
119 handler.sqlexec( |
|
120 'INSERT INTO %s_relation ' |
|
121 'SELECT X.eid, ET.cw_eid FROM entities as X, cw_CWEType as ET ' |
|
122 'WHERE X.type=ET.cw_name AND NOT EXISTS(' |
|
123 ' SELECT 1 from is_relation ' |
|
124 ' WHERE eid_from=X.eid AND eid_to=ET.cw_eid)' % rtype) |
126 # yoo ! |
125 # yoo ! |
127 cnx.commit() |
126 cnx.commit() |
128 config.enabled_sources = None |
127 config.enabled_sources = None |
129 for uri, source_config in config.sources().items(): |
128 for uri, source_config in config.sources().items(): |
130 if uri in ('admin', 'system'): |
129 if uri in ('admin', 'system'): |