annotate rhodecode/lib/dbmigrate/versions/004_version_1_3_0.py @ 3700:3563bb7b4b82

merge with rc1
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 07 Apr 2013 18:37:22 +0200
parents fa6ba6727475
children 7e5f8c12a3fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1632
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 import logging
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 import datetime
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 from sqlalchemy import *
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 from sqlalchemy.exc import DatabaseError
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 from sqlalchemy.orm import relation, backref, class_mapper
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 from sqlalchemy.orm.session import Session
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 from rhodecode.lib.dbmigrate.migrate import *
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 from rhodecode.lib.dbmigrate.migrate.changeset import *
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 from rhodecode.model.meta import Base
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 log = logging.getLogger(__name__)
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
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
1632
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 def upgrade(migrate_engine):
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 """ Upgrade operations go here.
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 Don't create your own engine; bind migrate_engine to your metadata
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 """
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
21 #==========================================================================
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
22 # Add table `users_group_repo_group_to_perm`
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
23 #==========================================================================
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 2000
diff changeset
24 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import UserGroupRepoGroupToPerm
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 2000
diff changeset
25 UserGroupRepoGroupToPerm().__table__.create()
1632
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
27 #==========================================================================
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
28 # Add table `changeset_comments`
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
29 #==========================================================================
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
30 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import ChangesetComment
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
31 ChangesetComment().__table__.create()
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1632
diff changeset
32
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
33 #==========================================================================
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
34 # Add table `notifications`
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
35 #==========================================================================
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
36 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import Notification
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
37 Notification().__table__.create()
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
38
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
39 #==========================================================================
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
40 # Add table `user_to_notification`
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
41 #==========================================================================
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
42 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import UserNotification
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
43 UserNotification().__table__.create()
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
44
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
45 #==========================================================================
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
46 # Add unique to table `users_group_to_perm`
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
47 #==========================================================================
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 2000
diff changeset
48 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import UserGroupToPerm
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 2000
diff changeset
49 tbl = UserGroupToPerm().__table__
2000
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
50 cons = UniqueConstraint('users_group_id', 'permission_id', table=tbl)
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
51 cons.create()
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
52
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
53 #==========================================================================
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
54 # Fix unique constrain on table `user_logs`
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
55 #==========================================================================
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
56 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import UserLog
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
57 tbl = UserLog().__table__
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
58 col = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'),
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
59 nullable=False, unique=None, default=None)
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
60 col.alter(nullable=True, table=tbl)
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
61
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
62 #==========================================================================
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
63 # Rename table `group_to_perm` to `user_repo_group_to_perm`
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
64 #==========================================================================
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
65 tbl = Table('group_to_perm', MetaData(bind=migrate_engine), autoload=True,
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
66 autoload_with=migrate_engine)
72c525a7e7ad added migrations from 1.2.X to 1.3
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
67 tbl.rename('user_repo_group_to_perm')
1632
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 return
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 def downgrade(migrate_engine):
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 meta = MetaData()
5b2cf21b1947 Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 meta.bind = migrate_engine