From f266485001f809f5ee46457dcb90a61f93cce7b8 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 26 Aug 2011 18:56:36 +0100 Subject: [PATCH] Add fields to database --- openlp/core/lib/db.py | 1 + openlp/plugins/songs/lib/upgrade.py | 6 +- openlp/plugins/songusage/lib/db.py | 4 +- openlp/plugins/songusage/lib/upgrade.py | 61 +++++++++++++++++++++ openlp/plugins/songusage/songusageplugin.py | 5 +- 5 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 openlp/plugins/songusage/lib/upgrade.py diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index fb8a38b1f..2c504c3ae 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -72,6 +72,7 @@ def upgrade_db(url, upgrade): ``upgrade`` The python module that contains the upgrade instructions. """ + print url, upgrade session, metadata = init_db(url) tables = upgrade.upgrade_setup(metadata) metadata_table = Table(u'metadata', metadata, diff --git a/openlp/plugins/songs/lib/upgrade.py b/openlp/plugins/songs/lib/upgrade.py index e0f2668d9..a7aa1bd6c 100644 --- a/openlp/plugins/songs/lib/upgrade.py +++ b/openlp/plugins/songs/lib/upgrade.py @@ -25,8 +25,8 @@ # 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 @@ -57,7 +57,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. diff --git a/openlp/plugins/songusage/lib/db.py b/openlp/plugins/songusage/lib/db.py index 9a11ef16b..bbd645634 100644 --- a/openlp/plugins/songusage/lib/db.py +++ b/openlp/plugins/songusage/lib/db.py @@ -56,7 +56,9 @@ def init_schema(url): Column(u'title', types.Unicode(255), nullable=False), Column(u'authors', types.Unicode(255), nullable=False), Column(u'copyright', types.Unicode(255)), - Column(u'ccl_number', types.Unicode(65)) + Column(u'ccl_number', types.Unicode(65)), + Column(u'plugin_name', types.Unicode(20)), + Column(u'source', types.Unicode(10)) ) mapper(SongUsageItem, songusage_table) diff --git a/openlp/plugins/songusage/lib/upgrade.py b/openlp/plugins/songusage/lib/upgrade.py new file mode 100644 index 000000000..cdae3b694 --- /dev/null +++ b/openlp/plugins/songusage/lib/upgrade.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2011 Raoul Snyman # +# Portions copyright (c) 2008-2011 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, # +# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias # +# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# 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 SongsUsage plugin +""" + +from sqlalchemy import Column, ForeignKey, Table, types +from migrate import changeset +from migrate.changeset.constraint import ForeignKeyConstraint + +__version__ = 1 + +def upgrade_setup(metadata): + """ + Set up the latest revision all tables, with reflection, needed for the + upgrade process. If you want to drop a table, you need to remove it from + here, and add it to your upgrade function. + """ + tables = { + u'songusage_data': Table(u'songusage_data', metadata, autoload=True) + } + print tables + return tables + + +def upgrade_1(session, metadata, tables): + """ + Version 1 upgrade. + + This upgrade adds two new fields to the songusage database + """ + print "hi" + Column(u'plugin_name', types.Unicode(20), default=u'') \ + .create(table=tables[u'songusage_data'], populate_default=True) + Column(u'source', types.Unicode(10), default=u'') \ + .create(table=tables[u'songusage_data'], populate_default=True) diff --git a/openlp/plugins/songusage/songusageplugin.py b/openlp/plugins/songusage/songusageplugin.py index b39fe1a33..1a0335d67 100644 --- a/openlp/plugins/songusage/songusageplugin.py +++ b/openlp/plugins/songusage/songusageplugin.py @@ -37,6 +37,7 @@ from openlp.core.lib.ui import base_action, shortcut_action from openlp.core.utils.actions import ActionList from openlp.plugins.songusage.forms import SongUsageDetailForm, \ SongUsageDeleteForm +from openlp.plugins.songusage.lib import upgrade from openlp.plugins.songusage.lib.db import init_schema, SongUsageItem log = logging.getLogger(__name__) @@ -46,11 +47,11 @@ class SongUsagePlugin(Plugin): def __init__(self, plugin_helpers): Plugin.__init__(self, u'songusage', plugin_helpers) + self.manager = Manager(u'songusage', init_schema, upgrade_mod=upgrade) self.weight = -4 self.icon = build_icon(u':/plugins/plugin_songusage.png') self.activeIcon = build_icon(u':/songusage/song_usage_active.png') self.inactiveIcon = build_icon(u':/songusage/song_usage_inactive.png') - self.manager = None self.songUsageActive = False def addToolsMenuItem(self, tools_menu): @@ -137,8 +138,6 @@ class SongUsagePlugin(Plugin): translate('SongUsagePlugin', 'Song Usage')) action_list.add_action(self.songUsageReport, translate('SongUsagePlugin', 'Song Usage')) - if self.manager is None: - self.manager = Manager(u'songusage', init_schema) self.songUsageDeleteForm = SongUsageDeleteForm(self.manager, self.formparent) self.songUsageDetailForm = SongUsageDetailForm(self, self.formparent)