diff --git a/openlp/plugins/songs/lib/db.py b/openlp/plugins/songs/lib/db.py index bee64b3ba..13ce24266 100644 --- a/openlp/plugins/songs/lib/db.py +++ b/openlp/plugins/songs/lib/db.py @@ -31,6 +31,7 @@ the Songs plugin 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 @@ def init_schema(url): 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 diff --git a/openlp/plugins/songs/lib/upgrade.py b/openlp/plugins/songs/lib/upgrade.py index e0f2668d9..fae3400c2 100644 --- a/openlp/plugins/songs/lib/upgrade.py +++ b/openlp/plugins/songs/lib/upgrade.py @@ -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 @@ def upgrade_1(session, metadata, tables): """ 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 @@ def upgrade_1(session, metadata, tables): 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)