annotate rhodecode/lib/dbmigrate/versions/003_version_1_2_0.py @ 3700:3563bb7b4b82

merge with rc1
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 07 Apr 2013 18:37:22 +0200
parents a437a986d399 fa6ba6727475
children 7e5f8c12a3fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 log = logging.getLogger(__name__)
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
16
900
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 def upgrade(migrate_engine):
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1133
diff changeset
18 """ Upgrade operations go here.
900
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 #==========================================================================
2195
b5f03c1d2153 fixed migration import error
Marcin Kuzminski <marcin@python-works.com>
parents: 2000
diff changeset
25 from rhodecode.lib.dbmigrate.schema.db_1_2_0 import Group as Group
1026
3c80eb712a78 uncommented migrate tables, docfix
Marcin Kuzminski <marcin@python-works.com>
parents: 1023
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 #==========================================================================
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents: 1509
diff changeset
31 from rhodecode.lib.dbmigrate.schema.db_1_2_0 import UserRepoGroupToPerm
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents: 1509
diff changeset
32 UserRepoGroupToPerm().__table__.create()
1023
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 #==========================================================================
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 2195
diff changeset
37 from rhodecode.lib.dbmigrate.schema.db_1_2_0 import UserGroup
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 2195
diff changeset
38 UserGroup().__table__.create()
1023
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 #==========================================================================
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 2195
diff changeset
43 from rhodecode.lib.dbmigrate.schema.db_1_2_0 import UserGroupMember
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 2195
diff changeset
44 UserGroupMember().__table__.create()
1023
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 #==========================================================================
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1260
diff changeset
47 # Add table `users_group_repo_to_perm`
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1260
diff changeset
48 #==========================================================================
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 2195
diff changeset
49 from rhodecode.lib.dbmigrate.schema.db_1_2_0 import UserGroupRepoToPerm
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 2195
diff changeset
50 UserGroupRepoToPerm().__table__.create()
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1260
diff changeset
51
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1260
diff changeset
52 #==========================================================================
1023
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 908
diff changeset
53 # Add table `users_group_to_perm`
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 908
diff changeset
54 #==========================================================================
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 2195
diff changeset
55 from rhodecode.lib.dbmigrate.schema.db_1_2_0 import UserGroupToPerm
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 2195
diff changeset
56 UserGroupToPerm().__table__.create()
1023
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 #==========================================================================
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 908
diff changeset
59 # Upgrade of `users` table
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 908
diff changeset
60 #==========================================================================
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents: 1509
diff changeset
61 from rhodecode.lib.dbmigrate.schema.db_1_2_0 import User
1023
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 #add column
1762
a69d0029bd27 migration fix for mysql
Marcin Kuzminski <marcin@python-works.com>
parents: 1632
diff changeset
64 ldap_dn = Column("ldap_dn", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
1023
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 908
diff changeset
65 ldap_dn.create(User().__table__)
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 908
diff changeset
66
1133
07fcf1683503 updated migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 1026
diff changeset
67 api_key = Column("api_key", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
07fcf1683503 updated migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 1026
diff changeset
68 api_key.create(User().__table__)
1023
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 908
diff changeset
69
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 908
diff changeset
70 #remove old column
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 908
diff changeset
71 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
72 is_ldap.drop(User().__table__)
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 908
diff changeset
73
900
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 #==========================================================================
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 # Upgrade of `repositories` table
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1133
diff changeset
76 #==========================================================================
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents: 1509
diff changeset
77 from rhodecode.lib.dbmigrate.schema.db_1_2_0 import Repository
900
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78
1509
da886cc79907 migration schema fix
Marcin Kuzminski <marcin@python-works.com>
parents: 1442
diff changeset
79 #ADD clone_uri column#
da886cc79907 migration schema fix
Marcin Kuzminski <marcin@python-works.com>
parents: 1442
diff changeset
80
da886cc79907 migration schema fix
Marcin Kuzminski <marcin@python-works.com>
parents: 1442
diff changeset
81 clone_uri = Column("clone_uri", String(length=255, convert_unicode=False,
da886cc79907 migration schema fix
Marcin Kuzminski <marcin@python-works.com>
parents: 1442
diff changeset
82 assert_unicode=None),
da886cc79907 migration schema fix
Marcin Kuzminski <marcin@python-works.com>
parents: 1442
diff changeset
83 nullable=True, unique=False, default=None)
da886cc79907 migration schema fix
Marcin Kuzminski <marcin@python-works.com>
parents: 1442
diff changeset
84
da886cc79907 migration schema fix
Marcin Kuzminski <marcin@python-works.com>
parents: 1442
diff changeset
85 clone_uri.create(Repository().__table__)
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1762
diff changeset
86
1023
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 908
diff changeset
87 #ADD downloads column#
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 908
diff changeset
88 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
89 enable_downloads.create(Repository().__table__)
e7478ac19f9f updated db migrations to schema 3
Marcin Kuzminski <marcin@python-works.com>
parents: 908
diff changeset
90
1442
7f31de1584c6 update migrations for 1.2
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
91 #ADD column created_on
7f31de1584c6 update migrations for 1.2
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
92 created_on = Column('created_on', DateTime(timezone=False), nullable=True,
7f31de1584c6 update migrations for 1.2
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
93 unique=None, default=datetime.datetime.now)
7f31de1584c6 update migrations for 1.2
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
94 created_on.create(Repository().__table__)
7f31de1584c6 update migrations for 1.2
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
95
900
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 #ADD group_id column#
908
de560c47dd03 Added missing FK to migration
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
97 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
98 nullable=True, unique=False, default=None)
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99
908
de560c47dd03 Added missing FK to migration
Marcin Kuzminski <marcin@python-works.com>
parents: 907
diff changeset
100 group_id.create(Repository().__table__)
900
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101
1442
7f31de1584c6 update migrations for 1.2
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
102 #==========================================================================
7f31de1584c6 update migrations for 1.2
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
103 # Upgrade of `user_followings` table
7f31de1584c6 update migrations for 1.2
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
104 #==========================================================================
7f31de1584c6 update migrations for 1.2
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
105
1631
5cacb51f25f1 freeze of models for future migrations using small schema files snapshoting current model state
Marcin Kuzminski <marcin@python-works.com>
parents: 1509
diff changeset
106 from rhodecode.lib.dbmigrate.schema.db_1_2_0 import UserFollowing
1509
da886cc79907 migration schema fix
Marcin Kuzminski <marcin@python-works.com>
parents: 1442
diff changeset
107
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1762
diff changeset
108 follows_from = Column('follows_from', DateTime(timezone=False),
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1762
diff changeset
109 nullable=True, unique=None,
1509
da886cc79907 migration schema fix
Marcin Kuzminski <marcin@python-works.com>
parents: 1442
diff changeset
110 default=datetime.datetime.now)
da886cc79907 migration schema fix
Marcin Kuzminski <marcin@python-works.com>
parents: 1442
diff changeset
111 follows_from.create(UserFollowing().__table__)
1442
7f31de1584c6 update migrations for 1.2
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
112
900
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 return
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 def downgrade(migrate_engine):
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 meta = MetaData()
07f248329a3b updated migration for version 1.2
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 meta.bind = migrate_engine