##// END OF EJS Templates
removed unicode from models string params
marcink -
r880:014071a7 beta
parent child Browse files
Show More
@@ -1,300 +1,293 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.model.db
3 rhodecode.model.db
4 ~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~
5
5
6 Database Models for RhodeCode
6 Database Models for RhodeCode
7
7
8 :created_on: Apr 08, 2010
8 :created_on: Apr 08, 2010
9 :author: marcink
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
11 :license: GPLv3, see COPYING for more details.
12 """
12 """
13 # This program is free software; you can redistribute it and/or
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; version 2
15 # as published by the Free Software Foundation; version 2
16 # of the License or (at your opinion) any later version of the license.
16 # of the License or (at your opinion) any later version of the license.
17 #
17 #
18 # This program is distributed in the hope that it will be useful,
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
21 # GNU General Public License for more details.
22 #
22 #
23 # You should have received a copy of the GNU General Public License
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 # MA 02110-1301, USA.
26 # MA 02110-1301, USA.
27 import logging
27 import logging
28 import datetime
28 import datetime
29
29
30 from sqlalchemy import *
30 from sqlalchemy import *
31 from sqlalchemy.exc import DatabaseError
31 from sqlalchemy.exc import DatabaseError
32 from sqlalchemy.orm import relation, backref, class_mapper
32 from sqlalchemy.orm import relation, backref, class_mapper
33 from sqlalchemy.orm.session import Session
33 from sqlalchemy.orm.session import Session
34
34
35 from rhodecode.model.meta import Base
35 from rhodecode.model.meta import Base
36
36
37 log = logging.getLogger(__name__)
37 log = logging.getLogger(__name__)
38
38
39 class BaseModel(object):
39 class BaseModel(object):
40
40
41 @classmethod
41 @classmethod
42 def _get_keys(cls):
42 def _get_keys(cls):
43 """return column names for this model """
43 """return column names for this model """
44 return class_mapper(cls).c.keys()
44 return class_mapper(cls).c.keys()
45
45
46 def get_dict(self):
46 def get_dict(self):
47 """return dict with keys and values corresponding
47 """return dict with keys and values corresponding
48 to this model data """
48 to this model data """
49
49
50 d = {}
50 d = {}
51 for k in self._get_keys():
51 for k in self._get_keys():
52 d[k] = getattr(self, k)
52 d[k] = getattr(self, k)
53 return d
53 return d
54
54
55 def get_appstruct(self):
55 def get_appstruct(self):
56 """return list with keys and values tupples corresponding
56 """return list with keys and values tupples corresponding
57 to this model data """
57 to this model data """
58
58
59 l = []
59 l = []
60 for k in self._get_keys():
60 for k in self._get_keys():
61 l.append((k, getattr(self, k),))
61 l.append((k, getattr(self, k),))
62 return l
62 return l
63
63
64 def populate_obj(self, populate_dict):
64 def populate_obj(self, populate_dict):
65 """populate model with data from given populate_dict"""
65 """populate model with data from given populate_dict"""
66
66
67 for k in self._get_keys():
67 for k in self._get_keys():
68 if k in populate_dict:
68 if k in populate_dict:
69 setattr(self, k, populate_dict[k])
69 setattr(self, k, populate_dict[k])
70
70
71 class RhodeCodeSettings(Base, BaseModel):
71 class RhodeCodeSettings(Base, BaseModel):
72 __tablename__ = 'rhodecode_settings'
72 __tablename__ = 'rhodecode_settings'
73 __table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True})
73 __table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True})
74 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
74 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
75 app_settings_name = Column("app_settings_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
75 app_settings_name = Column("app_settings_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
76 app_settings_value = Column("app_settings_value", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
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 self.app_settings_name = k
79 self.app_settings_name = k
80 self.app_settings_value = v
80 self.app_settings_value = v
81
81
82 def __repr__(self):
82 def __repr__(self):
83 return "<%s('%s:%s')>" % (self.__class__.__name__,
83 return "<%s('%s:%s')>" % (self.__class__.__name__,
84 self.app_settings_name, self.app_settings_value)
84 self.app_settings_name, self.app_settings_value)
85
85
86 class RhodeCodeUi(Base, BaseModel):
86 class RhodeCodeUi(Base, BaseModel):
87 __tablename__ = 'rhodecode_ui'
87 __tablename__ = 'rhodecode_ui'
88 __table_args__ = {'useexisting':True}
88 __table_args__ = {'useexisting':True}
89 ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
89 ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
90 ui_section = Column("ui_section", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
90 ui_section = Column("ui_section", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
91 ui_key = Column("ui_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
91 ui_key = Column("ui_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92 ui_value = Column("ui_value", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
92 ui_value = Column("ui_value", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
93 ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True)
93 ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True)
94
94
95
95
96 class User(Base, BaseModel):
96 class User(Base, BaseModel):
97 __tablename__ = 'users'
97 __tablename__ = 'users'
98 __table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'useexisting':True})
98 __table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'useexisting':True})
99 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
99 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
100 username = Column("username", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
100 username = Column("username", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
101 password = Column("password", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
101 password = Column("password", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
102 active = Column("active", Boolean(), nullable=True, unique=None, default=None)
102 active = Column("active", Boolean(), nullable=True, unique=None, default=None)
103 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
103 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
104 name = Column("name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
104 name = Column("name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
105 lastname = Column("lastname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
105 lastname = Column("lastname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
106 email = Column("email", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
106 email = Column("email", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
107 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
107 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
108 is_ldap = Column("is_ldap", Boolean(), nullable=False, unique=None, default=False)
108 is_ldap = Column("is_ldap", Boolean(), nullable=False, unique=None, default=False)
109
109
110 user_log = relation('UserLog', cascade='all')
110 user_log = relation('UserLog', cascade='all')
111 user_perms = relation('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
111 user_perms = relation('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
112
112
113 repositories = relation('Repository')
113 repositories = relation('Repository')
114 user_followers = relation('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
114 user_followers = relation('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
115
115
116 @property
116 @property
117 def full_contact(self):
117 def full_contact(self):
118 return '%s %s <%s>' % (self.name, self.lastname, self.email)
118 return '%s %s <%s>' % (self.name, self.lastname, self.email)
119
119
120 def __repr__(self):
120 def __repr__(self):
121 return "<%s('id:%s:%s')>" % (self.__class__.__name__,
121 return "<%s('id:%s:%s')>" % (self.__class__.__name__,
122 self.user_id, self.username)
122 self.user_id, self.username)
123
123
124 def update_lastlogin(self):
124 def update_lastlogin(self):
125 """Update user lastlogin"""
125 """Update user lastlogin"""
126
126
127 try:
127 try:
128 session = Session.object_session(self)
128 session = Session.object_session(self)
129 self.last_login = datetime.datetime.now()
129 self.last_login = datetime.datetime.now()
130 session.add(self)
130 session.add(self)
131 session.commit()
131 session.commit()
132 log.debug('updated user %s lastlogin', self.username)
132 log.debug('updated user %s lastlogin', self.username)
133 except (DatabaseError,):
133 except (DatabaseError,):
134 session.rollback()
134 session.rollback()
135
135
136
136
137 class UserLog(Base, BaseModel):
137 class UserLog(Base, BaseModel):
138 __tablename__ = 'user_logs'
138 __tablename__ = 'user_logs'
139 __table_args__ = {'useexisting':True}
139 __table_args__ = {'useexisting':True}
140 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
140 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
141 user_id = Column("user_id", Integer(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None)
141 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
142 repository_id = Column("repository_id", Integer(length=None, convert_unicode=False, assert_unicode=None), ForeignKey(u'repositories.repo_id'), nullable=False, unique=None, default=None)
142 repository_id = Column("repository_id", Integer(length=None, convert_unicode=False, assert_unicode=None), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
143 repository_name = Column("repository_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
143 repository_name = Column("repository_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
144 user_ip = Column("user_ip", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
144 user_ip = Column("user_ip", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
145 action = Column("action", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
145 action = Column("action", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
146 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
146 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
147
147
148 user = relation('User')
148 user = relation('User')
149 repository = relation('Repository')
149 repository = relation('Repository')
150
150
151 class Repository(Base, BaseModel):
151 class Repository(Base, BaseModel):
152 __tablename__ = 'repositories'
152 __tablename__ = 'repositories'
153 __table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},)
153 __table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},)
154 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
154 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
155 repo_name = Column("repo_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
155 repo_name = Column("repo_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
156 repo_type = Column("repo_type", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg')
156 repo_type = Column("repo_type", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg')
157 user_id = Column("user_id", Integer(), ForeignKey(u'users.user_id'), nullable=False, unique=False, default=None)
157 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
158 private = Column("private", Boolean(), nullable=True, unique=None, default=None)
158 private = Column("private", Boolean(), nullable=True, unique=None, default=None)
159 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
159 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
160 description = Column("description", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
160 description = Column("description", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
161 fork_id = Column("fork_id", Integer(), ForeignKey(u'repositories.repo_id'), nullable=True, unique=False, default=None)
161 fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None)
162 group_id = Column("group_id", Integer(), ForeignKey(u'groups.group_id'), nullable=True, unique=False, default=None)
162 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None)
163
163
164 user = relation('User')
164 user = relation('User')
165 fork = relation('Repository', remote_side=repo_id)
165 fork = relation('Repository', remote_side=repo_id)
166 group = relation('Group')
166 group = relation('Group')
167 repo_to_perm = relation('RepoToPerm', cascade='all')
167 repo_to_perm = relation('RepoToPerm', cascade='all')
168 stats = relation('Statistics', cascade='all', uselist=False)
168 stats = relation('Statistics', cascade='all', uselist=False)
169
169
170 repo_followers = relation('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all')
170 repo_followers = relation('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all')
171
171
172
173 def __repr__(self):
172 def __repr__(self):
174 return "<%s('%s:%s')>" % (self.__class__.__name__,
173 return "<%s('%s:%s')>" % (self.__class__.__name__,
175 self.repo_id, self.repo_name)
174 self.repo_id, self.repo_name)
176
175
177 class Group(Base, BaseModel):
176 class Group(Base, BaseModel):
178 __tablename__ = 'groups'
177 __tablename__ = 'groups'
179 __table_args__ = (UniqueConstraint('group_name'), {'useexisting':True},)
178 __table_args__ = (UniqueConstraint('group_name'), {'useexisting':True},)
180
179
181 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
180 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
182 group_name = Column("group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
181 group_name = Column("group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
183 group_parent_id = Column("group_parent_id", Integer(), ForeignKey(u'groups.group_id'), nullable=True, unique=None, default=None)
182 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
184
183
185 parent_group = relation('Group', remote_side=group_id)
184 parent_group = relation('Group', remote_side=group_id)
186
185
187
186
188 def __init__(self, group_name='', parent_group=None):
187 def __init__(self, group_name='', parent_group=None):
189 self.group_name = group_name
188 self.group_name = group_name
190 self.parent_group = parent_group
189 self.parent_group = parent_group
191
190
192 def __repr__(self):
191 def __repr__(self):
193 return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
192 return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
194 self.group_name)
193 self.group_name)
195
194
196 class Permission(Base, BaseModel):
195 class Permission(Base, BaseModel):
197 __tablename__ = 'permissions'
196 __tablename__ = 'permissions'
198 __table_args__ = {'useexisting':True}
197 __table_args__ = {'useexisting':True}
199 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
198 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
200 permission_name = Column("permission_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
199 permission_name = Column("permission_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
201 permission_longname = Column("permission_longname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
200 permission_longname = Column("permission_longname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
202
201
203 def __repr__(self):
202 def __repr__(self):
204 return "<%s('%s:%s')>" % (self.__class__.__name__,
203 return "<%s('%s:%s')>" % (self.__class__.__name__,
205 self.permission_id, self.permission_name)
204 self.permission_id, self.permission_name)
206
205
207 class RepoToPerm(Base, BaseModel):
206 class RepoToPerm(Base, BaseModel):
208 __tablename__ = 'repo_to_perm'
207 __tablename__ = 'repo_to_perm'
209 __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True})
208 __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True})
210 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
209 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
211 user_id = Column("user_id", Integer(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None)
210 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
212 permission_id = Column("permission_id", Integer(), ForeignKey(u'permissions.permission_id'), nullable=False, unique=None, default=None)
211 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
213 repository_id = Column("repository_id", Integer(), ForeignKey(u'repositories.repo_id'), nullable=False, unique=None, default=None)
212 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
214
213
215 user = relation('User')
214 user = relation('User')
216 permission = relation('Permission')
215 permission = relation('Permission')
217 repository = relation('Repository')
216 repository = relation('Repository')
218
217
219 class UserToPerm(Base, BaseModel):
218 class UserToPerm(Base, BaseModel):
220 __tablename__ = 'user_to_perm'
219 __tablename__ = 'user_to_perm'
221 __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True})
220 __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True})
222 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
221 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
223 user_id = Column("user_id", Integer(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None)
222 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
224 permission_id = Column("permission_id", Integer(), ForeignKey(u'permissions.permission_id'), nullable=False, unique=None, default=None)
223 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
225
224
226 user = relation('User')
225 user = relation('User')
227 permission = relation('Permission')
226 permission = relation('Permission')
228
227
229 class GroupToPerm(Base, BaseModel):
228 class GroupToPerm(Base, BaseModel):
230 __tablename__ = 'group_to_perm'
229 __tablename__ = 'group_to_perm'
231 __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'useexisting':True})
230 __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'useexisting':True})
232
231
233 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
232 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
234 user_id = Column("user_id", Integer(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None)
233 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
235 permission_id = Column("permission_id", Integer(), ForeignKey(u'permissions.permission_id'), nullable=False, unique=None, default=None)
234 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
236 group_id = Column("group_id", Integer(), ForeignKey(u'groups.group_id'), nullable=False, unique=None, default=None)
235 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
237
236
238 user = relation('User')
237 user = relation('User')
239 permission = relation('Permission')
238 permission = relation('Permission')
240 group = relation('Group')
239 group = relation('Group')
241
240
242
243
244
245
246
247 class Statistics(Base, BaseModel):
241 class Statistics(Base, BaseModel):
248 __tablename__ = 'statistics'
242 __tablename__ = 'statistics'
249 __table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True})
243 __table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True})
250 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
244 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
251 repository_id = Column("repository_id", Integer(), ForeignKey(u'repositories.repo_id'), nullable=False, unique=True, default=None)
245 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
252 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
246 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
253 commit_activity = Column("commit_activity", LargeBinary(), nullable=False)#JSON data
247 commit_activity = Column("commit_activity", LargeBinary(), nullable=False)#JSON data
254 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
248 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
255 languages = Column("languages", LargeBinary(), nullable=False)#JSON data
249 languages = Column("languages", LargeBinary(), nullable=False)#JSON data
256
250
257 repository = relation('Repository', single_parent=True)
251 repository = relation('Repository', single_parent=True)
258
252
259 class UserFollowing(Base, BaseModel):
253 class UserFollowing(Base, BaseModel):
260 __tablename__ = 'user_followings'
254 __tablename__ = 'user_followings'
261 __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'),
255 __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'),
262 UniqueConstraint('user_id', 'follows_user_id')
256 UniqueConstraint('user_id', 'follows_user_id')
263 , {'useexisting':True})
257 , {'useexisting':True})
264
258
265 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
259 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
266 user_id = Column("user_id", Integer(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None)
260 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
267 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey(u'repositories.repo_id'), nullable=True, unique=None, default=None)
261 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
268 follows_user_id = Column("follows_user_id", Integer(), ForeignKey(u'users.user_id'), nullable=True, unique=None, default=None)
262 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
269
263
270 user = relation('User', primaryjoin='User.user_id==UserFollowing.user_id')
264 user = relation('User', primaryjoin='User.user_id==UserFollowing.user_id')
271
265
272 follows_user = relation('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
266 follows_user = relation('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
273 follows_repository = relation('Repository')
267 follows_repository = relation('Repository')
274
268
275
276 class CacheInvalidation(Base, BaseModel):
269 class CacheInvalidation(Base, BaseModel):
277 __tablename__ = 'cache_invalidation'
270 __tablename__ = 'cache_invalidation'
278 __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True})
271 __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True})
279 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
272 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
280 cache_key = Column("cache_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
273 cache_key = Column("cache_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
281 cache_args = Column("cache_args", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
274 cache_args = Column("cache_args", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
282 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
275 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
283
276
284
277
285 def __init__(self, cache_key, cache_args=''):
278 def __init__(self, cache_key, cache_args=''):
286 self.cache_key = cache_key
279 self.cache_key = cache_key
287 self.cache_args = cache_args
280 self.cache_args = cache_args
288 self.cache_active = False
281 self.cache_active = False
289
282
290 def __repr__(self):
283 def __repr__(self):
291 return "<%s('%s:%s')>" % (self.__class__.__name__,
284 return "<%s('%s:%s')>" % (self.__class__.__name__,
292 self.cache_id, self.cache_key)
285 self.cache_id, self.cache_key)
293
286
294 class DbMigrateVersion(Base, BaseModel):
287 class DbMigrateVersion(Base, BaseModel):
295 __tablename__ = 'db_migrate_version'
288 __tablename__ = 'db_migrate_version'
296 __table_args__ = {'useexisting':True}
289 __table_args__ = {'useexisting':True}
297 repository_id = Column('repository_id', String(250), primary_key=True)
290 repository_id = Column('repository_id', String(250), primary_key=True)
298 repository_path = Column('repository_path', Text)
291 repository_path = Column('repository_path', Text)
299 version = Column('version', Integer)
292 version = Column('version', Integer)
300
293
General Comments 0
You need to be logged in to leave comments. Login now