|
@@
-1,7
+1,7
|
|
1
|
# -*- coding: utf-8 -*-
|
|
1
|
# -*- coding: utf-8 -*-
|
|
2
|
"""
|
|
2
|
"""
|
|
3
|
package.rhodecode.model.db
|
|
3
|
rhodecode.model.db
|
|
4
|
~~~~~~~~~~~~~~
|
|
4
|
~~~~~~~~~~~~~~~~~~
|
|
5
|
|
|
5
|
|
|
6
|
Database Models for RhodeCode
|
|
6
|
Database Models for RhodeCode
|
|
7
|
:created_on: Apr 08, 2010
|
|
7
|
:created_on: Apr 08, 2010
|
|
@@
-28,14
+28,46
import datetime
|
|
28
|
|
|
28
|
|
|
29
|
from sqlalchemy import *
|
|
29
|
from sqlalchemy import *
|
|
30
|
from sqlalchemy.exc import DatabaseError
|
|
30
|
from sqlalchemy.exc import DatabaseError
|
|
31
|
from sqlalchemy.orm import relation, backref
|
|
31
|
from sqlalchemy.orm import relation, backref, class_mapper
|
|
32
|
from sqlalchemy.orm.session import Session
|
|
32
|
from sqlalchemy.orm.session import Session
|
|
33
|
|
|
33
|
|
|
34
|
from rhodecode.model.meta import Base
|
|
34
|
from rhodecode.model.meta import Base
|
|
35
|
|
|
35
|
|
|
36
|
log = logging.getLogger(__name__)
|
|
36
|
log = logging.getLogger(__name__)
|
|
37
|
|
|
37
|
|
|
38
|
class RhodeCodeSettings(Base):
|
|
38
|
class BaseModel(object):
|
|
|
|
|
39
|
|
|
|
|
|
40
|
@classmethod
|
|
|
|
|
41
|
def _get_keys(cls):
|
|
|
|
|
42
|
"""return column names for this model """
|
|
|
|
|
43
|
return class_mapper(cls).c.keys()
|
|
|
|
|
44
|
|
|
|
|
|
45
|
def get_dict(self):
|
|
|
|
|
46
|
"""return dict with keys and values corresponding
|
|
|
|
|
47
|
to this model data """
|
|
|
|
|
48
|
|
|
|
|
|
49
|
d = {}
|
|
|
|
|
50
|
for k in self._get_keys():
|
|
|
|
|
51
|
d[k] = getattr(self, k)
|
|
|
|
|
52
|
return d
|
|
|
|
|
53
|
|
|
|
|
|
54
|
def get_appstruct(self):
|
|
|
|
|
55
|
"""return list with keys and values tupples corresponding
|
|
|
|
|
56
|
to this model data """
|
|
|
|
|
57
|
|
|
|
|
|
58
|
l = []
|
|
|
|
|
59
|
for k in self._get_keys():
|
|
|
|
|
60
|
l.append((k, getattr(self, k),))
|
|
|
|
|
61
|
return l
|
|
|
|
|
62
|
|
|
|
|
|
63
|
def populate_obj(self, populate_dict):
|
|
|
|
|
64
|
"""populate model with data from given populate_dict"""
|
|
|
|
|
65
|
|
|
|
|
|
66
|
for k in self._get_keys():
|
|
|
|
|
67
|
if k in populate_dict:
|
|
|
|
|
68
|
setattr(self, k, populate_dict[k])
|
|
|
|
|
69
|
|
|
|
|
|
70
|
class RhodeCodeSettings(Base, BaseModel):
|
|
39
|
__tablename__ = 'rhodecode_settings'
|
|
71
|
__tablename__ = 'rhodecode_settings'
|
|
40
|
__table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True})
|
|
72
|
__table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True})
|
|
41
|
app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
73
|
app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
@@
-50,7
+82,7
class RhodeCodeSettings(Base):
|
|
50
|
return "<RhodeCodeSetting('%s:%s')>" % (self.app_settings_name,
|
|
82
|
return "<RhodeCodeSetting('%s:%s')>" % (self.app_settings_name,
|
|
51
|
self.app_settings_value)
|
|
83
|
self.app_settings_value)
|
|
52
|
|
|
84
|
|
|
53
|
class RhodeCodeUi(Base):
|
|
85
|
class RhodeCodeUi(Base, BaseModel):
|
|
54
|
__tablename__ = 'rhodecode_ui'
|
|
86
|
__tablename__ = 'rhodecode_ui'
|
|
55
|
__table_args__ = {'useexisting':True}
|
|
87
|
__table_args__ = {'useexisting':True}
|
|
56
|
ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
88
|
ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
@@
-60,7
+92,7
class RhodeCodeUi(Base):
|
|
60
|
ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True)
|
|
92
|
ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True)
|
|
61
|
|
|
93
|
|
|
62
|
|
|
94
|
|
|
63
|
class User(Base):
|
|
95
|
class User(Base, BaseModel):
|
|
64
|
__tablename__ = 'users'
|
|
96
|
__tablename__ = 'users'
|
|
65
|
__table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'useexisting':True})
|
|
97
|
__table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'useexisting':True})
|
|
66
|
user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
98
|
user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
@@
-100,7
+132,7
class User(Base):
|
|
100
|
session.rollback()
|
|
132
|
session.rollback()
|
|
101
|
|
|
133
|
|
|
102
|
|
|
134
|
|
|
103
|
class UserLog(Base):
|
|
135
|
class UserLog(Base, BaseModel):
|
|
104
|
__tablename__ = 'user_logs'
|
|
136
|
__tablename__ = 'user_logs'
|
|
105
|
__table_args__ = {'useexisting':True}
|
|
137
|
__table_args__ = {'useexisting':True}
|
|
106
|
user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
138
|
user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
@@
-114,7
+146,7
class UserLog(Base):
|
|
114
|
user = relation('User')
|
|
146
|
user = relation('User')
|
|
115
|
repository = relation('Repository')
|
|
147
|
repository = relation('Repository')
|
|
116
|
|
|
148
|
|
|
117
|
class Repository(Base):
|
|
149
|
class Repository(Base, BaseModel):
|
|
118
|
__tablename__ = 'repositories'
|
|
150
|
__tablename__ = 'repositories'
|
|
119
|
__table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},)
|
|
151
|
__table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},)
|
|
120
|
repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
152
|
repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
@@
-137,7
+169,7
class Repository(Base):
|
|
137
|
def __repr__(self):
|
|
169
|
def __repr__(self):
|
|
138
|
return "<Repository('%s:%s')>" % (self.repo_id, self.repo_name)
|
|
170
|
return "<Repository('%s:%s')>" % (self.repo_id, self.repo_name)
|
|
139
|
|
|
171
|
|
|
140
|
class Permission(Base):
|
|
172
|
class Permission(Base, BaseModel):
|
|
141
|
__tablename__ = 'permissions'
|
|
173
|
__tablename__ = 'permissions'
|
|
142
|
__table_args__ = {'useexisting':True}
|
|
174
|
__table_args__ = {'useexisting':True}
|
|
143
|
permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
175
|
permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
@@
-147,7
+179,7
class Permission(Base):
|
|
147
|
def __repr__(self):
|
|
179
|
def __repr__(self):
|
|
148
|
return "<Permission('%s:%s')>" % (self.permission_id, self.permission_name)
|
|
180
|
return "<Permission('%s:%s')>" % (self.permission_id, self.permission_name)
|
|
149
|
|
|
181
|
|
|
150
|
class RepoToPerm(Base):
|
|
182
|
class RepoToPerm(Base, BaseModel):
|
|
151
|
__tablename__ = 'repo_to_perm'
|
|
183
|
__tablename__ = 'repo_to_perm'
|
|
152
|
__table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True})
|
|
184
|
__table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True})
|
|
153
|
repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
185
|
repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
@@
-159,7
+191,7
class RepoToPerm(Base):
|
|
159
|
permission = relation('Permission')
|
|
191
|
permission = relation('Permission')
|
|
160
|
repository = relation('Repository')
|
|
192
|
repository = relation('Repository')
|
|
161
|
|
|
193
|
|
|
162
|
class UserToPerm(Base):
|
|
194
|
class UserToPerm(Base, BaseModel):
|
|
163
|
__tablename__ = 'user_to_perm'
|
|
195
|
__tablename__ = 'user_to_perm'
|
|
164
|
__table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True})
|
|
196
|
__table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True})
|
|
165
|
user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
197
|
user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
@@
-169,7
+201,7
class UserToPerm(Base):
|
|
169
|
user = relation('User')
|
|
201
|
user = relation('User')
|
|
170
|
permission = relation('Permission')
|
|
202
|
permission = relation('Permission')
|
|
171
|
|
|
203
|
|
|
172
|
class Statistics(Base):
|
|
204
|
class Statistics(Base, BaseModel):
|
|
173
|
__tablename__ = 'statistics'
|
|
205
|
__tablename__ = 'statistics'
|
|
174
|
__table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True})
|
|
206
|
__table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True})
|
|
175
|
stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
207
|
stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
@@
-181,7
+213,7
class Statistics(Base):
|
|
181
|
|
|
213
|
|
|
182
|
repository = relation('Repository', single_parent=True)
|
|
214
|
repository = relation('Repository', single_parent=True)
|
|
183
|
|
|
215
|
|
|
184
|
class UserFollowing(Base):
|
|
216
|
class UserFollowing(Base, BaseModel):
|
|
185
|
__tablename__ = 'user_followings'
|
|
217
|
__tablename__ = 'user_followings'
|
|
186
|
__table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'),
|
|
218
|
__table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'),
|
|
187
|
UniqueConstraint('user_id', 'follows_user_id')
|
|
219
|
UniqueConstraint('user_id', 'follows_user_id')
|
|
@@
-198,7
+230,7
class UserFollowing(Base):
|
|
198
|
follows_repository = relation('Repository')
|
|
230
|
follows_repository = relation('Repository')
|
|
199
|
|
|
231
|
|
|
200
|
|
|
232
|
|
|
201
|
class CacheInvalidation(Base):
|
|
233
|
class CacheInvalidation(Base, BaseModel):
|
|
202
|
__tablename__ = 'cache_invalidation'
|
|
234
|
__tablename__ = 'cache_invalidation'
|
|
203
|
__table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True})
|
|
235
|
__table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True})
|
|
204
|
cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|
|
236
|
cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
|