##// END OF EJS Templates
Added missing FK to migration
marcink -
r908:de560c47 beta
parent child Browse files
Show More
@@ -1,59 +1,52
1 import logging
1 import logging
2 import datetime
2 import datetime
3
3
4 from sqlalchemy import *
4 from sqlalchemy import *
5 from sqlalchemy.exc import DatabaseError
5 from sqlalchemy.exc import DatabaseError
6 from sqlalchemy.orm import relation, backref, class_mapper
6 from sqlalchemy.orm import relation, backref, class_mapper
7 from sqlalchemy.orm.session import Session
7 from sqlalchemy.orm.session import Session
8
8
9
10 from rhodecode.lib.dbmigrate.migrate import *
9 from rhodecode.lib.dbmigrate.migrate import *
11 from rhodecode.lib.dbmigrate.migrate.changeset import *
10 from rhodecode.lib.dbmigrate.migrate.changeset import *
12
11
13 from rhodecode.model.meta import Base
12 from rhodecode.model.meta import Base
14 from rhodecode.model.db import BaseModel
13 from rhodecode.model.db import BaseModel
15
14
16 log = logging.getLogger(__name__)
15 log = logging.getLogger(__name__)
17
16
18 def upgrade(migrate_engine):
17 def upgrade(migrate_engine):
19 """ Upgrade operations go here.
18 """ Upgrade operations go here.
20 Don't create your own engine; bind migrate_engine to your metadata
19 Don't create your own engine; bind migrate_engine to your metadata
21 """
20 """
22
21
23 #==========================================================================
22 #==========================================================================
24 # Add table `groups``
23 # Add table `groups``
25 #==========================================================================
24 #==========================================================================
26 from rhodecode.model.db import Group
25 from rhodecode.model.db import Group
27 Group().__table__.create()
26 Group().__table__.create()
28
27
29 #==========================================================================
28 #==========================================================================
30 # Add table `group_to_perm`
29 # Add table `group_to_perm`
31 #==========================================================================
30 #==========================================================================
32 from rhodecode.model.db import GroupToPerm
31 from rhodecode.model.db import GroupToPerm
33 GroupToPerm().__table__.create()
32 GroupToPerm().__table__.create()
34
33
35 #==========================================================================
34 #==========================================================================
36 # Upgrade of `repositories` table
35 # Upgrade of `repositories` table
37 #==========================================================================
36 #==========================================================================
38 tblname = 'repositories'
37 from rhodecode.model.db import Repository
39 tbl = Table(tblname, MetaData(bind=migrate_engine), autoload=True,
40 autoload_with=migrate_engine)
41
38
42 #ADD group_id column#
39 #ADD group_id column#
43 group_id = Column("group_id", Integer(), #ForeignKey('groups.group_id'),
40 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'),
44 nullable=True, unique=False, default=None)
41 nullable=True, unique=False, default=None)
45
42
46 group_id.create(tbl)
43 group_id.create(Repository().__table__)
47
44
48 # TODO: fix this somehow ?!
49 # cons = ForeignKeyConstraint([tbl.c.group_id], ['groups.group_id'], table=tbl)
50 #
51 # cons.create()
52 return
45 return
53
46
54
47
55 def downgrade(migrate_engine):
48 def downgrade(migrate_engine):
56 meta = MetaData()
49 meta = MetaData()
57 meta.bind = migrate_engine
50 meta.bind = migrate_engine
58
51
59
52
General Comments 0
You need to be logged in to leave comments. Login now