##// END OF EJS Templates
fixed Session problems in model class functions...
marcink -
r1081:70bf0be5 beta
parent child Browse files
Show More
@@ -1,325 +1,336
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-2011 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2009-2011 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 from datetime import date
29 from datetime import date
30
30
31 from sqlalchemy import *
31 from sqlalchemy import *
32 from sqlalchemy.exc import DatabaseError
32 from sqlalchemy.exc import DatabaseError
33 from sqlalchemy.orm import relationship, backref
33 from sqlalchemy.orm import relationship, backref
34 from sqlalchemy.orm.session import Session
34 from sqlalchemy.orm.interfaces import MapperExtension
35
35
36 from rhodecode.model.meta import Base
36 from rhodecode.model.meta import Base, Session
37
37
38 log = logging.getLogger(__name__)
38 log = logging.getLogger(__name__)
39
39
40 #==============================================================================
41 # MAPPER EXTENSIONS
42 #==============================================================================
43
44 class RepositoryMapper(MapperExtension):
45 def after_update(self, mapper, connection, instance):
46 pass
47
48
40 class RhodeCodeSettings(Base):
49 class RhodeCodeSettings(Base):
41 __tablename__ = 'rhodecode_settings'
50 __tablename__ = 'rhodecode_settings'
42 __table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True})
51 __table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True})
43 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
52 app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
44 app_settings_name = Column("app_settings_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
53 app_settings_name = Column("app_settings_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
45 app_settings_value = Column("app_settings_value", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
54 app_settings_value = Column("app_settings_value", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
46
55
47 def __init__(self, k='', v=''):
56 def __init__(self, k='', v=''):
48 self.app_settings_name = k
57 self.app_settings_name = k
49 self.app_settings_value = v
58 self.app_settings_value = v
50
59
51 def __repr__(self):
60 def __repr__(self):
52 return "<%s('%s:%s')>" % (self.__class__.__name__,
61 return "<%s('%s:%s')>" % (self.__class__.__name__,
53 self.app_settings_name, self.app_settings_value)
62 self.app_settings_name, self.app_settings_value)
54
63
55 class RhodeCodeUi(Base):
64 class RhodeCodeUi(Base):
56 __tablename__ = 'rhodecode_ui'
65 __tablename__ = 'rhodecode_ui'
57 __table_args__ = {'useexisting':True}
66 __table_args__ = {'useexisting':True}
58 ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
67 ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
59 ui_section = Column("ui_section", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
68 ui_section = Column("ui_section", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
60 ui_key = Column("ui_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
69 ui_key = Column("ui_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
61 ui_value = Column("ui_value", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
70 ui_value = Column("ui_value", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
62 ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True)
71 ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True)
63
72
64
73
65 class User(Base):
74 class User(Base):
66 __tablename__ = 'users'
75 __tablename__ = 'users'
67 __table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'useexisting':True})
76 __table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'useexisting':True})
68 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
77 user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
69 username = Column("username", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
78 username = Column("username", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
70 password = Column("password", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
79 password = Column("password", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
71 active = Column("active", Boolean(), nullable=True, unique=None, default=None)
80 active = Column("active", Boolean(), nullable=True, unique=None, default=None)
72 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
81 admin = Column("admin", Boolean(), nullable=True, unique=None, default=False)
73 name = Column("name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
82 name = Column("name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
74 lastname = Column("lastname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
83 lastname = Column("lastname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
75 email = Column("email", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
84 email = Column("email", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
76 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
85 last_login = Column("last_login", DateTime(timezone=False), nullable=True, unique=None, default=None)
77 ldap_dn = Column("ldap_dn", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
86 ldap_dn = Column("ldap_dn", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
78
87
79 user_log = relationship('UserLog', cascade='all')
88 user_log = relationship('UserLog', cascade='all')
80 user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
89 user_perms = relationship('UserToPerm', primaryjoin="User.user_id==UserToPerm.user_id", cascade='all')
81
90
82 repositories = relationship('Repository')
91 repositories = relationship('Repository')
83 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
92 user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
84
93
85 group_member = relationship('UsersGroupMember', cascade='all')
94 group_member = relationship('UsersGroupMember', cascade='all')
86
95
87 @property
96 @property
88 def full_contact(self):
97 def full_contact(self):
89 return '%s %s <%s>' % (self.name, self.lastname, self.email)
98 return '%s %s <%s>' % (self.name, self.lastname, self.email)
90
99
91 @property
100 @property
92 def is_admin(self):
101 def is_admin(self):
93 return self.admin
102 return self.admin
94
103
95 def __repr__(self):
104 def __repr__(self):
96 return "<%s('id:%s:%s')>" % (self.__class__.__name__,
105 return "<%s('id:%s:%s')>" % (self.__class__.__name__,
97 self.user_id, self.username)
106 self.user_id, self.username)
98
107
99 @classmethod
108 @classmethod
100 def by_username(cls, username):
109 def by_username(cls, username):
101 return Session.query(cls).filter(cls.username == username).one()
110 return Session.query(cls).filter(cls.username == username).one()
102
111
103
112
104 def update_lastlogin(self):
113 def update_lastlogin(self):
105 """Update user lastlogin"""
114 """Update user lastlogin"""
106
115
107 try:
116 try:
108 session = Session.object_session(self)
117 session = Session.object_session(self)
109 self.last_login = datetime.datetime.now()
118 self.last_login = datetime.datetime.now()
110 session.add(self)
119 session.add(self)
111 session.commit()
120 session.commit()
112 log.debug('updated user %s lastlogin', self.username)
121 log.debug('updated user %s lastlogin', self.username)
113 except (DatabaseError,):
122 except (DatabaseError,):
114 session.rollback()
123 session.rollback()
115
124
116
125
117 class UserLog(Base):
126 class UserLog(Base):
118 __tablename__ = 'user_logs'
127 __tablename__ = 'user_logs'
119 __table_args__ = {'useexisting':True}
128 __table_args__ = {'useexisting':True}
120 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
129 user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
121 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
130 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
122 repository_id = Column("repository_id", Integer(length=None, convert_unicode=False, assert_unicode=None), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
131 repository_id = Column("repository_id", Integer(length=None, convert_unicode=False, assert_unicode=None), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
123 repository_name = Column("repository_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
132 repository_name = Column("repository_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
124 user_ip = Column("user_ip", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
133 user_ip = Column("user_ip", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
125 action = Column("action", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
134 action = Column("action", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
126 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
135 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
127
136
128 @property
137 @property
129 def action_as_day(self):
138 def action_as_day(self):
130 return date(*self.action_date.timetuple()[:3])
139 return date(*self.action_date.timetuple()[:3])
131
140
132 user = relationship('User')
141 user = relationship('User')
133 repository = relationship('Repository')
142 repository = relationship('Repository')
134
143
135
144
136 class UsersGroup(Base):
145 class UsersGroup(Base):
137 __tablename__ = 'users_groups'
146 __tablename__ = 'users_groups'
138 __table_args__ = {'useexisting':True}
147 __table_args__ = {'useexisting':True}
139
148
140 users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
149 users_group_id = Column("users_group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
141 users_group_name = Column("users_group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
150 users_group_name = Column("users_group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
142 users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None)
151 users_group_active = Column("users_group_active", Boolean(), nullable=True, unique=None, default=None)
143
152
144 members = relationship('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
153 members = relationship('UsersGroupMember', cascade="all, delete, delete-orphan", lazy="joined")
145
154
146 class UsersGroupMember(Base):
155 class UsersGroupMember(Base):
147 __tablename__ = 'users_groups_members'
156 __tablename__ = 'users_groups_members'
148 __table_args__ = {'useexisting':True}
157 __table_args__ = {'useexisting':True}
149
158
150 users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
159 users_group_member_id = Column("users_group_member_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
151 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
160 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
152 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
161 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
153
162
154 user = relationship('User', lazy='joined')
163 user = relationship('User', lazy='joined')
155 users_group = relationship('UsersGroup')
164 users_group = relationship('UsersGroup')
156
165
157 def __init__(self, gr_id='', u_id=''):
166 def __init__(self, gr_id='', u_id=''):
158 self.users_group_id = gr_id
167 self.users_group_id = gr_id
159 self.user_id = u_id
168 self.user_id = u_id
160
169
161 class Repository(Base):
170 class Repository(Base):
162 __tablename__ = 'repositories'
171 __tablename__ = 'repositories'
163 __table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},)
172 __table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},)
173 __mapper_args__ = {'extension':RepositoryMapper()}
174
164 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
175 repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
165 repo_name = Column("repo_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
176 repo_name = Column("repo_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
166 repo_type = Column("repo_type", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg')
177 repo_type = Column("repo_type", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg')
167 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
178 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None)
168 private = Column("private", Boolean(), nullable=True, unique=None, default=None)
179 private = Column("private", Boolean(), nullable=True, unique=None, default=None)
169 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
180 enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True)
170 enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True)
181 enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True)
171 description = Column("description", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
182 description = Column("description", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
172 fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None)
183 fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None)
173 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None)
184 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None)
174
185
175 user = relationship('User')
186 user = relationship('User')
176 fork = relationship('Repository', remote_side=repo_id)
187 fork = relationship('Repository', remote_side=repo_id)
177 group = relationship('Group')
188 group = relationship('Group')
178 repo_to_perm = relationship('RepoToPerm', cascade='all', order_by='RepoToPerm.repo_to_perm_id')
189 repo_to_perm = relationship('RepoToPerm', cascade='all', order_by='RepoToPerm.repo_to_perm_id')
179 users_group_to_perm = relationship('UsersGroupToPerm', cascade='all')
190 users_group_to_perm = relationship('UsersGroupToPerm', cascade='all')
180 stats = relationship('Statistics', cascade='all', uselist=False)
191 stats = relationship('Statistics', cascade='all', uselist=False)
181
192
182 followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all')
193 followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all')
183
194
184 logs = relationship('UserLog', cascade='all')
195 logs = relationship('UserLog', cascade='all')
185
196
186 def __repr__(self):
197 def __repr__(self):
187 return "<%s('%s:%s')>" % (self.__class__.__name__,
198 return "<%s('%s:%s')>" % (self.__class__.__name__,
188 self.repo_id, self.repo_name)
199 self.repo_id, self.repo_name)
189
200
190 @classmethod
201 @classmethod
191 def by_repo_name(cls, repo_name):
202 def by_repo_name(cls, repo_name):
192 return Session.query(cls).filter(cls.repo_name == repo_name).one()
203 return Session.query(cls).filter(cls.repo_name == repo_name).one()
193
204
194
205
195 class Group(Base):
206 class Group(Base):
196 __tablename__ = 'groups'
207 __tablename__ = 'groups'
197 __table_args__ = (UniqueConstraint('group_name'), {'useexisting':True},)
208 __table_args__ = (UniqueConstraint('group_name'), {'useexisting':True},)
198
209
199 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
210 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
200 group_name = Column("group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
211 group_name = Column("group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
201 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
212 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
202
213
203 parent_group = relationship('Group', remote_side=group_id)
214 parent_group = relationship('Group', remote_side=group_id)
204
215
205
216
206 def __init__(self, group_name='', parent_group=None):
217 def __init__(self, group_name='', parent_group=None):
207 self.group_name = group_name
218 self.group_name = group_name
208 self.parent_group = parent_group
219 self.parent_group = parent_group
209
220
210 def __repr__(self):
221 def __repr__(self):
211 return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
222 return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
212 self.group_name)
223 self.group_name)
213
224
214 class Permission(Base):
225 class Permission(Base):
215 __tablename__ = 'permissions'
226 __tablename__ = 'permissions'
216 __table_args__ = {'useexisting':True}
227 __table_args__ = {'useexisting':True}
217 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
228 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
218 permission_name = Column("permission_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
229 permission_name = Column("permission_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
219 permission_longname = Column("permission_longname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
230 permission_longname = Column("permission_longname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
220
231
221 def __repr__(self):
232 def __repr__(self):
222 return "<%s('%s:%s')>" % (self.__class__.__name__,
233 return "<%s('%s:%s')>" % (self.__class__.__name__,
223 self.permission_id, self.permission_name)
234 self.permission_id, self.permission_name)
224
235
225 class RepoToPerm(Base):
236 class RepoToPerm(Base):
226 __tablename__ = 'repo_to_perm'
237 __tablename__ = 'repo_to_perm'
227 __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True})
238 __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True})
228 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
239 repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
229 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
240 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
230 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
241 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
231 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
242 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
232
243
233 user = relationship('User')
244 user = relationship('User')
234 permission = relationship('Permission')
245 permission = relationship('Permission')
235 repository = relationship('Repository')
246 repository = relationship('Repository')
236
247
237 class UserToPerm(Base):
248 class UserToPerm(Base):
238 __tablename__ = 'user_to_perm'
249 __tablename__ = 'user_to_perm'
239 __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True})
250 __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True})
240 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
251 user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
241 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
252 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
242 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
253 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
243
254
244 user = relationship('User')
255 user = relationship('User')
245 permission = relationship('Permission')
256 permission = relationship('Permission')
246
257
247
258
248 class UsersGroupToPerm(Base):
259 class UsersGroupToPerm(Base):
249 __tablename__ = 'users_group_to_perm'
260 __tablename__ = 'users_group_to_perm'
250 __table_args__ = (UniqueConstraint('users_group_id', 'permission_id'), {'useexisting':True})
261 __table_args__ = (UniqueConstraint('users_group_id', 'permission_id'), {'useexisting':True})
251 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
262 users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
252 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
263 users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
253 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
264 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
254 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
265 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
255
266
256 users_group = relationship('UsersGroup')
267 users_group = relationship('UsersGroup')
257 permission = relationship('Permission')
268 permission = relationship('Permission')
258 repository = relationship('Repository')
269 repository = relationship('Repository')
259
270
260 class GroupToPerm(Base):
271 class GroupToPerm(Base):
261 __tablename__ = 'group_to_perm'
272 __tablename__ = 'group_to_perm'
262 __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'useexisting':True})
273 __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'useexisting':True})
263
274
264 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
275 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
265 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
276 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
266 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
277 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
267 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
278 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
268
279
269 user = relationship('User')
280 user = relationship('User')
270 permission = relationship('Permission')
281 permission = relationship('Permission')
271 group = relationship('Group')
282 group = relationship('Group')
272
283
273 class Statistics(Base):
284 class Statistics(Base):
274 __tablename__ = 'statistics'
285 __tablename__ = 'statistics'
275 __table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True})
286 __table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True})
276 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
287 stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
277 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
288 repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None)
278 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
289 stat_on_revision = Column("stat_on_revision", Integer(), nullable=False)
279 commit_activity = Column("commit_activity", LargeBinary(), nullable=False)#JSON data
290 commit_activity = Column("commit_activity", LargeBinary(), nullable=False)#JSON data
280 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
291 commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data
281 languages = Column("languages", LargeBinary(), nullable=False)#JSON data
292 languages = Column("languages", LargeBinary(), nullable=False)#JSON data
282
293
283 repository = relationship('Repository', single_parent=True)
294 repository = relationship('Repository', single_parent=True)
284
295
285 class UserFollowing(Base):
296 class UserFollowing(Base):
286 __tablename__ = 'user_followings'
297 __tablename__ = 'user_followings'
287 __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'),
298 __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'),
288 UniqueConstraint('user_id', 'follows_user_id')
299 UniqueConstraint('user_id', 'follows_user_id')
289 , {'useexisting':True})
300 , {'useexisting':True})
290
301
291 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
302 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
292 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
303 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
293 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
304 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None)
294 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
305 follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None)
295
306
296 user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id')
307 user = relationship('User', primaryjoin='User.user_id==UserFollowing.user_id')
297
308
298 follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
309 follows_user = relationship('User', primaryjoin='User.user_id==UserFollowing.follows_user_id')
299 follows_repository = relationship('Repository', order_by='Repository.repo_name')
310 follows_repository = relationship('Repository', order_by='Repository.repo_name')
300
311
301 class CacheInvalidation(Base):
312 class CacheInvalidation(Base):
302 __tablename__ = 'cache_invalidation'
313 __tablename__ = 'cache_invalidation'
303 __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True})
314 __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True})
304 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
315 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
305 cache_key = Column("cache_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
316 cache_key = Column("cache_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
306 cache_args = Column("cache_args", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
317 cache_args = Column("cache_args", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
307 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
318 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False)
308
319
309
320
310 def __init__(self, cache_key, cache_args=''):
321 def __init__(self, cache_key, cache_args=''):
311 self.cache_key = cache_key
322 self.cache_key = cache_key
312 self.cache_args = cache_args
323 self.cache_args = cache_args
313 self.cache_active = False
324 self.cache_active = False
314
325
315 def __repr__(self):
326 def __repr__(self):
316 return "<%s('%s:%s')>" % (self.__class__.__name__,
327 return "<%s('%s:%s')>" % (self.__class__.__name__,
317 self.cache_id, self.cache_key)
328 self.cache_id, self.cache_key)
318
329
319 class DbMigrateVersion(Base):
330 class DbMigrateVersion(Base):
320 __tablename__ = 'db_migrate_version'
331 __tablename__ = 'db_migrate_version'
321 __table_args__ = {'useexisting':True}
332 __table_args__ = {'useexisting':True}
322 repository_id = Column('repository_id', String(250), primary_key=True)
333 repository_id = Column('repository_id', String(250), primary_key=True)
323 repository_path = Column('repository_path', Text)
334 repository_path = Column('repository_path', Text)
324 version = Column('version', Integer)
335 version = Column('version', Integer)
325
336
General Comments 0
You need to be logged in to leave comments. Login now