Add date fields to songs

This commit is contained in:
Tim Bentley 2011-08-26 13:02:06 +01:00
parent cc92bf7028
commit 1adac78588
2 changed files with 19 additions and 5 deletions

View File

@ -31,6 +31,7 @@ the Songs plugin
from sqlalchemy import Column, ForeignKey, Table, types from sqlalchemy import Column, ForeignKey, Table, types
from sqlalchemy.orm import mapper, relation from sqlalchemy.orm import mapper, relation
from sqlalchemy.sql.expression import func
from openlp.core.lib.db import BaseModel, init_db 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'song_number', types.Unicode(64)),
Column(u'theme_name', types.Unicode(128)), Column(u'theme_name', types.Unicode(128)),
Column(u'search_title', types.Unicode(255), index=True, nullable=False), 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 # Definition of the "topics" table

View File

@ -25,15 +25,16 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # 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 :mod:`upgrade` module provides a way for the database and schema that is the
the Songs plugin backend for the Songs plugin
""" """
from sqlalchemy import Column, ForeignKey, Table, types from sqlalchemy import Column, ForeignKey, Table, types
from sqlalchemy.sql.expression import func
from migrate import changeset from migrate import changeset
from migrate.changeset.constraint import ForeignKeyConstraint from migrate.changeset.constraint import ForeignKeyConstraint
__version__ = 1 __version__ = 2
def upgrade_setup(metadata): def upgrade_setup(metadata):
""" """
@ -57,7 +58,7 @@ def upgrade_1(session, metadata, tables):
""" """
Version 1 upgrade. 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 media_files and replaces it with a one-to-many, which is far more
representative of the real relationship between the two entities. 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'], ForeignKeyConstraint([u'song_id'], [u'songs.id'],
table=tables[u'media_files']).create() 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)