##// END OF EJS Templates
Fixed dbmigrate issues.
marcink -
r907:2f83756f beta
parent child Browse files
Show More
@@ -51,10 +51,14 b' class DbManage(object):'
51 51 self.tests = tests
52 52 self.root = root
53 53 self.dburi = dbconf
54 engine = create_engine(self.dburi, echo=log_sql)
54 self.log_sql = log_sql
55 self.db_exists = False
56 self.init_db()
57
58 def init_db(self):
59 engine = create_engine(self.dburi, echo=self.log_sql)
55 60 init_model(engine)
56 61 self.sa = meta.Session()
57 self.db_exists = False
58 62
59 63 def check_for_db(self, override):
60 64 db_path = jn(self.root, self.dbname)
@@ -222,6 +226,7 b' class DbManage(object):'
222 226 """
223 227
224 228 hgsettings3 = RhodeCodeSettings('ga_code', '')
229
225 230 try:
226 231 self.sa.add(hgsettings3)
227 232 self.sa.commit()
@@ -9,6 +9,7 b' from rhodecode.model.meta import Base'
9 9 from rhodecode.model.db import BaseModel
10 10
11 11 from rhodecode.lib.dbmigrate.migrate import *
12 from rhodecode.lib.dbmigrate.migrate.changeset import *
12 13
13 14 log = logging.getLogger(__name__)
14 15
@@ -69,57 +70,17 b' def upgrade(migrate_engine):'
69 70 #==========================================================================
70 71 # Add table `user_followings`
71 72 #==========================================================================
72 tblname = 'user_followings'
73
74 class UserFollowing(Base, BaseModel):
75 __tablename__ = 'user_followings'
76 __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'),
77 UniqueConstraint('user_id', 'follows_user_id')
78 , {'useexisting':True})
79
80 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
81 user_id = Column("user_id", Integer(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None)
82 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey(u'repositories.repo_id'), nullable=True, unique=None, default=None)
83 follows_user_id = Column("follows_user_id", Integer(), ForeignKey(u'users.user_id'), nullable=True, unique=None, default=None)
84
85 user = relation('User', primaryjoin='User.user_id==UserFollowing.user_id')
86
87 follows_user = relation('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
88 follows_repository = relation('Repository')
89
90 Base.metadata.tables[tblname].create(migrate_engine)
73 from rhodecode.model.db import UserFollowing
74 UserFollowing().__table__.create()
91 75
92 76 #==========================================================================
93 77 # Add table `cache_invalidation`
94 78 #==========================================================================
95 tblname = 'cache_invalidation'
96
97 class CacheInvalidation(Base, BaseModel):
98 __tablename__ = 'cache_invalidation'
99 __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True})
100 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
101 cache_key = Column("cache_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
102 cache_args = Column("cache_args", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
103 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
104
105
106 def __init__(self, cache_key, cache_args=''):
107 self.cache_key = cache_key
108 self.cache_args = cache_args
109 self.cache_active = False
110
111 def __repr__(self):
112 return "<CacheInvalidation('%s:%s')>" % (self.cache_id, self.cache_key)
113
114 Base.metadata.tables[tblname].create(migrate_engine)
79 from rhodecode.model.db import CacheInvalidation
80 CacheInvalidation().__table__.create()
115 81
116 82 return
117 83
118
119
120
121
122
123 84 def downgrade(migrate_engine):
124 85 meta = MetaData()
125 86 meta.bind = migrate_engine
@@ -5,11 +5,14 b' from sqlalchemy import *'
5 5 from sqlalchemy.exc import DatabaseError
6 6 from sqlalchemy.orm import relation, backref, class_mapper
7 7 from sqlalchemy.orm.session import Session
8
9
10 from rhodecode.lib.dbmigrate.migrate import *
11 from rhodecode.lib.dbmigrate.migrate.changeset import *
12
8 13 from rhodecode.model.meta import Base
9 14 from rhodecode.model.db import BaseModel
10 15
11 from rhodecode.lib.dbmigrate.migrate import *
12
13 16 log = logging.getLogger(__name__)
14 17
15 18 def upgrade(migrate_engine):
@@ -20,48 +23,14 b' def upgrade(migrate_engine):'
20 23 #==========================================================================
21 24 # Add table `groups``
22 25 #==========================================================================
23 tblname = 'groups'
24
25 class Group(Base, BaseModel):
26 __tablename__ = 'groups'
27 __table_args__ = (UniqueConstraint('group_name'), {'useexisting':True},)
28
29 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
30 group_name = Column("group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
31 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
32
33 parent_group = relation('Group', remote_side=group_id)
34
35
36 def __init__(self, group_name='', parent_group=None):
37 self.group_name = group_name
38 self.parent_group = parent_group
39
40 def __repr__(self):
41 return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
42 self.group_name)
43
44 Base.metadata.tables[tblname].create(migrate_engine)
26 from rhodecode.model.db import Group
27 Group().__table__.create()
45 28
46 29 #==========================================================================
47 30 # Add table `group_to_perm`
48 31 #==========================================================================
49 tblname = 'group_to_perm'
50
51 class GroupToPerm(Base, BaseModel):
52 __tablename__ = 'group_to_perm'
53 __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'useexisting':True})
54
55 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
56 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
57 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
58 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
59
60 user = relation('User')
61 permission = relation('Permission')
62 group = relation('Group')
63
64 Base.metadata.tables[tblname].create(migrate_engine)
32 from rhodecode.model.db import GroupToPerm
33 GroupToPerm().__table__.create()
65 34
66 35 #==========================================================================
67 36 # Upgrade of `repositories` table
@@ -71,12 +40,15 b' def upgrade(migrate_engine):'
71 40 autoload_with=migrate_engine)
72 41
73 42 #ADD group_id column#
74 group_id = Column("group_id", Integer(), ForeignKey(u'groups.group_id'),
43 group_id = Column("group_id", Integer(), #ForeignKey('groups.group_id'),
75 44 nullable=True, unique=False, default=None)
76 45
77 group_id.create(tbl, populate_default=True)
46 group_id.create(tbl)
78 47
79
48 # TODO: fix this somehow ?!
49 # cons = ForeignKeyConstraint([tbl.c.group_id], ['groups.group_id'], table=tbl)
50 #
51 # cons.create()
80 52 return
81 53
82 54
@@ -75,7 +75,7 b' class RhodeCodeSettings(Base, BaseModel)'
75 75 app_settings_name = Column("app_settings_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
76 76 app_settings_value = Column("app_settings_value", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
77 77
78 def __init__(self, k, v):
78 def __init__(self, k='', v=''):
79 79 self.app_settings_name = k
80 80 self.app_settings_value = v
81 81
General Comments 0
You need to be logged in to leave comments. Login now