Show More
@@ -51,10 +51,14 b' class DbManage(object):' | |||||
51 | self.tests = tests |
|
51 | self.tests = tests | |
52 | self.root = root |
|
52 | self.root = root | |
53 | self.dburi = dbconf |
|
53 | self.dburi = dbconf | |
54 | engine = create_engine(self.dburi, echo=log_sql) |
|
54 | self.log_sql = log_sql | |
|
55 | self.db_exists = False | |||
|
56 | self.init_db() | |||
|
57 | ||||
|
58 | def init_db(self): | |||
|
59 | engine = create_engine(self.dburi, echo=self.log_sql) | |||
55 | init_model(engine) |
|
60 | init_model(engine) | |
56 | self.sa = meta.Session() |
|
61 | self.sa = meta.Session() | |
57 | self.db_exists = False |
|
|||
58 |
|
62 | |||
59 | def check_for_db(self, override): |
|
63 | def check_for_db(self, override): | |
60 | db_path = jn(self.root, self.dbname) |
|
64 | db_path = jn(self.root, self.dbname) | |
@@ -222,6 +226,7 b' class DbManage(object):' | |||||
222 | """ |
|
226 | """ | |
223 |
|
227 | |||
224 | hgsettings3 = RhodeCodeSettings('ga_code', '') |
|
228 | hgsettings3 = RhodeCodeSettings('ga_code', '') | |
|
229 | ||||
225 | try: |
|
230 | try: | |
226 | self.sa.add(hgsettings3) |
|
231 | self.sa.add(hgsettings3) | |
227 | self.sa.commit() |
|
232 | self.sa.commit() |
@@ -9,6 +9,7 b' from rhodecode.model.meta import Base' | |||||
9 | from rhodecode.model.db import BaseModel |
|
9 | from rhodecode.model.db import BaseModel | |
10 |
|
10 | |||
11 | from rhodecode.lib.dbmigrate.migrate import * |
|
11 | from rhodecode.lib.dbmigrate.migrate import * | |
|
12 | from rhodecode.lib.dbmigrate.migrate.changeset import * | |||
12 |
|
13 | |||
13 | log = logging.getLogger(__name__) |
|
14 | log = logging.getLogger(__name__) | |
14 |
|
15 | |||
@@ -69,57 +70,17 b' def upgrade(migrate_engine):' | |||||
69 | #========================================================================== |
|
70 | #========================================================================== | |
70 | # Add table `user_followings` |
|
71 | # Add table `user_followings` | |
71 | #========================================================================== |
|
72 | #========================================================================== | |
72 | tblname = 'user_followings' |
|
73 | from rhodecode.model.db import UserFollowing | |
73 |
|
74 | UserFollowing().__table__.create() | ||
74 | class UserFollowing(Base, BaseModel): |
|
|||
75 | __tablename__ = 'user_followings' |
|
|||
76 | __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'), |
|
|||
77 | UniqueConstraint('user_id', 'follows_user_id') |
|
|||
78 | , {'useexisting':True}) |
|
|||
79 |
|
||||
80 | user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
|||
81 | user_id = Column("user_id", Integer(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None) |
|
|||
82 | follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey(u'repositories.repo_id'), nullable=True, unique=None, default=None) |
|
|||
83 | follows_user_id = Column("follows_user_id", Integer(), ForeignKey(u'users.user_id'), nullable=True, unique=None, default=None) |
|
|||
84 |
|
||||
85 | user = relation('User', primaryjoin='User.user_id==UserFollowing.user_id') |
|
|||
86 |
|
||||
87 | follows_user = relation('User', primaryjoin='User.user_id==UserFollowing.follows_user_id') |
|
|||
88 | follows_repository = relation('Repository') |
|
|||
89 |
|
||||
90 | Base.metadata.tables[tblname].create(migrate_engine) |
|
|||
91 |
|
75 | |||
92 | #========================================================================== |
|
76 | #========================================================================== | |
93 | # Add table `cache_invalidation` |
|
77 | # Add table `cache_invalidation` | |
94 | #========================================================================== |
|
78 | #========================================================================== | |
95 | tblname = 'cache_invalidation' |
|
79 | from rhodecode.model.db import CacheInvalidation | |
96 |
|
80 | CacheInvalidation().__table__.create() | ||
97 | class CacheInvalidation(Base, BaseModel): |
|
|||
98 | __tablename__ = 'cache_invalidation' |
|
|||
99 | __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True}) |
|
|||
100 | cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
|||
101 | cache_key = Column("cache_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
|||
102 | cache_args = Column("cache_args", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
|||
103 | cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False) |
|
|||
104 |
|
||||
105 |
|
||||
106 | def __init__(self, cache_key, cache_args=''): |
|
|||
107 | self.cache_key = cache_key |
|
|||
108 | self.cache_args = cache_args |
|
|||
109 | self.cache_active = False |
|
|||
110 |
|
||||
111 | def __repr__(self): |
|
|||
112 | return "<CacheInvalidation('%s:%s')>" % (self.cache_id, self.cache_key) |
|
|||
113 |
|
||||
114 | Base.metadata.tables[tblname].create(migrate_engine) |
|
|||
115 |
|
81 | |||
116 | return |
|
82 | return | |
117 |
|
83 | |||
118 |
|
||||
119 |
|
||||
120 |
|
||||
121 |
|
||||
122 |
|
||||
123 | def downgrade(migrate_engine): |
|
84 | def downgrade(migrate_engine): | |
124 | meta = MetaData() |
|
85 | meta = MetaData() | |
125 | meta.bind = migrate_engine |
|
86 | meta.bind = migrate_engine |
@@ -5,11 +5,14 b' from sqlalchemy import *' | |||||
5 | from sqlalchemy.exc import DatabaseError |
|
5 | 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 | ||||
|
9 | ||||
|
10 | from rhodecode.lib.dbmigrate.migrate import * | |||
|
11 | from rhodecode.lib.dbmigrate.migrate.changeset import * | |||
|
12 | ||||
8 | from rhodecode.model.meta import Base |
|
13 | from rhodecode.model.meta import Base | |
9 | from rhodecode.model.db import BaseModel |
|
14 | from rhodecode.model.db import BaseModel | |
10 |
|
15 | |||
11 | from rhodecode.lib.dbmigrate.migrate import * |
|
|||
12 |
|
||||
13 | log = logging.getLogger(__name__) |
|
16 | log = logging.getLogger(__name__) | |
14 |
|
17 | |||
15 | def upgrade(migrate_engine): |
|
18 | def upgrade(migrate_engine): | |
@@ -20,48 +23,14 b' def upgrade(migrate_engine):' | |||||
20 | #========================================================================== |
|
23 | #========================================================================== | |
21 | # Add table `groups`` |
|
24 | # Add table `groups`` | |
22 | #========================================================================== |
|
25 | #========================================================================== | |
23 | tblname = 'groups' |
|
26 | from rhodecode.model.db import Group | |
24 |
|
27 | Group().__table__.create() | ||
25 | class Group(Base, BaseModel): |
|
|||
26 | __tablename__ = 'groups' |
|
|||
27 | __table_args__ = (UniqueConstraint('group_name'), {'useexisting':True},) |
|
|||
28 |
|
||||
29 | group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
|||
30 | group_name = Column("group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None) |
|
|||
31 | group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None) |
|
|||
32 |
|
||||
33 | parent_group = relation('Group', remote_side=group_id) |
|
|||
34 |
|
||||
35 |
|
||||
36 | def __init__(self, group_name='', parent_group=None): |
|
|||
37 | self.group_name = group_name |
|
|||
38 | self.parent_group = parent_group |
|
|||
39 |
|
||||
40 | def __repr__(self): |
|
|||
41 | return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id, |
|
|||
42 | self.group_name) |
|
|||
43 |
|
||||
44 | Base.metadata.tables[tblname].create(migrate_engine) |
|
|||
45 |
|
28 | |||
46 | #========================================================================== |
|
29 | #========================================================================== | |
47 | # Add table `group_to_perm` |
|
30 | # Add table `group_to_perm` | |
48 | #========================================================================== |
|
31 | #========================================================================== | |
49 | tblname = 'group_to_perm' |
|
32 | from rhodecode.model.db import GroupToPerm | |
50 |
|
33 | GroupToPerm().__table__.create() | ||
51 | class GroupToPerm(Base, BaseModel): |
|
|||
52 | __tablename__ = 'group_to_perm' |
|
|||
53 | __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'useexisting':True}) |
|
|||
54 |
|
||||
55 | group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |
|
|||
56 | user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None) |
|
|||
57 | permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) |
|
|||
58 | group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None) |
|
|||
59 |
|
||||
60 | user = relation('User') |
|
|||
61 | permission = relation('Permission') |
|
|||
62 | group = relation('Group') |
|
|||
63 |
|
||||
64 | Base.metadata.tables[tblname].create(migrate_engine) |
|
|||
65 |
|
34 | |||
66 | #========================================================================== |
|
35 | #========================================================================== | |
67 | # Upgrade of `repositories` table |
|
36 | # Upgrade of `repositories` table | |
@@ -71,12 +40,15 b' def upgrade(migrate_engine):' | |||||
71 | autoload_with=migrate_engine) |
|
40 | autoload_with=migrate_engine) | |
72 |
|
41 | |||
73 | #ADD group_id column# |
|
42 | #ADD group_id column# | |
74 |
group_id = Column("group_id", Integer(), ForeignKey( |
|
43 | group_id = Column("group_id", Integer(), #ForeignKey('groups.group_id'), | |
75 | nullable=True, unique=False, default=None) |
|
44 | nullable=True, unique=False, default=None) | |
76 |
|
45 | |||
77 |
group_id.create(tbl |
|
46 | group_id.create(tbl) | |
78 |
|
47 | |||
79 |
|
48 | # TODO: fix this somehow ?! | ||
|
49 | # cons = ForeignKeyConstraint([tbl.c.group_id], ['groups.group_id'], table=tbl) | |||
|
50 | # | |||
|
51 | # cons.create() | |||
80 | return |
|
52 | return | |
81 |
|
53 | |||
82 |
|
54 |
@@ -75,7 +75,7 b' class RhodeCodeSettings(Base, BaseModel)' | |||||
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 |
General Comments 0
You need to be logged in to leave comments.
Login now