Show More
@@ -14,39 +14,7 b' from rhodecode.lib.dbmigrate.migrate imp' | |||||
14 |
|
14 | |||
15 | log = logging.getLogger(__name__) |
|
15 | log = logging.getLogger(__name__) | |
16 |
|
16 | |||
17 | class BaseModel(object): |
|
17 | class RhodeCodeSettings(Base): | |
18 |
|
||||
19 | @classmethod |
|
|||
20 | def _get_keys(cls): |
|
|||
21 | """return column names for this model """ |
|
|||
22 | return class_mapper(cls).c.keys() |
|
|||
23 |
|
||||
24 | def get_dict(self): |
|
|||
25 | """return dict with keys and values corresponding |
|
|||
26 | to this model data """ |
|
|||
27 |
|
||||
28 | d = {} |
|
|||
29 | for k in self._get_keys(): |
|
|||
30 | d[k] = getattr(self, k) |
|
|||
31 | return d |
|
|||
32 |
|
||||
33 | def get_appstruct(self): |
|
|||
34 | """return list with keys and values tupples corresponding |
|
|||
35 | to this model data """ |
|
|||
36 |
|
||||
37 | l = [] |
|
|||
38 | for k in self._get_keys(): |
|
|||
39 | l.append((k, getattr(self, k),)) |
|
|||
40 | return l |
|
|||
41 |
|
||||
42 | def populate_obj(self, populate_dict): |
|
|||
43 | """populate model with data from given populate_dict""" |
|
|||
44 |
|
||||
45 | for k in self._get_keys(): |
|
|||
46 | if k in populate_dict: |
|
|||
47 | setattr(self, k, populate_dict[k]) |
|
|||
48 |
|
||||
49 | class RhodeCodeSettings(Base, BaseModel): |
|
|||
50 | __tablename__ = 'rhodecode_settings' |
|
18 | __tablename__ = 'rhodecode_settings' | |
51 | __table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True}) |
|
19 | __table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True}) | |
52 | app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
20 | app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
@@ -61,7 +29,7 b' class RhodeCodeSettings(Base, BaseModel)' | |||||
61 | return "<RhodeCodeSetting('%s:%s')>" % (self.app_settings_name, |
|
29 | return "<RhodeCodeSetting('%s:%s')>" % (self.app_settings_name, | |
62 | self.app_settings_value) |
|
30 | self.app_settings_value) | |
63 |
|
31 | |||
64 |
class RhodeCodeUi(Base |
|
32 | class RhodeCodeUi(Base): | |
65 | __tablename__ = 'rhodecode_ui' |
|
33 | __tablename__ = 'rhodecode_ui' | |
66 | __table_args__ = {'useexisting':True} |
|
34 | __table_args__ = {'useexisting':True} | |
67 | ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
35 | ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
@@ -71,7 +39,7 b' class RhodeCodeUi(Base, BaseModel):' | |||||
71 | ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True) |
|
39 | ui_active = Column("ui_active", Boolean(), nullable=True, unique=None, default=True) | |
72 |
|
40 | |||
73 |
|
41 | |||
74 |
class User(Base |
|
42 | class User(Base): | |
75 | __tablename__ = 'users' |
|
43 | __tablename__ = 'users' | |
76 | __table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'useexisting':True}) |
|
44 | __table_args__ = (UniqueConstraint('username'), UniqueConstraint('email'), {'useexisting':True}) | |
77 | user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
45 | user_id = Column("user_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
@@ -111,7 +79,7 b' class User(Base, BaseModel):' | |||||
111 | session.rollback() |
|
79 | session.rollback() | |
112 |
|
80 | |||
113 |
|
81 | |||
114 |
class UserLog(Base |
|
82 | class UserLog(Base): | |
115 | __tablename__ = 'user_logs' |
|
83 | __tablename__ = 'user_logs' | |
116 | __table_args__ = {'useexisting':True} |
|
84 | __table_args__ = {'useexisting':True} | |
117 | user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
85 | user_log_id = Column("user_log_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
@@ -125,7 +93,7 b' class UserLog(Base, BaseModel):' | |||||
125 | user = relation('User') |
|
93 | user = relation('User') | |
126 | repository = relation('Repository') |
|
94 | repository = relation('Repository') | |
127 |
|
95 | |||
128 |
class Repository(Base |
|
96 | class Repository(Base): | |
129 | __tablename__ = 'repositories' |
|
97 | __tablename__ = 'repositories' | |
130 | __table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},) |
|
98 | __table_args__ = (UniqueConstraint('repo_name'), {'useexisting':True},) | |
131 | repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
99 | repo_id = Column("repo_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
@@ -148,7 +116,7 b' class Repository(Base, BaseModel):' | |||||
148 | def __repr__(self): |
|
116 | def __repr__(self): | |
149 | return "<Repository('%s:%s')>" % (self.repo_id, self.repo_name) |
|
117 | return "<Repository('%s:%s')>" % (self.repo_id, self.repo_name) | |
150 |
|
118 | |||
151 |
class Permission(Base |
|
119 | class Permission(Base): | |
152 | __tablename__ = 'permissions' |
|
120 | __tablename__ = 'permissions' | |
153 | __table_args__ = {'useexisting':True} |
|
121 | __table_args__ = {'useexisting':True} | |
154 | permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
122 | permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
@@ -158,7 +126,7 b' class Permission(Base, BaseModel):' | |||||
158 | def __repr__(self): |
|
126 | def __repr__(self): | |
159 | return "<Permission('%s:%s')>" % (self.permission_id, self.permission_name) |
|
127 | return "<Permission('%s:%s')>" % (self.permission_id, self.permission_name) | |
160 |
|
128 | |||
161 |
class RepoToPerm(Base |
|
129 | class RepoToPerm(Base): | |
162 | __tablename__ = 'repo_to_perm' |
|
130 | __tablename__ = 'repo_to_perm' | |
163 | __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True}) |
|
131 | __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True}) | |
164 | repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
132 | repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
@@ -170,7 +138,7 b' class RepoToPerm(Base, BaseModel):' | |||||
170 | permission = relation('Permission') |
|
138 | permission = relation('Permission') | |
171 | repository = relation('Repository') |
|
139 | repository = relation('Repository') | |
172 |
|
140 | |||
173 |
class UserToPerm(Base |
|
141 | class UserToPerm(Base): | |
174 | __tablename__ = 'user_to_perm' |
|
142 | __tablename__ = 'user_to_perm' | |
175 | __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True}) |
|
143 | __table_args__ = (UniqueConstraint('user_id', 'permission_id'), {'useexisting':True}) | |
176 | user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
144 | user_to_perm_id = Column("user_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
@@ -180,7 +148,7 b' class UserToPerm(Base, BaseModel):' | |||||
180 | user = relation('User') |
|
148 | user = relation('User') | |
181 | permission = relation('Permission') |
|
149 | permission = relation('Permission') | |
182 |
|
150 | |||
183 |
class Statistics(Base |
|
151 | class Statistics(Base): | |
184 | __tablename__ = 'statistics' |
|
152 | __tablename__ = 'statistics' | |
185 | __table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True}) |
|
153 | __table_args__ = (UniqueConstraint('repository_id'), {'useexisting':True}) | |
186 | stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
154 | stat_id = Column("stat_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
@@ -192,7 +160,7 b' class Statistics(Base, BaseModel):' | |||||
192 |
|
160 | |||
193 | repository = relation('Repository', single_parent=True) |
|
161 | repository = relation('Repository', single_parent=True) | |
194 |
|
162 | |||
195 |
class UserFollowing(Base |
|
163 | class UserFollowing(Base): | |
196 | __tablename__ = 'user_followings' |
|
164 | __tablename__ = 'user_followings' | |
197 | __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'), |
|
165 | __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'), | |
198 | UniqueConstraint('user_id', 'follows_user_id') |
|
166 | UniqueConstraint('user_id', 'follows_user_id') | |
@@ -209,7 +177,7 b' class UserFollowing(Base, BaseModel):' | |||||
209 | follows_repository = relation('Repository') |
|
177 | follows_repository = relation('Repository') | |
210 |
|
178 | |||
211 |
|
179 | |||
212 |
class CacheInvalidation(Base |
|
180 | class CacheInvalidation(Base): | |
213 | __tablename__ = 'cache_invalidation' |
|
181 | __tablename__ = 'cache_invalidation' | |
214 | __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True}) |
|
182 | __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True}) | |
215 | cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
183 | cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
@@ -6,7 +6,6 b' from sqlalchemy.exc import DatabaseError' | |||||
6 | from sqlalchemy.orm import relation, backref, class_mapper |
|
6 | from sqlalchemy.orm import relation, backref, class_mapper | |
7 | from sqlalchemy.orm.session import Session |
|
7 | from sqlalchemy.orm.session import Session | |
8 | from rhodecode.model.meta import Base |
|
8 | from rhodecode.model.meta import Base | |
9 | from rhodecode.model.db import BaseModel |
|
|||
10 |
|
9 | |||
11 | from rhodecode.lib.dbmigrate.migrate import * |
|
10 | from rhodecode.lib.dbmigrate.migrate import * | |
12 | from rhodecode.lib.dbmigrate.migrate.changeset import * |
|
11 | from rhodecode.lib.dbmigrate.migrate.changeset import * | |
@@ -70,13 +69,43 b' def upgrade(migrate_engine):' | |||||
70 | #========================================================================== |
|
69 | #========================================================================== | |
71 | # Add table `user_followings` |
|
70 | # Add table `user_followings` | |
72 | #========================================================================== |
|
71 | #========================================================================== | |
73 | from rhodecode.model.db import UserFollowing |
|
72 | class UserFollowing(Base, BaseModel): | |
|
73 | __tablename__ = 'user_followings' | |||
|
74 | __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'), | |||
|
75 | UniqueConstraint('user_id', 'follows_user_id') | |||
|
76 | , {'useexisting':True}) | |||
|
77 | ||||
|
78 | user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |||
|
79 | user_id = Column("user_id", Integer(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None) | |||
|
80 | follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey(u'repositories.repo_id'), nullable=True, unique=None, default=None) | |||
|
81 | follows_user_id = Column("follows_user_id", Integer(), ForeignKey(u'users.user_id'), nullable=True, unique=None, default=None) | |||
|
82 | ||||
|
83 | user = relation('User', primaryjoin='User.user_id==UserFollowing.user_id') | |||
|
84 | ||||
|
85 | follows_user = relation('User', primaryjoin='User.user_id==UserFollowing.follows_user_id') | |||
|
86 | follows_repository = relation('Repository') | |||
|
87 | ||||
74 | UserFollowing().__table__.create() |
|
88 | UserFollowing().__table__.create() | |
75 |
|
89 | |||
76 | #========================================================================== |
|
90 | #========================================================================== | |
77 | # Add table `cache_invalidation` |
|
91 | # Add table `cache_invalidation` | |
78 | #========================================================================== |
|
92 | #========================================================================== | |
79 | from rhodecode.model.db import CacheInvalidation |
|
93 | class CacheInvalidation(Base, BaseModel): | |
|
94 | __tablename__ = 'cache_invalidation' | |||
|
95 | __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True}) | |||
|
96 | cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |||
|
97 | cache_key = Column("cache_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |||
|
98 | cache_args = Column("cache_args", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |||
|
99 | cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False) | |||
|
100 | ||||
|
101 | ||||
|
102 | def __init__(self, cache_key, cache_args=''): | |||
|
103 | self.cache_key = cache_key | |||
|
104 | self.cache_args = cache_args | |||
|
105 | self.cache_active = False | |||
|
106 | ||||
|
107 | def __repr__(self): | |||
|
108 | return "<CacheInvalidation('%s:%s')>" % (self.cache_id, self.cache_key) | |||
80 | CacheInvalidation().__table__.create() |
|
109 | CacheInvalidation().__table__.create() | |
81 |
|
110 | |||
82 | return |
|
111 | return |
General Comments 0
You need to be logged in to leave comments.
Login now