##// END OF EJS Templates
dbmigrations:...
marcink -
r836:28a4bb11 beta
parent child Browse files
Show More
@@ -29,7 +29,7 b''
29 29
30 30 VERSION = (1, 1, 0, 'beta')
31 31 __version__ = '.'.join((str(each) for each in VERSION[:4]))
32 __dbversion__ = 1 #defines current db version for migrations
32 __dbversion__ = 2 #defines current db version for migrations
33 33
34 34 from rhodecode.lib.utils import get_current_revision
35 35 _rev = get_current_revision()
@@ -28,6 +28,8 b''
28 28 import logging
29 29 from sqlalchemy import engine_from_config
30 30
31 from rhodecode import __dbversion__
32 from rhodecode.lib.dbmigrate.migrate.versioning import api
31 33 from rhodecode.lib.dbmigrate.migrate.exceptions import \
32 34 DatabaseNotControlledError
33 35 from rhodecode.lib.utils import BasePasterCommand, Command, add_cache
@@ -49,25 +51,32 b' class UpgradeDb(BasePasterCommand):'
49 51
50 52 def command(self):
51 53 from pylons import config
54
52 55 add_cache(config)
53 #engine = engine_from_config(config, 'sqlalchemy.db1.')
54 #rint engine
55 56
56 from rhodecode.lib.dbmigrate.migrate.versioning import api
57 path = 'rhodecode/lib/dbmigrate'
57 #engine = engine_from_config(config, 'sqlalchemy.db1.')
58 58
59 repository_path = 'rhodecode/lib/dbmigrate'
60 db_uri = config['sqlalchemy.db1.url']
59 61
60 62 try:
61 curr_version = api.db_version(config['sqlalchemy.db1.url'], path)
63 curr_version = api.db_version(db_uri, repository_path)
62 64 msg = ('Found current database under version'
63 65 ' control with version %s' % curr_version)
64 66
65 67 except (RuntimeError, DatabaseNotControlledError), e:
66 curr_version = 0
68 curr_version = 1
67 69 msg = ('Current database is not under version control setting'
68 70 ' as version %s' % curr_version)
71 api.version_control(db_uri, repository_path, curr_version)
72
69 73
70 74 print msg
75 #now we have our dbversion we can do upgrade
76
77 msg = 'attempting to do database upgrade to version %s' % __dbversion__
78 print msg
79 api.upgrade(db_uri, repository_path, __dbversion__)
71 80
72 81 def update_parser(self):
73 82 self.parser.add_option('--sql',
@@ -119,7 +119,7 b' def alter_column(*p, **k):'
119 119
120 120
121 121 """
122
122
123 123 k.setdefault('alter_metadata', DEFAULT_ALTER_METADATA)
124 124
125 125 if 'table' not in k and isinstance(p[0], sqlalchemy.Column):
@@ -367,7 +367,7 b' class ColumnDelta(DictMixin, sqlalchemy.'
367 367 for_update=True))
368 368 if toinit:
369 369 column._init_items(*toinit)
370
370
371 371 if not SQLA_06:
372 372 column.args = []
373 373
@@ -573,12 +573,12 b' populated with defaults'
573 573
574 574 def _col_name_in_constraint(self, cons, name):
575 575 return False
576
576
577 577 def remove_from_table(self, table, unset_table=True):
578 578 # TODO: remove primary keys, constraints, etc
579 579 if unset_table:
580 580 self.table = None
581
581
582 582 to_drop = set()
583 583 for index in table.indexes:
584 584 columns = []
@@ -590,7 +590,7 b' populated with defaults'
590 590 else:
591 591 to_drop.add(index)
592 592 table.indexes = table.indexes - to_drop
593
593
594 594 to_drop = set()
595 595 for cons in table.constraints:
596 596 # TODO: deal with other types of constraint
@@ -602,7 +602,7 b' populated with defaults'
602 602 if self.name == col_name:
603 603 to_drop.add(cons)
604 604 table.constraints = table.constraints - to_drop
605
605
606 606 if table.c.contains_column(self):
607 607 table.c.remove(self)
608 608
@@ -30,8 +30,8 b' import inspect'
30 30 import logging
31 31
32 32 from rhodecode.lib.dbmigrate.migrate import exceptions
33 from rhodecode.lib.dbmigrate.migrate.versioning import (repository, schema, version,
34 script as script_) # command name conflict
33 from rhodecode.lib.dbmigrate.migrate.versioning import repository, schema, version, \
34 script as script_ # command name conflict
35 35 from rhodecode.lib.dbmigrate.migrate.versioning.util import catch_known_errors, with_engine
36 36
37 37
@@ -18,7 +18,6 b' class SqlScript(base.BaseScript):'
18 18
19 19 :returns: :class:`SqlScript instance <migrate.versioning.script.sql.SqlScript>`"""
20 20 cls.require_notfound(path)
21
22 21 src = Template(opts.pop('templates_path', None)).get_sql_script(theme=opts.pop('templates_theme', None))
23 22 shutil.copy(src, path)
24 23 return cls(path)
@@ -37,7 +37,7 b' class Template(pathed.Pathed):'
37 37 :param path: Templates are loaded from rhodecode.lib.dbmigrate.migrate package
38 38 if `path` is not provided.
39 39 """
40 pkg = 'migrate.versioning.templates'
40 pkg = 'rhodecode.lib.dbmigrate.migrate.versioning.templates'
41 41 _manage = 'manage.py_tmpl'
42 42
43 43 def __new__(cls, path=None):
@@ -80,7 +80,7 b' class Template(pathed.Pathed):'
80 80 def get_repository(self, *a, **kw):
81 81 """Calls self._get_item('repository', *a, **kw)"""
82 82 return self._get_item('repository', *a, **kw)
83
83
84 84 def get_script(self, *a, **kw):
85 85 """Calls self._get_item('script', *a, **kw)"""
86 86 return self._get_item('script', *a, **kw)
@@ -1,5 +1,3 b''
1 from migrate import *
2
3 1 #==============================================================================
4 2 # DB INITIAL MODEL
5 3 #==============================================================================
@@ -10,8 +8,9 b' from sqlalchemy import *'
10 8 from sqlalchemy.exc import DatabaseError
11 9 from sqlalchemy.orm import relation, backref, class_mapper
12 10 from sqlalchemy.orm.session import Session
11 from rhodecode.model.meta import Base
13 12
14 from rhodecode.model.meta import Base
13 from rhodecode.lib.dbmigrate.migrate import *
15 14
16 15 log = logging.getLogger(__name__)
17 16
@@ -1,9 +1,16 b''
1 from sqlalchemy import *
2 from sqlalchemy.orm import relation
1 import logging
2 import datetime
3 3
4 from migrate import *
5 from migrate.changeset import *
6 from rhodecode.model.meta import Base, BaseModel
4 from sqlalchemy import *
5 from sqlalchemy.exc import DatabaseError
6 from sqlalchemy.orm import relation, backref, class_mapper
7 from sqlalchemy.orm.session import Session
8 from rhodecode.model.meta import Base
9 from rhodecode.model.db import BaseModel
10
11 from rhodecode.lib.dbmigrate.migrate import *
12
13 log = logging.getLogger(__name__)
7 14
8 15 def upgrade(migrate_engine):
9 16 """ Upgrade operations go here.
@@ -18,10 +25,10 b' def upgrade(migrate_engine):'
18 25 autoload_with=migrate_engine)
19 26
20 27 #ADD is_ldap column
21 is_ldap = Column("is_ldap", Boolean(), nullable=False,
28 is_ldap = Column("is_ldap", Boolean(), nullable=True,
22 29 unique=None, default=False)
23 is_ldap.create(tbl)
24
30 is_ldap.create(tbl, populate_default=True)
31 is_ldap.alter(nullable=False)
25 32
26 33 #==========================================================================
27 34 # Upgrade of `user_logs` table
@@ -49,9 +56,10 b' def upgrade(migrate_engine):'
49 56 #ADD repo_type column
50 57 repo_type = Column("repo_type", String(length=None, convert_unicode=False,
51 58 assert_unicode=None),
52 nullable=False, unique=False, default=None)
53 repo_type.create(tbl)
59 nullable=True, unique=False, default='hg')
54 60
61 repo_type.create(tbl, populate_default=True)
62 repo_type.alter(nullable=False)
55 63
56 64 #ADD statistics column
57 65 enable_statistics = Column("statistics", Boolean(), nullable=True,
@@ -64,6 +72,7 b' def upgrade(migrate_engine):'
64 72 # Add table `user_followings`
65 73 #==========================================================================
66 74 tblname = 'user_followings'
75
67 76 class UserFollowing(Base, BaseModel):
68 77 __tablename__ = 'user_followings'
69 78 __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'),
@@ -85,6 +94,8 b' def upgrade(migrate_engine):'
85 94 #==========================================================================
86 95 # Add table `cache_invalidation`
87 96 #==========================================================================
97 tblname = 'cache_invalidation'
98
88 99 class CacheInvalidation(Base, BaseModel):
89 100 __tablename__ = 'cache_invalidation'
90 101 __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True})
@@ -152,7 +152,7 b' class Repository(Base, BaseModel):'
152 152 __table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},)
153 153 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
154 154 repo_name = Column("repo_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
155 repo_type = Column("repo_type", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default=None)
155 repo_type = Column("repo_type", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg')
156 156 user_id = Column("user_id", Integer(), ForeignKey(u'users.user_id'), nullable=False, unique=False, default=None)
157 157 private = Column("private", Boolean(), nullable=True, unique=None, default=None)
158 158 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
General Comments 0
You need to be logged in to leave comments. Login now