##// END OF EJS Templates
migration: change prints to logging
marcink -
r1543:4acfe019 default
parent child Browse files
Show More
@@ -1,45 +1,45 b''
1 import logging
1 import logging
2 import datetime
2 import datetime
3
3
4 from sqlalchemy import *
4 from sqlalchemy import *
5 from sqlalchemy.exc import DatabaseError
5 from sqlalchemy.exc import DatabaseError
6 from sqlalchemy.orm import relation, backref, class_mapper, joinedload
6 from sqlalchemy.orm import relation, backref, class_mapper, joinedload
7 from sqlalchemy.orm.session import Session
7 from sqlalchemy.orm.session import Session
8 from sqlalchemy.ext.declarative import declarative_base
8 from sqlalchemy.ext.declarative import declarative_base
9
9
10 from rhodecode.lib.dbmigrate.migrate import *
10 from rhodecode.lib.dbmigrate.migrate import *
11 from rhodecode.lib.dbmigrate.migrate.changeset import *
11 from rhodecode.lib.dbmigrate.migrate.changeset import *
12 from rhodecode.lib.utils2 import str2bool
12 from rhodecode.lib.utils2 import str2bool
13
13
14 from rhodecode.model.meta import Base
14 from rhodecode.model.meta import Base
15 from rhodecode.model import meta
15 from rhodecode.model import meta
16 from rhodecode.lib.dbmigrate.versions import _reset_base, notify
16 from rhodecode.lib.dbmigrate.versions import _reset_base, notify
17
17
18 log = logging.getLogger(__name__)
18 log = logging.getLogger(__name__)
19
19
20
20
21 def upgrade(migrate_engine):
21 def upgrade(migrate_engine):
22 """
22 """
23 Upgrade operations go here.
23 Upgrade operations go here.
24 Don't create your own engine; bind migrate_engine to your metadata
24 Don't create your own engine; bind migrate_engine to your metadata
25 """
25 """
26 _reset_base(migrate_engine)
26 _reset_base(migrate_engine)
27 from rhodecode.lib.dbmigrate.schema import db_2_2_3
27 from rhodecode.lib.dbmigrate.schema import db_2_2_3
28
28
29 # issue fixups
29 # issue fixups
30 fixups(db_2_2_3, meta.Session)
30 fixups(db_2_2_3, meta.Session)
31
31
32
32
33 def downgrade(migrate_engine):
33 def downgrade(migrate_engine):
34 meta = MetaData()
34 meta = MetaData()
35 meta.bind = migrate_engine
35 meta.bind = migrate_engine
36
36
37
37
38 def fixups(models, _SESSION):
38 def fixups(models, _SESSION):
39 notify('Creating repository states')
39 notify('Creating repository states')
40 _state = models.Repository.STATE_CREATED
40 _state = models.Repository.STATE_CREATED
41 for repo in models.Repository.get_all():
41 for repo in models.Repository.get_all():
42 print 'setting repo %s state to "%s"' % (repo, _state)
42 log.info('setting repo %s state to "%s"', repo, _state)
43 repo.repo_state = _state
43 repo.repo_state = _state
44 _SESSION().add(repo)
44 _SESSION().add(repo)
45 _SESSION().commit()
45 _SESSION().commit()
@@ -1,45 +1,45 b''
1 import logging
1 import logging
2 import datetime
2 import datetime
3
3
4 from sqlalchemy import *
4 from sqlalchemy import *
5 from sqlalchemy.exc import DatabaseError
5 from sqlalchemy.exc import DatabaseError
6 from sqlalchemy.orm import relation, backref, class_mapper, joinedload
6 from sqlalchemy.orm import relation, backref, class_mapper, joinedload
7 from sqlalchemy.orm.session import Session
7 from sqlalchemy.orm.session import Session
8 from sqlalchemy.ext.declarative import declarative_base
8 from sqlalchemy.ext.declarative import declarative_base
9
9
10 from rhodecode.lib.dbmigrate.migrate import *
10 from rhodecode.lib.dbmigrate.migrate import *
11 from rhodecode.lib.dbmigrate.migrate.changeset import *
11 from rhodecode.lib.dbmigrate.migrate.changeset import *
12 from rhodecode.lib.utils2 import str2bool
12 from rhodecode.lib.utils2 import str2bool
13
13
14 from rhodecode.model.meta import Base
14 from rhodecode.model.meta import Base
15 from rhodecode.model import meta
15 from rhodecode.model import meta
16 from rhodecode.lib.dbmigrate.versions import _reset_base, notify
16 from rhodecode.lib.dbmigrate.versions import _reset_base, notify
17
17
18 log = logging.getLogger(__name__)
18 log = logging.getLogger(__name__)
19
19
20
20
21 def upgrade(migrate_engine):
21 def upgrade(migrate_engine):
22 """
22 """
23 Upgrade operations go here.
23 Upgrade operations go here.
24 Don't create your own engine; bind migrate_engine to your metadata
24 Don't create your own engine; bind migrate_engine to your metadata
25 """
25 """
26 _reset_base(migrate_engine)
26 _reset_base(migrate_engine)
27 from rhodecode.lib.dbmigrate.schema import db_2_3_0_0
27 from rhodecode.lib.dbmigrate.schema import db_2_3_0_0
28
28
29 # issue fixups
29 # issue fixups
30 fixups(db_2_3_0_0, meta.Session)
30 fixups(db_2_3_0_0, meta.Session)
31
31
32
32
33 def downgrade(migrate_engine):
33 def downgrade(migrate_engine):
34 meta = MetaData()
34 meta = MetaData()
35 meta.bind = migrate_engine
35 meta.bind = migrate_engine
36
36
37
37
38 def fixups(models, _SESSION):
38 def fixups(models, _SESSION):
39 notify('Fixing auth tokens roles')
39 notify('Fixing auth tokens roles')
40 _role = models.UserApiKeys.ROLE_ALL
40 _role = models.UserApiKeys.ROLE_ALL
41 for token in models.UserApiKeys.get_all():
41 for token in models.UserApiKeys.get_all():
42 print 'setting key %s role to "%s"' % (token, _role)
42 log.info('setting key %s role to "%s"', token, _role)
43 token.role = _role
43 token.role = _role
44 _SESSION().add(token)
44 _SESSION().add(token)
45 _SESSION().commit()
45 _SESSION().commit()
@@ -1,47 +1,47 b''
1 import logging
1 import logging
2 import datetime
2 import datetime
3
3
4 from sqlalchemy import *
4 from sqlalchemy import *
5 from sqlalchemy.exc import DatabaseError
5 from sqlalchemy.exc import DatabaseError
6 from sqlalchemy.orm import relation, backref, class_mapper, joinedload
6 from sqlalchemy.orm import relation, backref, class_mapper, joinedload
7 from sqlalchemy.orm.session import Session
7 from sqlalchemy.orm.session import Session
8 from sqlalchemy.ext.declarative import declarative_base
8 from sqlalchemy.ext.declarative import declarative_base
9
9
10 from rhodecode.lib.dbmigrate.migrate import *
10 from rhodecode.lib.dbmigrate.migrate import *
11 from rhodecode.lib.dbmigrate.migrate.changeset import *
11 from rhodecode.lib.dbmigrate.migrate.changeset import *
12 from rhodecode.lib.utils2 import str2bool
12 from rhodecode.lib.utils2 import str2bool
13
13
14 from rhodecode.model.meta import Base
14 from rhodecode.model.meta import Base
15 from rhodecode.model import meta
15 from rhodecode.model import meta
16 from rhodecode.lib.dbmigrate.versions import _reset_base, notify
16 from rhodecode.lib.dbmigrate.versions import _reset_base, notify
17
17
18 log = logging.getLogger(__name__)
18 log = logging.getLogger(__name__)
19
19
20
20
21 def upgrade(migrate_engine):
21 def upgrade(migrate_engine):
22 """
22 """
23 Upgrade operations go here.
23 Upgrade operations go here.
24 Don't create your own engine; bind migrate_engine to your metadata
24 Don't create your own engine; bind migrate_engine to your metadata
25 """
25 """
26 _reset_base(migrate_engine)
26 _reset_base(migrate_engine)
27 from rhodecode.lib.dbmigrate.schema import db_3_0_0_0
27 from rhodecode.lib.dbmigrate.schema import db_3_0_0_0
28
28
29 # issue fixups
29 # issue fixups
30 fixups(db_3_0_0_0, meta.Session)
30 fixups(db_3_0_0_0, meta.Session)
31
31
32
32
33 def downgrade(migrate_engine):
33 def downgrade(migrate_engine):
34 meta = MetaData()
34 meta = MetaData()
35 meta.bind = migrate_engine
35 meta.bind = migrate_engine
36
36
37
37
38 def fixups(models, _SESSION):
38 def fixups(models, _SESSION):
39 # ** create default permissions ** #
39 # ** create default permissions ** #
40 from rhodecode.model.permission import PermissionModel
40 from rhodecode.model.permission import PermissionModel
41 PermissionModel(_SESSION()).create_permissions()
41 PermissionModel(_SESSION()).create_permissions()
42 _SESSION().commit()
42 _SESSION().commit()
43
43
44 res = PermissionModel(_SESSION()).create_default_user_permissions(
44 res = PermissionModel(_SESSION()).create_default_user_permissions(
45 models.User.DEFAULT_USER)
45 models.User.DEFAULT_USER)
46 print res
46 log.info('created default permission %s', res)
47 _SESSION().commit()
47 _SESSION().commit()
@@ -1,37 +1,37 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 import logging
3 import logging
4
4
5 from sqlalchemy.orm.attributes import flag_modified
5 from sqlalchemy.orm.attributes import flag_modified
6
6
7 from rhodecode.lib.dbmigrate.versions import _reset_base
7 from rhodecode.lib.dbmigrate.versions import _reset_base
8 from rhodecode.model import init_model_encryption, meta
8 from rhodecode.model import init_model_encryption, meta
9
9
10 log = logging.getLogger(__name__)
10 log = logging.getLogger(__name__)
11
11
12
12
13 def upgrade(migrate_engine):
13 def upgrade(migrate_engine):
14 """
14 """
15 Upgrade operations go here.
15 Upgrade operations go here.
16 Don't create your own engine; bind migrate_engine to your metadata
16 Don't create your own engine; bind migrate_engine to your metadata
17 """
17 """
18 _reset_base(migrate_engine)
18 _reset_base(migrate_engine)
19 from rhodecode.lib.dbmigrate.schema import db_3_7_0_0
19 from rhodecode.lib.dbmigrate.schema import db_3_7_0_0
20 init_model_encryption(db_3_7_0_0)
20 init_model_encryption(db_3_7_0_0)
21 fixups(db_3_7_0_0, meta.Session)
21 fixups(db_3_7_0_0, meta.Session)
22
22
23
23
24 def downgrade(migrate_engine):
24 def downgrade(migrate_engine):
25 pass
25 pass
26
26
27
27
28 def fixups(models, Session):
28 def fixups(models, Session):
29 for repo in models.Repository.get_all():
29 for repo in models.Repository.get_all():
30 if repo.clone_uri:
30 if repo.clone_uri:
31 print 'Encrypting clone uri in repo %s' % repo
31 log.info('Encrypting clone uri in repo %s', repo)
32 flag_modified(repo, 'clone_uri')
32 flag_modified(repo, 'clone_uri')
33 Session().add(repo)
33 Session().add(repo)
34
34
35 Session().commit()
35 Session().commit()
36
36
37
37
General Comments 0
You need to be logged in to leave comments. Login now