From d7bb1cdd88f2f19839d99ad7d6aece10ba60a815 Mon Sep 17 00:00:00 2001 From: Martin Saturka Date: Mon, 7 Jul 2014 16:26:52 +0200 Subject: [PATCH] lb-1822: big ints for cids of users and blog posts --- .../livedesk/__plugin__/livedesk/upgrade.py | 16 +++++++++- plugins/livedesk/livedesk/meta/blog_post.py | 4 +-- .../__plugin__/superdesk_user/upgrade.py | 31 +++++++++++++++++++ .../superdesk/user/meta/user.py | 4 +-- 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 plugins/superdesk-user/__plugin__/superdesk_user/upgrade.py diff --git a/plugins/livedesk/__plugin__/livedesk/upgrade.py b/plugins/livedesk/__plugin__/livedesk/upgrade.py index a9598e275..ae5452498 100644 --- a/plugins/livedesk/__plugin__/livedesk/upgrade.py +++ b/plugins/livedesk/__plugin__/livedesk/upgrade.py @@ -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() @@ -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 - \ No newline at end of file + diff --git a/plugins/livedesk/livedesk/meta/blog_post.py b/plugins/livedesk/livedesk/meta/blog_post.py index fc7441728..18fb0cf0f 100644 --- a/plugins/livedesk/livedesk/meta/blog_post.py +++ b/plugins/livedesk/livedesk/meta/blog_post.py @@ -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 @@ -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 -------------------------------------- diff --git a/plugins/superdesk-user/__plugin__/superdesk_user/upgrade.py b/plugins/superdesk-user/__plugin__/superdesk_user/upgrade.py new file mode 100644 index 000000000..9a8643f99 --- /dev/null +++ b/plugins/superdesk-user/__plugin__/superdesk_user/upgrade.py @@ -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() + diff --git a/plugins/superdesk-user/superdesk/user/meta/user.py b/plugins/superdesk-user/superdesk/user/meta/user.py index 448048f3e..119a6792a 100644 --- a/plugins/superdesk-user/superdesk/user/meta/user.py +++ b/plugins/superdesk-user/superdesk/user/meta/user.py @@ -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 # -------------------------------------------------------------------- @@ -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')