Mercurial > kallithea
comparison rhodecode/lib/dbmigrate/versions/002_version_1_1_0.py @ 833:9753e0907827 beta
added dbmigrate package, added model changes
moved out upgrade db command to that package
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 11 Dec 2010 01:54:12 +0100 |
parents | |
children | 28a4bb11bb6f |
comparison
equal
deleted
inserted
replaced
832:634596f81cfd | 833:9753e0907827 |
---|---|
1 from sqlalchemy import * | |
2 from sqlalchemy.orm import relation | |
3 | |
4 from migrate import * | |
5 from migrate.changeset import * | |
6 from rhodecode.model.meta import Base, BaseModel | |
7 | |
8 def upgrade(migrate_engine): | |
9 """ Upgrade operations go here. | |
10 Don't create your own engine; bind migrate_engine to your metadata | |
11 """ | |
12 | |
13 #========================================================================== | |
14 # Upgrade of `users` table | |
15 #========================================================================== | |
16 tblname = 'users' | |
17 tbl = Table(tblname, MetaData(bind=migrate_engine), autoload=True, | |
18 autoload_with=migrate_engine) | |
19 | |
20 #ADD is_ldap column | |
21 is_ldap = Column("is_ldap", Boolean(), nullable=False, | |
22 unique=None, default=False) | |
23 is_ldap.create(tbl) | |
24 | |
25 | |
26 #========================================================================== | |
27 # Upgrade of `user_logs` table | |
28 #========================================================================== | |
29 | |
30 tblname = 'users' | |
31 tbl = Table(tblname, MetaData(bind=migrate_engine), autoload=True, | |
32 autoload_with=migrate_engine) | |
33 | |
34 #ADD revision column | |
35 revision = Column('revision', TEXT(length=None, convert_unicode=False, | |
36 assert_unicode=None), | |
37 nullable=True, unique=None, default=None) | |
38 revision.create(tbl) | |
39 | |
40 | |
41 | |
42 #========================================================================== | |
43 # Upgrade of `repositories` table | |
44 #========================================================================== | |
45 tblname = 'users' | |
46 tbl = Table(tblname, MetaData(bind=migrate_engine), autoload=True, | |
47 autoload_with=migrate_engine) | |
48 | |
49 #ADD repo_type column | |
50 repo_type = Column("repo_type", String(length=None, convert_unicode=False, | |
51 assert_unicode=None), | |
52 nullable=False, unique=False, default=None) | |
53 repo_type.create(tbl) | |
54 | |
55 | |
56 #ADD statistics column | |
57 enable_statistics = Column("statistics", Boolean(), nullable=True, | |
58 unique=None, default=True) | |
59 enable_statistics.create(tbl) | |
60 | |
61 | |
62 | |
63 #========================================================================== | |
64 # Add table `user_followings` | |
65 #========================================================================== | |
66 tblname = 'user_followings' | |
67 class UserFollowing(Base, BaseModel): | |
68 __tablename__ = 'user_followings' | |
69 __table_args__ = (UniqueConstraint('user_id', 'follows_repository_id'), | |
70 UniqueConstraint('user_id', 'follows_user_id') | |
71 , {'useexisting':True}) | |
72 | |
73 user_following_id = Column("user_following_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
74 user_id = Column("user_id", Integer(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None) | |
75 follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey(u'repositories.repo_id'), nullable=True, unique=None, default=None) | |
76 follows_user_id = Column("follows_user_id", Integer(), ForeignKey(u'users.user_id'), nullable=True, unique=None, default=None) | |
77 | |
78 user = relation('User', primaryjoin='User.user_id==UserFollowing.user_id') | |
79 | |
80 follows_user = relation('User', primaryjoin='User.user_id==UserFollowing.follows_user_id') | |
81 follows_repository = relation('Repository') | |
82 | |
83 Base.metadata.tables[tblname].create(migrate_engine) | |
84 | |
85 #========================================================================== | |
86 # Add table `cache_invalidation` | |
87 #========================================================================== | |
88 class CacheInvalidation(Base, BaseModel): | |
89 __tablename__ = 'cache_invalidation' | |
90 __table_args__ = (UniqueConstraint('cache_key'), {'useexisting':True}) | |
91 cache_id = Column("cache_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | |
92 cache_key = Column("cache_key", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
93 cache_args = Column("cache_args", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
94 cache_active = Column("cache_active", Boolean(), nullable=True, unique=None, default=False) | |
95 | |
96 | |
97 def __init__(self, cache_key, cache_args=''): | |
98 self.cache_key = cache_key | |
99 self.cache_args = cache_args | |
100 self.cache_active = False | |
101 | |
102 def __repr__(self): | |
103 return "<CacheInvalidation('%s:%s')>" % (self.cache_id, self.cache_key) | |
104 | |
105 Base.metadata.tables[tblname].create(migrate_engine) | |
106 | |
107 return | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | |
114 def downgrade(migrate_engine): | |
115 meta = MetaData() | |
116 meta.bind = migrate_engine | |
117 | |
118 |