Changeset - 1a080d4e926e
[Not reviewed]
default
0 3 0
Søren Løvborg - 9 years ago 2016-07-15 21:49:35
sorenl@unity3d.com
db: use consistent key/index/constraint names when creating database

This simplifies future Alembic upgrades/downgrades.
http://alembic.zzzcomputing.com/en/latest/naming.html

A future changeset will update old databases to match this naming
convention.

Bump SQLAlchemy minimum version to 1.0, required for naming_convention
support.
3 files changed with 20 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/model/db.py
Show inline comments
 
@@ -1480,13 +1480,13 @@ class Repository(Base, BaseModel):
 
    def __json__(self):
 
        return dict(landing_rev = self.landing_rev)
 

	
 
class RepoGroup(Base, BaseModel):
 
    __tablename__ = 'groups'
 
    __table_args__ = (
 
        CheckConstraint('group_id != group_parent_id'),
 
        CheckConstraint('group_id != group_parent_id', name='ck_groups_no_self_parent'),
 
        _table_args_default_dict,
 
    )
 
    __mapper_args__ = {'order_by': 'group_name'}
 

	
 
    SEP = ' » '
 

	
 
@@ -1897,13 +1897,13 @@ class UserGroupRepoToPerm(Base, BaseMode
 

	
 

	
 
class UserGroupUserGroupToPerm(Base, BaseModel):
 
    __tablename__ = 'user_group_user_group_to_perm'
 
    __table_args__ = (
 
        UniqueConstraint('target_user_group_id', 'user_group_id', 'permission_id'),
 
        CheckConstraint('target_user_group_id != user_group_id'),
 
        CheckConstraint('target_user_group_id != user_group_id', name='ck_user_group_user_group_to_perm_no_self_target'),
 
        _table_args_default_dict,
 
    )
 

	
 
    user_group_user_group_to_perm_id = Column(Integer(), primary_key=True)
 
    target_user_group_id = Column(Integer(), ForeignKey('users_groups.users_group_id'), nullable=False)
 
    permission_id = Column(Integer(), ForeignKey('permissions.permission_id'), nullable=False)
 
@@ -2009,14 +2009,14 @@ class Statistics(Base, BaseModel):
 
    repository = relationship('Repository', single_parent=True)
 

	
 

	
 
class UserFollowing(Base, BaseModel):
 
    __tablename__ = 'user_followings'
 
    __table_args__ = (
 
        UniqueConstraint('user_id', 'follows_repository_id'),
 
        UniqueConstraint('user_id', 'follows_user_id'),
 
        UniqueConstraint('user_id', 'follows_repository_id', name='uq_user_followings_user_repo'),
 
        UniqueConstraint('user_id', 'follows_user_id', name='uq_user_followings_user_user'),
 
        _table_args_default_dict,
 
    )
 

	
 
    user_following_id = Column(Integer(), primary_key=True)
 
    user_id = Column(Integer(), ForeignKey('users.user_id'), nullable=False)
 
    follows_repo_id = Column("follows_repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=True)
kallithea/model/meta.py
Show inline comments
 
@@ -37,6 +37,21 @@ Session = scoped_session(session_factory
 
# The base class for declarative schemas in db.py
 
# Engine is injected when model.__init__.init_model() sets meta.Base.metadata.bind
 
Base = declarative_base()
 

	
 
#to use cache use this in query
 
#.options(FromCache("sqlalchemy_cache_type", "cachekey"))
 

	
 

	
 
# Define naming conventions for foreign keys, primary keys, indexes,
 
# check constraints, and unique constraints, respectively.
 
Base.metadata.naming_convention = {
 
    'fk': 'fk_%(table_name)s_%(column_0_name)s',
 
    'pk': 'pk_%(table_name)s',
 
    'ix': 'ix_%(column_0_label)s',
 
    'ck': 'ck_%(table_name)s_%(column_0_name)s',
 
    'uq': 'uq_%(table_name)s_%(column_0_name)s',
 
}
 
# For custom CheckConstraints (not those autogenerated e.g. for Boolean
 
# types), a name should be given explicitly, since "column_0" is here a
 
# rather vague notion. A custom name is also necesarry if the generated
 
# name is very long, since MySQL limits identifiers to 64 characters.
setup.py
Show inline comments
 
@@ -40,13 +40,13 @@ requirements = [
 
    "webob>=1.0.8,<=1.1.1",
 
    "webtest==1.4.3",
 
    "Pylons>=1.0.0,<=1.0.2",
 
    "Beaker==1.6.4",
 
    "WebHelpers==1.3",
 
    "formencode>=1.2.4,<=1.2.6",
 
    "SQLAlchemy>=0.7.10,<1.1",
 
    "SQLAlchemy>=1.0,<1.1",
 
    "Mako>=0.9.0,<=1.0.0",
 
    "pygments>=1.5",
 
    "whoosh>=2.4.0,<=2.5.7",
 
    "celery>=2.2.5,<2.3",
 
    "babel>=0.9.6,<=1.3",
 
    "python-dateutil>=1.5.0,<2.0.0",
0 comments (0 inline, 0 general)