[PATCH 2 of 8 v2] database: drafts: add draft column in changesetcomment table

Jan Heylen heyleke at gmail.com
Sat May 16 08:02:27 EDT 2015


# HG changeset patch
# User Jan Heylen <heyleke at gmail.com>
# Date 1430814921 -7200
#      Tue May 05 10:35:21 2015 +0200
# Node ID dc6bb39a25a624034be795d083a118009f903d31
# Parent  4fad09a8ca22ff3ec15ceb46383e0d534682e048
database: drafts: add draft column in changesetcomment table

+ migration script to add the column to an existing database
+ server_default allows downgrades without user interaction
  without breaking the database
+ added database index

diff -r 4fad09a8ca22 -r dc6bb39a25a6 kallithea/__init__.py
--- a/kallithea/__init__.py	Mon May 04 21:07:37 2015 +0200
+++ b/kallithea/__init__.py	Tue May 05 10:35:21 2015 +0200
@@ -76,7 +76,7 @@
     pass
 
 __version__ = ('.'.join((str(each) for each in VERSION[:3])))
-__dbversion__ = 31  # defines current db version for migrations
+__dbversion__ = 32  # defines current db version for migrations
 __platform__ = platform.system()
 __license__ = 'GPLv3'
 __py_version__ = sys.version_info
diff -r 4fad09a8ca22 -r dc6bb39a25a6 kallithea/lib/dbmigrate/versions/032_version_2_2_3.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kallithea/lib/dbmigrate/versions/032_version_2_2_3.py	Tue May 05 10:35:21 2015 +0200
@@ -0,0 +1,32 @@
+import logging
+
+from sqlalchemy import *
+
+from kallithea.lib.dbmigrate.migrate import *
+from kallithea.lib.dbmigrate.migrate.changeset import *
+
+log = logging.getLogger(__name__)
+
+
+def upgrade(migrate_engine):
+    """ Upgrade operations go here.
+    Don't create your own engine; bind migrate_engine to your metadata
+    """
+
+    #==========================================================================
+    # Upgrade of `changeset_comments` table
+    #==========================================================================
+    tblname = 'changeset_comments'
+    tbl = Table(tblname, MetaData(bind=migrate_engine), autoload=True,
+                    autoload_with=migrate_engine)
+
+    #ADD draft column
+    draft = Column("draft", Boolean, default=False, server_default='0')
+    draft.create(tbl, populate_default=True)
+    draft.alter(nullable=False)
+    return
+
+
+def downgrade(migrate_engine):
+    meta = MetaData()
+    meta.bind = migrate_engine
diff -r 4fad09a8ca22 -r dc6bb39a25a6 kallithea/model/comment.py
--- a/kallithea/model/comment.py	Mon May 04 21:07:37 2015 +0200
+++ b/kallithea/model/comment.py	Tue May 05 10:35:21 2015 +0200
@@ -180,6 +180,7 @@
         comment.text = text
         comment.f_path = f_path
         comment.line_no = line_no
+        comment.draft = False
 
         if revision:
             comment.revision = revision
diff -r 4fad09a8ca22 -r dc6bb39a25a6 kallithea/model/db.py
--- a/kallithea/model/db.py	Mon May 04 21:07:37 2015 +0200
+++ b/kallithea/model/db.py	Tue May 05 10:35:21 2015 +0200
@@ -2142,6 +2142,7 @@
     __table_args__ = (
         Index('cc_revision_idx', 'revision'),
         Index('cc_pull_request_id_idx', 'pull_request_id'),
+        Index('cc_draft_idx', 'draft'),
         {'extend_existing': True, 'mysql_engine': 'InnoDB',
          'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
     )
@@ -2156,6 +2157,7 @@
     text = Column(UnicodeText(25000), nullable=False)
     created_on = Column(DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
     modified_at = Column(DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
+    draft = Column(Boolean, default=False, server_default='0')
 
     author = relationship('User')
     repo = relationship('Repository')


More information about the kallithea-general mailing list