Mercurial > kallithea
annotate rhodecode/lib/dbmigrate/versions/002_version_1_1_0.py @ 1818:cf51bbfb120e beta
auto white-space removal
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 29 Dec 2011 07:35:51 +0200 |
parents | 5cacb51f25f1 |
children | 72c525a7e7ad |
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 #========================================================================== |
1631
5cacb51f25f1
freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
72 from rhodecode.lib.dbmigrate.schema.db_1_1_0 import UserFollowing |
907
2f83756f3041
Fixed dbmigrate issues.
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
73 UserFollowing().__table__.create() |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1631
diff
changeset
|
74 |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 #========================================================================== |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 # Add table `cache_invalidation` |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 #========================================================================== |
1631
5cacb51f25f1
freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
78 from rhodecode.lib.dbmigrate.schema.db_1_1_0 import CacheInvalidation |
907
2f83756f3041
Fixed dbmigrate issues.
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
79 CacheInvalidation().__table__.create() |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 return |
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 def downgrade(migrate_engine): |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 meta = MetaData() |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 meta.bind = migrate_engine |