forked from openlp/openlp
Add fields to database
This commit is contained in:
parent
727a275bb6
commit
f266485001
@ -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,
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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)
|
||||
|
61
openlp/plugins/songusage/lib/upgrade.py
Normal file
61
openlp/plugins/songusage/lib/upgrade.py
Normal file
@ -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)
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user