← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~trb143/openlp/bug-815313 into lp:openlp

 

Tim Bentley has proposed merging lp:~trb143/openlp/bug-815313 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #815313 in OpenLP: "Add created_date and updated_date fields to all tables"
  https://bugs.launchpad.net/openlp/+bug/815313

For more details, see:
https://code.launchpad.net/~trb143/openlp/bug-815313/+merge/73040

Adds two dates to the song database.
Sets up the initial values on creation
Updates the updated value when changes happen.

Tested on a changed database (Raouls)
Tested on a clean database (Raouls and mine)
Editied a song
Added and edited a song.
-- 
https://code.launchpad.net/~trb143/openlp/bug-815313/+merge/73040
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/bug-815313 into lp:openlp.
=== modified file 'openlp/plugins/songs/lib/db.py'
--- openlp/plugins/songs/lib/db.py	2011-08-25 09:22:48 +0000
+++ openlp/plugins/songs/lib/db.py	2011-08-26 12:54:03 +0000
@@ -31,6 +31,7 @@
 
 from sqlalchemy import Column, ForeignKey, Table, types
 from sqlalchemy.orm import mapper, relation
+from sqlalchemy.sql.expression import func
 
 from openlp.core.lib.db import BaseModel, init_db
 
@@ -195,7 +196,9 @@
         Column(u'song_number', types.Unicode(64)),
         Column(u'theme_name', types.Unicode(128)),
         Column(u'search_title', types.Unicode(255), index=True, nullable=False),
-        Column(u'search_lyrics', types.UnicodeText, nullable=False)
+        Column(u'search_lyrics', types.UnicodeText, nullable=False),
+        Column(u'create_date', types.DateTime(), default=func.now()),
+        Column(u'last_modified', types.DateTime(), onupdate=func.now())
     )
 
     # Definition of the "topics" table

=== modified file 'openlp/plugins/songs/lib/upgrade.py'
--- openlp/plugins/songs/lib/upgrade.py	2011-08-25 20:14:02 +0000
+++ openlp/plugins/songs/lib/upgrade.py	2011-08-26 12:54:03 +0000
@@ -25,15 +25,16 @@
 # Temple Place, Suite 330, Boston, MA 02111-1307 USA                          #
 ###############################################################################
 """
-The :mod:`upgrade` module provides a way for the database and schema that is the backend for
-the Songs plugin
+The :mod:`upgrade` module provides a way for the database and schema that is the
+backend for the Songs plugin
 """
 
 from sqlalchemy import Column, ForeignKey, Table, types
+from sqlalchemy.sql.expression import func
 from migrate import changeset
 from migrate.changeset.constraint import ForeignKeyConstraint
 
-__version__ = 1
+__version__ = 2
 
 def upgrade_setup(metadata):
     """
@@ -57,7 +58,7 @@
     """
     Version 1 upgrade.
 
-    This upgrade removes the many-to-many relationship between songs and 
+    This upgrade removes the many-to-many relationship between songs and
     media_files and replaces it with a one-to-many, which is far more
     representative of the real relationship between the two entities.
 
@@ -75,3 +76,13 @@
         ForeignKeyConstraint([u'song_id'], [u'songs.id'],
             table=tables[u'media_files']).create()
 
+def upgrade_2(session, metadata, tables):
+    """
+    Version 2 upgrade.
+
+    This upgrade adds a create_date and last_modified date to the songs table
+    """
+    Column(u'create_date', types.DateTime(), default=func.now())\
+        .create(table=tables[u'songs'], populate_default=True)
+    Column(u'last_modified', types.DateTime(), default=func.now())\
+        .create(table=tables[u'songs'], populate_default=True)