Show More
@@ -26,17 +26,24 b' def upgrade(migrate_engine):' | |||||
26 | tbl = UserRepoToPerm().__table__ |
|
26 | tbl = UserRepoToPerm().__table__ | |
27 | new_cons = UniqueConstraint('user_id', 'repository_id', 'permission_id', table=tbl) |
|
27 | new_cons = UniqueConstraint('user_id', 'repository_id', 'permission_id', table=tbl) | |
28 | new_cons.create() |
|
28 | new_cons.create() | |
29 |
|
29 | old_cons = None | ||
30 | if migrate_engine.name in ['mysql']: |
|
30 | if migrate_engine.name in ['mysql']: | |
31 | old_cons = UniqueConstraint('user_id', 'repository_id', table=tbl, name="user_id") |
|
31 | old_cons = UniqueConstraint('user_id', 'repository_id', table=tbl, name="user_id") | |
32 | old_cons.drop() |
|
|||
33 | elif migrate_engine.name in ['postgresql']: |
|
32 | elif migrate_engine.name in ['postgresql']: | |
34 | old_cons = UniqueConstraint('user_id', 'repository_id', table=tbl) |
|
33 | old_cons = UniqueConstraint('user_id', 'repository_id', table=tbl) | |
35 | old_cons.drop() |
|
|||
36 | else: |
|
34 | else: | |
37 | # sqlite doesn't support dropping constraints... |
|
35 | # sqlite doesn't support dropping constraints... | |
38 | print """Please manually drop UniqueConstraint('user_id', 'repository_id')""" |
|
36 | print """Please manually drop UniqueConstraint('user_id', 'repository_id')""" | |
39 |
|
37 | |||
|
38 | if old_cons: | |||
|
39 | try: | |||
|
40 | old_cons.drop() | |||
|
41 | except Exception, e: | |||
|
42 | # we don't care if this fails really... better to pass migration than | |||
|
43 | # leave this in intermidiate state | |||
|
44 | print 'Failed to remove Unique for user_id, repository_id reason %s' % e | |||
|
45 | ||||
|
46 | ||||
40 | #========================================================================== |
|
47 | #========================================================================== | |
41 | # fix uniques of table `user_repo_group_to_perm` |
|
48 | # fix uniques of table `user_repo_group_to_perm` | |
42 | #========================================================================== |
|
49 | #========================================================================== | |
@@ -44,19 +51,26 b' def upgrade(migrate_engine):' | |||||
44 | tbl = UserRepoGroupToPerm().__table__ |
|
51 | tbl = UserRepoGroupToPerm().__table__ | |
45 | new_cons = UniqueConstraint('group_id', 'permission_id', 'user_id', table=tbl) |
|
52 | new_cons = UniqueConstraint('group_id', 'permission_id', 'user_id', table=tbl) | |
46 | new_cons.create() |
|
53 | new_cons.create() | |
|
54 | old_cons = None | |||
47 |
|
55 | |||
48 | # fix uniqueConstraints |
|
56 | # fix uniqueConstraints | |
49 | if migrate_engine.name in ['mysql']: |
|
57 | if migrate_engine.name in ['mysql']: | |
50 | #mysql is givinig troubles here... |
|
58 | #mysql is givinig troubles here... | |
51 | old_cons = UniqueConstraint('group_id', 'permission_id', table=tbl, name="group_id") |
|
59 | old_cons = UniqueConstraint('group_id', 'permission_id', table=tbl, name="group_id") | |
52 | old_cons.drop() |
|
|||
53 | elif migrate_engine.name in ['postgresql']: |
|
60 | elif migrate_engine.name in ['postgresql']: | |
54 | old_cons = UniqueConstraint('group_id', 'permission_id', table=tbl, name='group_to_perm_group_id_permission_id_key') |
|
61 | old_cons = UniqueConstraint('group_id', 'permission_id', table=tbl, name='group_to_perm_group_id_permission_id_key') | |
55 | old_cons.drop() |
|
|||
56 | else: |
|
62 | else: | |
57 | # sqlite doesn't support dropping constraints... |
|
63 | # sqlite doesn't support dropping constraints... | |
58 | print """Please manually drop UniqueConstraint('group_id', 'permission_id')""" |
|
64 | print """Please manually drop UniqueConstraint('group_id', 'permission_id')""" | |
59 |
|
65 | |||
|
66 | if old_cons: | |||
|
67 | try: | |||
|
68 | old_cons.drop() | |||
|
69 | except Exception, e: | |||
|
70 | # we don't care if this fails really... better to pass migration than | |||
|
71 | # leave this in intermidiate state | |||
|
72 | print 'Failed to remove Unique for user_id, repository_id reason %s' % e | |||
|
73 | ||||
60 | return |
|
74 | return | |
61 |
|
75 | |||
62 |
|
76 |
General Comments 0
You need to be logged in to leave comments.
Login now