Skip to content

Commit

Permalink
Merge pull request #783 from msat-cont/lb-1822-cid-bigints
Browse files Browse the repository at this point in the history
lb-1822: big ints for cids of users and blog posts
  • Loading branch information
ioanpocol committed Jul 11, 2014
2 parents 76924ae + d7bb1cd commit 000de65
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
16 changes: 15 additions & 1 deletion plugins/livedesk/__plugin__/livedesk/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ def insertTheme():

# --------------------------------------------------------------------

@app.populate(priority=PRIORITY_LAST)
def upgradeBlogPostCid():
creator = alchemySessionCreator()
session = creator()
assert isinstance(session, Session)

try: session.execute("ALTER TABLE livedesk_post CHANGE COLUMN `id_change` `id_change` BIGINT UNSIGNED")
except (ProgrammingError, OperationalError): pass

session.commit()
session.close()

# --------------------------------------------------------------------

@app.populate
def upgradeUser():
creator = alchemySessionCreator()
Expand Down Expand Up @@ -512,4 +526,4 @@ def upgradeSeoChangedOnFix():
try:
session.execute("ALTER TABLE `livedesk_blog_seo` ADD COLUMN `changed_on` DATETIME NULL DEFAULT NULL")
except (Exception): pass


4 changes: 2 additions & 2 deletions plugins/livedesk/livedesk/meta/blog_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from ..api.blog_post import BlogPost
from livedesk.meta.blog import BlogMapped
from sqlalchemy.dialects.mysql.base import INTEGER
from sqlalchemy.dialects.mysql.base import BIGINT
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.schema import Column, ForeignKey
Expand All @@ -30,7 +30,7 @@ class BlogPostDefinition:
__tablename__ = 'livedesk_post'
__table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8')

CId = declared_attr(lambda cls: Column('id_change', INTEGER(unsigned=True)))
CId = declared_attr(lambda cls: Column('id_change', BIGINT(unsigned=True)))
Blog = declared_attr(lambda cls: Column('fk_blog_id', ForeignKey(BlogMapped.Id), nullable=False))
Order = declared_attr(lambda cls: Column('ordering', REAL))
# Non REST model attribute --------------------------------------
Expand Down
31 changes: 31 additions & 0 deletions plugins/superdesk-user/__plugin__/superdesk_user/upgrade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'''
Created on July 7, 2014
@package: superdesk user
@copyright: 2014 Sourcefabric o.p.s.
@license: http://www.gnu.org/licenses/gpl-3.0.txt
@author: Martin Saturka
Contains upgrade functions
'''

from ..superdesk.db_superdesk import alchemySessionCreator
from ally.container import app
from sqlalchemy.exc import ProgrammingError, OperationalError
from sqlalchemy.orm.session import Session
from ally.container.app import PRIORITY_LAST

# --------------------------------------------------------------------

@app.populate(priority=PRIORITY_LAST)
def upgradeUserCid():
creator = alchemySessionCreator()
session = creator()
assert isinstance(session, Session)

try: session.execute("ALTER TABLE user CHANGE COLUMN `cid` `cid` BIGINT UNSIGNED DEFAULT 0")
except (ProgrammingError, OperationalError): pass

session.commit()
session.close()

4 changes: 2 additions & 2 deletions plugins/superdesk-user/superdesk/user/meta/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from sqlalchemy.orm import relationship
from sqlalchemy.ext.associationproxy import association_proxy
from superdesk.person.meta.person import PersonMapped
from sqlalchemy.dialects.mysql.base import INTEGER
from sqlalchemy.dialects.mysql.base import BIGINT

# --------------------------------------------------------------------

Expand All @@ -33,7 +33,7 @@ class UserMapped(PersonMapped, User):

Name = Column('name', String(150), nullable=False, unique=True)
Uuid = Column('uuid', String(32), unique=True, nullable=True)
Cid = Column('cid', INTEGER(unsigned=True), nullable=True, default=0)
Cid = Column('cid', BIGINT(unsigned=True), nullable=True, default=0)
CreatedOn = Column('created_on', DateTime, nullable=False)
Active = Column('active', Boolean, nullable=False, default=True)
Type = association_proxy('type', 'Key')
Expand Down

0 comments on commit 000de65

Please sign in to comment.