Changeset - 1a080d4e926e
[Not reviewed]
default
0 3 0
Søren Løvborg (kwi) - 9 years ago 2016-07-15 19: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) First comment
kallithea/model/db.py
Show inline comments
 
@@ -1483,7 +1483,7 @@ class Repository(Base, BaseModel):
 
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'}
 
@@ -1900,7 +1900,7 @@ class UserGroupUserGroupToPerm(Base, Bas
 
    __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,
 
    )
 

	
 
@@ -2012,8 +2012,8 @@ class Statistics(Base, BaseModel):
 
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,
 
    )
 

	
kallithea/model/meta.py
Show inline comments
 
@@ -40,3 +40,18 @@ 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
 
@@ -43,7 +43,7 @@ requirements = [
 
    "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",
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now