Mercurial > kallithea
annotate rhodecode/lib/dbmigrate/versions/002_version_1_1_0.py @ 1509:da886cc79907 beta
migration schema fix
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 04 Oct 2011 14:11:42 +0200 |
parents | 6832ef664673 |
children | bf263968da47 5cacb51f25f1 |
rev | line source |
---|---|
836 | 1 import logging |
2 import datetime | |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 |
836 | 4 from sqlalchemy import * |
5 from sqlalchemy.exc import DatabaseError | |
6 from sqlalchemy.orm import relation, backref, class_mapper | |
7 from sqlalchemy.orm.session import Session | |
8 from rhodecode.model.meta import Base | |
9 | |
10 from rhodecode.lib.dbmigrate.migrate import * | |
907
2f83756f3041
Fixed dbmigrate issues.
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
11 from rhodecode.lib.dbmigrate.migrate.changeset import * |
836 | 12 |
13 log = logging.getLogger(__name__) | |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 def upgrade(migrate_engine): |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1182
diff
changeset
|
16 """ Upgrade operations go here. |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 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
|
18 """ |
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 #========================================================================== |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # Upgrade of `users` table |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 #========================================================================== |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 tblname = 'users' |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 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
|
25 autoload_with=migrate_engine) |
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 #ADD is_ldap column |
836 | 28 is_ldap = Column("is_ldap", Boolean(), nullable=True, |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 unique=None, default=False) |
836 | 30 is_ldap.create(tbl, populate_default=True) |
31 is_ldap.alter(nullable=False) | |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 |
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 # Upgrade of `user_logs` table |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1182
diff
changeset
|
35 #========================================================================== |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 tblname = 'users' |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 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
|
39 autoload_with=migrate_engine) |
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 #ADD revision column |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 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
|
43 assert_unicode=None), |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 nullable=True, unique=None, default=None) |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 revision.create(tbl) |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 |
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 #========================================================================== |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 # Upgrade of `repositories` table |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1182
diff
changeset
|
51 #========================================================================== |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
52 tblname = 'repositories' |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 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
|
54 autoload_with=migrate_engine) |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
56 #ADD repo_type column# |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 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
|
58 assert_unicode=None), |
836 | 59 nullable=True, unique=False, default='hg') |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 |
836 | 61 repo_type.create(tbl, populate_default=True) |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
62 #repo_type.alter(nullable=False) |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
64 #ADD statistics column# |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 enable_statistics = Column("statistics", Boolean(), nullable=True, |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 unique=None, default=True) |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 enable_statistics.create(tbl) |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 #========================================================================== |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 # Add table `user_followings` |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 #========================================================================== |
1182 | 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') | |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1182
diff
changeset
|
87 |
907
2f83756f3041
Fixed dbmigrate issues.
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
88 UserFollowing().__table__.create() |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 #========================================================================== |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 # Add table `cache_invalidation` |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 #========================================================================== |
1182 | 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) | |
907
2f83756f3041
Fixed dbmigrate issues.
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
109 CacheInvalidation().__table__.create() |
833
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 return |
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 def downgrade(migrate_engine): |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
114 meta = MetaData() |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 meta.bind = migrate_engine |