##// END OF EJS Templates
updated migration for version 1.2
marcink -
r900:07f24832 beta
parent child Browse files
Show More
@@ -0,0 +1,87 b''
1 import logging
2 import datetime
3
4 from sqlalchemy import *
5 from sqlalchemy.exc import DatabaseError
6 from sqlalchemy.orm import relation, backref, class_mapper
7 from sqlalchemy.orm.session import Session
8 from rhodecode.model.meta import Base
9 from rhodecode.model.db import BaseModel
10
11 from rhodecode.lib.dbmigrate.migrate import *
12
13 log = logging.getLogger(__name__)
14
15 def upgrade(migrate_engine):
16 """ Upgrade operations go here.
17 Don't create your own engine; bind migrate_engine to your metadata
18 """
19
20 #==========================================================================
21 # Add table `groups``
22 #==========================================================================
23 tblname = 'groups'
24
25 class Group(Base, BaseModel):
26 __tablename__ = 'groups'
27 __table_args__ = (UniqueConstraint('group_name'), {'useexisting':True},)
28
29 group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
30 group_name = Column("group_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
31 group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
32
33 parent_group = relation('Group', remote_side=group_id)
34
35
36 def __init__(self, group_name='', parent_group=None):
37 self.group_name = group_name
38 self.parent_group = parent_group
39
40 def __repr__(self):
41 return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
42 self.group_name)
43
44 Base.metadata.tables[tblname].create(migrate_engine)
45
46 #==========================================================================
47 # Add table `group_to_perm`
48 #==========================================================================
49 tblname = 'group_to_perm'
50
51 class GroupToPerm(Base, BaseModel):
52 __tablename__ = 'group_to_perm'
53 __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'useexisting':True})
54
55 group_to_perm_id = Column("group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
56 user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
57 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
58 group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
59
60 user = relation('User')
61 permission = relation('Permission')
62 group = relation('Group')
63
64 Base.metadata.tables[tblname].create(migrate_engine)
65
66 #==========================================================================
67 # Upgrade of `repositories` table
68 #==========================================================================
69 tblname = 'repositories'
70 tbl = Table(tblname, MetaData(bind=migrate_engine), autoload=True,
71 autoload_with=migrate_engine)
72
73 #ADD group_id column#
74 group_id = Column("group_id", Integer(), ForeignKey(u'groups.group_id'),
75 nullable=True, unique=False, default=None)
76
77 group_id.create(tbl, populate_default=True)
78
79
80 return
81
82
83 def downgrade(migrate_engine):
84 meta = MetaData()
85 meta.bind = migrate_engine
86
87
@@ -103,9 +103,8 b' class DbManage(object):'
103
103
104 def upgrade(self):
104 def upgrade(self):
105 """Upgrades given database schema to given revision following
105 """Upgrades given database schema to given revision following
106 all needed steps,
106 all needed steps, to perform the upgrade
107
107
108 :param revision: revision to upgrade to
109 """
108 """
110
109
111 from rhodecode.lib.dbmigrate.migrate.versioning import api
110 from rhodecode.lib.dbmigrate.migrate.versioning import api
@@ -142,6 +141,9 b' class DbManage(object):'
142 # UPGRADE STEPS
141 # UPGRADE STEPS
143 #======================================================================
142 #======================================================================
144 class UpgradeSteps(object):
143 class UpgradeSteps(object):
144 """Those steps follow schema versions so for example schema
145 for example schema with seq 002 == step_2 and so on.
146 """
145
147
146 def __init__(self, klass):
148 def __init__(self, klass):
147 self.klass = klass
149 self.klass = klass
General Comments 0
You need to be logged in to leave comments. Login now