Mercurial > kallithea
annotate rhodecode/lib/dbmigrate/versions/003_version_1_2_0.py @ 1023:e7478ac19f9f beta
updated db migrations to schema 3
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 11 Feb 2011 00:35:48 +0100 |
parents | de560c47dd03 |
children | 3c80eb712a78 |
rev | line source |
---|---|
900
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 import logging |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 import datetime |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 from sqlalchemy import * |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 from sqlalchemy.exc import DatabaseError |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 from sqlalchemy.orm import relation, backref, class_mapper |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 from sqlalchemy.orm.session import Session |
907
2f83756f3041
Fixed dbmigrate issues.
Marcin Kuzminski <marcin@python-works.com>
parents:
900
diff
changeset
|
8 |
2f83756f3041
Fixed dbmigrate issues.
Marcin Kuzminski <marcin@python-works.com>
parents:
900
diff
changeset
|
9 from rhodecode.lib.dbmigrate.migrate import * |
2f83756f3041
Fixed dbmigrate issues.
Marcin Kuzminski <marcin@python-works.com>
parents:
900
diff
changeset
|
10 from rhodecode.lib.dbmigrate.migrate.changeset import * |
2f83756f3041
Fixed dbmigrate issues.
Marcin Kuzminski <marcin@python-works.com>
parents:
900
diff
changeset
|
11 |
900
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 from rhodecode.model.meta import Base |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 from rhodecode.model.db import BaseModel |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 log = logging.getLogger(__name__) |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 def upgrade(migrate_engine): |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 """ Upgrade operations go here. |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 Don't create your own engine; bind migrate_engine to your metadata |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 """ |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 #========================================================================== |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # Add table `groups`` |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 #========================================================================== |
1023
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
25 # from rhodecode.model.db import Group |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
26 # Group().__table__.create() |
900
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 #========================================================================== |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 # Add table `group_to_perm` |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 #========================================================================== |
1023
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
31 # from rhodecode.model.db import GroupToPerm |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
32 # GroupToPerm().__table__.create() |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
33 |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
34 #========================================================================== |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
35 # Add table `users_groups` |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
36 #========================================================================== |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
37 # from rhodecode.model.db import UsersGroup |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
38 # UsersGroup().__table__.create() |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
39 |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
40 #========================================================================== |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
41 # Add table `users_groups_members` |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
42 #========================================================================== |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
43 from rhodecode.model.db import UsersGroupMember |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
44 UsersGroupMember().__table__.create() |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
45 |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
46 #========================================================================== |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
47 # Add table `users_group_to_perm` |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
48 #========================================================================== |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
49 from rhodecode.model.db import UsersGroupToPerm |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
50 UsersGroupToPerm().__table__.create() |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
51 |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
52 |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
53 #========================================================================== |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
54 # Upgrade of `users` table |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
55 #========================================================================== |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
56 from rhodecode.model.db import User |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
57 |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
58 #add column |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
59 ldap_dn = Column("ldap_dn", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
60 ldap_dn.create(User().__table__) |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
61 |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
62 |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
63 #remove old column |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
64 is_ldap = Column("is_ldap", Boolean(), nullable=False, unique=None, default=False) |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
65 is_ldap.drop(User().__table__) |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
66 |
900
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 #========================================================================== |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 # Upgrade of `repositories` table |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 #========================================================================== |
908
de560c47dd03
Added missing FK to migration
Marcin Kuzminski <marcin@python-works.com>
parents:
907
diff
changeset
|
71 from rhodecode.model.db import Repository |
900
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 |
1023
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
73 #ADD downloads column# |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
74 enable_downloads = Column("downloads", Boolean(), nullable=True, unique=None, default=True) |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
75 enable_downloads.create(Repository().__table__) |
e7478ac19f9f
updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents:
908
diff
changeset
|
76 |
900
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 #ADD group_id column# |
908
de560c47dd03
Added missing FK to migration
Marcin Kuzminski <marcin@python-works.com>
parents:
907
diff
changeset
|
78 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), |
900
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 nullable=True, unique=False, default=None) |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 |
908
de560c47dd03
Added missing FK to migration
Marcin Kuzminski <marcin@python-works.com>
parents:
907
diff
changeset
|
81 group_id.create(Repository().__table__) |
900
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 return |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 def downgrade(migrate_engine): |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 meta = MetaData() |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 meta.bind = migrate_engine |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 |
07f248329a3b
updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 |