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