Show More
@@ -1,321 +1,331 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-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 |
|
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 |
|
120 | |||
121 | @property |
|
121 | @property | |
122 | def is_admin(self): |
|
122 | def is_admin(self): | |
123 | return self.admin |
|
123 | return self.admin | |
124 |
|
124 | |||
125 | def __repr__(self): |
|
125 | def __repr__(self): | |
126 | return "<%s('id:%s:%s')>" % (self.__class__.__name__, |
|
126 | return "<%s('id:%s:%s')>" % (self.__class__.__name__, | |
127 | self.user_id, self.username) |
|
127 | self.user_id, self.username) | |
128 |
|
128 | |||
129 | def update_lastlogin(self): |
|
129 | def update_lastlogin(self): | |
130 | """Update user lastlogin""" |
|
130 | """Update user lastlogin""" | |
131 |
|
131 | |||
132 | try: |
|
132 | try: | |
133 | session = Session.object_session(self) |
|
133 | session = Session.object_session(self) | |
134 | self.last_login = datetime.datetime.now() |
|
134 | self.last_login = datetime.datetime.now() | |
135 | session.add(self) |
|
135 | session.add(self) | |
136 | session.commit() |
|
136 | session.commit() | |
137 | log.debug('updated user %s lastlogin', self.username) |
|
137 | log.debug('updated user %s lastlogin', self.username) | |
138 | except (DatabaseError,): |
|
138 | except (DatabaseError,): | |
139 | session.rollback() |
|
139 | session.rollback() | |
140 |
|
140 | |||
141 |
|
141 | |||
142 | class UserLog(Base, BaseModel): |
|
142 | class UserLog(Base, BaseModel): | |
143 | __tablename__ = 'user_logs' |
|
143 | __tablename__ = 'user_logs' | |
144 | __table_args__ = {'useexisting':True} |
|
144 | __table_args__ = {'useexisting':True} | |
145 | user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
145 | user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
146 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
|
146 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) | |
147 | repository_id = Column("repository_id", Integer(length=None, convert_unicode=False, assert_unicode=None), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) |
|
147 | repository_id = Column("repository_id", Integer(length=None, convert_unicode=False, assert_unicode=None), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) | |
148 | repository_name = Column("repository_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
148 | repository_name = Column("repository_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
149 | user_ip = Column("user_ip", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
149 | user_ip = Column("user_ip", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
150 | action = Column("action", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
150 | action = Column("action", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
151 | action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None) |
|
151 | action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None) | |
152 |
|
152 | |||
153 | user = relation('User') |
|
153 | user = relation('User') | |
154 | repository = relation('Repository') |
|
154 | repository = relation('Repository') | |
155 |
|
155 | |||
156 |
|
156 | |||
157 | class UsersGroup(Base, BaseModel): |
|
157 | class UsersGroup(Base, BaseModel): | |
158 | __tablename__ = 'users_groups' |
|
158 | __tablename__ = 'users_groups' | |
159 | __table_args__ = {'useexisting':True} |
|
159 | __table_args__ = {'useexisting':True} | |
160 |
|
160 | |||
161 | user_group_id = Column("users_groups_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
161 | user_group_id = Column("users_groups_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
162 | user_group_name = Column("user_group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
|
162 | user_group_name = Column("user_group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) | |
163 |
|
163 | |||
164 |
|
164 | |||
165 | members = relation('UsersGroupMember') |
|
165 | members = relation('UsersGroupMember') | |
166 |
|
166 | |||
167 |
|
167 | |||
168 | class UsersGroupMember(Base, BaseModel): |
|
168 | class UsersGroupMember(Base, BaseModel): | |
169 | __tablename__ = 'users_groups_members' |
|
169 | __tablename__ = 'users_groups_members' | |
170 | __table_args__ = {'useexisting':True} |
|
170 | __table_args__ = {'useexisting':True} | |
171 |
|
171 | |||
172 | user_groups_members_id = Column("user_groups_members_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
172 | user_groups_members_id = Column("user_groups_members_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
173 | user_group_id = Column("user_group_id", Integer(), ForeignKey('users_groups.users_groups_id'), nullable=False, unique=None, default=None) |
|
173 | user_group_id = Column("user_group_id", Integer(), ForeignKey('users_groups.users_groups_id'), nullable=False, unique=None, default=None) | |
174 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
|
174 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) | |
175 |
|
175 | |||
176 | user = relation('User') |
|
176 | user = relation('User') | |
177 | users_group = relation('UsersGroup') |
|
177 | users_group = relation('UsersGroup') | |
178 |
|
178 | |||
179 | class Repository(Base, BaseModel): |
|
179 | class Repository(Base, BaseModel): | |
180 | __tablename__ = 'repositories' |
|
180 | __tablename__ = 'repositories' | |
181 | __table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},) |
|
181 | __table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},) | |
182 | repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
182 | repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
183 | repo_name = Column("repo_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
|
183 | repo_name = Column("repo_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) | |
184 | repo_type = Column("repo_type", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg') |
|
184 | repo_type = Column("repo_type", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=False, default='hg') | |
185 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None) |
|
185 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=False, default=None) | |
186 | private = Column("private", Boolean(), nullable=True, unique=None, default=None) |
|
186 | private = Column("private", Boolean(), nullable=True, unique=None, default=None) | |
187 | enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True) |
|
187 | enable_statistics = Column("statistics", Boolean(), nullable=True, unique=None, default=True) | |
188 | description = Column("description", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
188 | description = Column("description", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
189 | fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None) |
|
189 | fork_id = Column("fork_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=False, default=None) | |
190 | group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None) |
|
190 | group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=False, default=None) | |
191 |
|
191 | |||
192 | user = relation('User') |
|
192 | user = relation('User') | |
193 | fork = relation('Repository', remote_side=repo_id) |
|
193 | fork = relation('Repository', remote_side=repo_id) | |
194 | group = relation('Group') |
|
194 | group = relation('Group') | |
195 | repo_to_perm = relation('RepoToPerm', cascade='all') |
|
195 | repo_to_perm = relation('RepoToPerm', cascade='all') | |
196 | stats = relation('Statistics', cascade='all', uselist=False) |
|
196 | stats = relation('Statistics', cascade='all', uselist=False) | |
197 |
|
197 | |||
198 | repo_followers = relation('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all') |
|
198 | repo_followers = relation('UserFollowing', primaryjoin='UserFollowing.follows_repo_id==Repository.repo_id', cascade='all') | |
199 |
|
199 | |||
200 | def __repr__(self): |
|
200 | def __repr__(self): | |
201 | return "<%s('%s:%s')>" % (self.__class__.__name__, |
|
201 | return "<%s('%s:%s')>" % (self.__class__.__name__, | |
202 | self.repo_id, self.repo_name) |
|
202 | self.repo_id, self.repo_name) | |
203 |
|
203 | |||
204 | class Group(Base, BaseModel): |
|
204 | class Group(Base, BaseModel): | |
205 | __tablename__ = 'groups' |
|
205 | __tablename__ = 'groups' | |
206 | __table_args__ = (UniqueConstraint('group_name'), {'useexisting':True},) |
|
206 | __table_args__ = (UniqueConstraint('group_name'), {'useexisting':True},) | |
207 |
|
207 | |||
208 | group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
208 | group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
209 | group_name = Column("group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
|
209 | group_name = Column("group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) | |
210 | group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None) |
|
210 | group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None) | |
211 |
|
211 | |||
212 | parent_group = relation('Group', remote_side=group_id) |
|
212 | parent_group = relation('Group', remote_side=group_id) | |
213 |
|
213 | |||
214 |
|
214 | |||
215 | def __init__(self, group_name='', parent_group=None): |
|
215 | def __init__(self, group_name='', parent_group=None): | |
216 | self.group_name = group_name |
|
216 | self.group_name = group_name | |
217 | self.parent_group = parent_group |
|
217 | self.parent_group = parent_group | |
218 |
|
218 | |||
219 | def __repr__(self): |
|
219 | def __repr__(self): | |
220 | return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id, |
|
220 | return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id, | |
221 | self.group_name) |
|
221 | self.group_name) | |
222 |
|
222 | |||
223 | class Permission(Base, BaseModel): |
|
223 | class Permission(Base, BaseModel): | |
224 | __tablename__ = 'permissions' |
|
224 | __tablename__ = 'permissions' | |
225 | __table_args__ = {'useexisting':True} |
|
225 | __table_args__ = {'useexisting':True} | |
226 | permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
226 | permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
227 | permission_name = Column("permission_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
227 | permission_name = Column("permission_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
228 | permission_longname = Column("permission_longname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
228 | permission_longname = Column("permission_longname", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
229 |
|
229 | |||
230 | def __repr__(self): |
|
230 | def __repr__(self): | |
231 | return "<%s('%s:%s')>" % (self.__class__.__name__, |
|
231 | return "<%s('%s:%s')>" % (self.__class__.__name__, | |
232 | self.permission_id, self.permission_name) |
|
232 | self.permission_id, self.permission_name) | |
233 |
|
233 | |||
234 | class RepoToPerm(Base, BaseModel): |
|
234 | class RepoToPerm(Base, BaseModel): | |
235 | __tablename__ = 'repo_to_perm' |
|
235 | __tablename__ = 'repo_to_perm' | |
236 | __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True}) |
|
236 | __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True}) | |
237 | repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
237 | repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
238 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
|
238 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) | |
239 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
239 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) | |
240 | repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) |
|
240 | repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None) | |
241 |
|
241 | |||
242 | user = relation('User') |
|
242 | user = relation('User') | |
243 | permission = relation('Permission') |
|
243 | permission = relation('Permission') | |
244 | repository = relation('Repository') |
|
244 | repository = relation('Repository') | |
245 |
|
245 | |||
246 | class UserToPerm(Base, BaseModel): |
|
246 | class UserToPerm(Base, BaseModel): | |
247 | __tablename__ = 'user_to_perm' |
|
247 | __tablename__ = 'user_to_perm' | |
248 | __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True}) |
|
248 | __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True}) | |
249 | user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
249 | user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
250 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
|
250 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) | |
251 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
251 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) | |
252 |
|
252 | |||
253 | user = relation('User') |
|
253 | user = relation('User') | |
254 | permission = relation('Permission') |
|
254 | permission = relation('Permission') | |
255 |
|
255 | |||
|
256 | class UsersGroupToPerm(Base, BaseModel): | |||
|
257 | __tablename__ = 'users_group_to_perm' | |||
|
258 | __table_args__ = (UniqueConstraint('users_group_id', 'permission_id'), {'useexisting':True}) | |||
|
259 | users_group_to_perm_id = Column("users_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |||
|
260 | users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_groups_id'), nullable=False, unique=None, default=None) | |||
|
261 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) | |||
|
262 | ||||
|
263 | users_group = relation('UsersGroup') | |||
|
264 | permission = relation('Permission') | |||
|
265 | ||||
256 | class GroupToPerm(Base, BaseModel): |
|
266 | class GroupToPerm(Base, BaseModel): | |
257 | __tablename__ = 'group_to_perm' |
|
267 | __tablename__ = 'group_to_perm' | |
258 | __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'useexisting':True}) |
|
268 | __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'useexisting':True}) | |
259 |
|
269 | |||
260 | group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
270 | group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
261 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
|
271 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) | |
262 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
272 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) | |
263 | group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) |
|
273 | group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) | |
264 |
|
274 | |||
265 | user = relation('User') |
|
275 | user = relation('User') | |
266 | permission = relation('Permission') |
|
276 | permission = relation('Permission') | |
267 | group = relation('Group') |
|
277 | group = relation('Group') | |
268 |
|
278 | |||
269 | class Statistics(Base, BaseModel): |
|
279 | class Statistics(Base, BaseModel): | |
270 | __tablename__ = 'statistics' |
|
280 | __tablename__ = 'statistics' | |
271 | __table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True}) |
|
281 | __table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True}) | |
272 | stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
282 | stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
273 | repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None) |
|
283 | repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=True, default=None) | |
274 | stat_on_revision = Column("stat_on_revision", Integer(), nullable=False) |
|
284 | stat_on_revision = Column("stat_on_revision", Integer(), nullable=False) | |
275 | commit_activity = Column("commit_activity", LargeBinary(), nullable=False)#JSON data |
|
285 | commit_activity = Column("commit_activity", LargeBinary(), nullable=False)#JSON data | |
276 | commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data |
|
286 | commit_activity_combined = Column("commit_activity_combined", LargeBinary(), nullable=False)#JSON data | |
277 | languages = Column("languages", LargeBinary(), nullable=False)#JSON data |
|
287 | languages = Column("languages", LargeBinary(), nullable=False)#JSON data | |
278 |
|
288 | |||
279 | repository = relation('Repository', single_parent=True) |
|
289 | repository = relation('Repository', single_parent=True) | |
280 |
|
290 | |||
281 | class UserFollowing(Base, BaseModel): |
|
291 | class UserFollowing(Base, BaseModel): | |
282 | __tablename__ = 'user_followings' |
|
292 | __tablename__ = 'user_followings' | |
283 | __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'), |
|
293 | __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'), | |
284 | UniqueConstraint('user_id', 'follows_user_id') |
|
294 | UniqueConstraint('user_id', 'follows_user_id') | |
285 | , {'useexisting':True}) |
|
295 | , {'useexisting':True}) | |
286 |
|
296 | |||
287 | user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
297 | user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
288 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
|
298 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) | |
289 | follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None) |
|
299 | follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True, unique=None, default=None) | |
290 | follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None) |
|
300 | follows_user_id = Column("follows_user_id", Integer(), ForeignKey('users.user_id'), nullable=True, unique=None, default=None) | |
291 |
|
301 | |||
292 | user = relation('User', primaryjoin='User.user_id==UserFollowing.user_id') |
|
302 | user = relation('User', primaryjoin='User.user_id==UserFollowing.user_id') | |
293 |
|
303 | |||
294 | follows_user = relation('User', primaryjoin='User.user_id==UserFollowing.follows_user_id') |
|
304 | follows_user = relation('User', primaryjoin='User.user_id==UserFollowing.follows_user_id') | |
295 | follows_repository = relation('Repository') |
|
305 | follows_repository = relation('Repository') | |
296 |
|
306 | |||
297 | class CacheInvalidation(Base, BaseModel): |
|
307 | class CacheInvalidation(Base, BaseModel): | |
298 | __tablename__ = 'cache_invalidation' |
|
308 | __tablename__ = 'cache_invalidation' | |
299 | __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True}) |
|
309 | __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True}) | |
300 | cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
310 | cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
301 | cache_key = Column("cache_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
311 | cache_key = Column("cache_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
302 | cache_args = Column("cache_args", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
312 | cache_args = Column("cache_args", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
303 | cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False) |
|
313 | cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False) | |
304 |
|
314 | |||
305 |
|
315 | |||
306 | def __init__(self, cache_key, cache_args=''): |
|
316 | def __init__(self, cache_key, cache_args=''): | |
307 | self.cache_key = cache_key |
|
317 | self.cache_key = cache_key | |
308 | self.cache_args = cache_args |
|
318 | self.cache_args = cache_args | |
309 | self.cache_active = False |
|
319 | self.cache_active = False | |
310 |
|
320 | |||
311 | def __repr__(self): |
|
321 | def __repr__(self): | |
312 | return "<%s('%s:%s')>" % (self.__class__.__name__, |
|
322 | return "<%s('%s:%s')>" % (self.__class__.__name__, | |
313 | self.cache_id, self.cache_key) |
|
323 | self.cache_id, self.cache_key) | |
314 |
|
324 | |||
315 | class DbMigrateVersion(Base, BaseModel): |
|
325 | class DbMigrateVersion(Base, BaseModel): | |
316 | __tablename__ = 'db_migrate_version' |
|
326 | __tablename__ = 'db_migrate_version' | |
317 | __table_args__ = {'useexisting':True} |
|
327 | __table_args__ = {'useexisting':True} | |
318 | repository_id = Column('repository_id', String(250), primary_key=True) |
|
328 | repository_id = Column('repository_id', String(250), primary_key=True) | |
319 | repository_path = Column('repository_path', Text) |
|
329 | repository_path = Column('repository_path', Text) | |
320 | version = Column('version', Integer) |
|
330 | version = Column('version', Integer) | |
321 |
|
331 |
General Comments 0
You need to be logged in to leave comments.
Login now