openlp/openlp/core/projectors/upgrade.py

95 lines
4.1 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2019-02-14 15:09:09 +00:00
# Copyright (c) 2008-2019 OpenLP Developers #
# --------------------------------------------------------------------------- #
# 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
2017-05-30 23:26:37 +00:00
backend for the projector setup.
"""
import logging
2018-10-02 04:39:42 +00:00
from sqlalchemy import Column, Table, types
from sqlalchemy.sql.expression import null
from openlp.core.lib.db import get_upgrade_op
2018-10-02 04:39:42 +00:00
log = logging.getLogger(__name__)
# Initial projector DB was unversioned
2018-01-13 05:41:42 +00:00
__version__ = 3
log.debug('Projector DB upgrade module loading')
def upgrade_1(session, metadata):
"""
Version 1 upgrade - old db might/might not be versioned.
"""
2017-08-06 07:23:26 +00:00
log.debug('Skipping projector DB upgrade to version 1 - not used')
def upgrade_2(session, metadata):
"""
Version 2 upgrade.
Update Projector() table to include new data defined in PJLink version 2 changes
2017-06-09 12:12:39 +00:00
mac_adx: Column(String(18))
serial_no: Column(String(30))
sw_version: Column(String(30))
model_filter: Column(String(30))
model_lamp: Column(String(30))
:param session: DB session instance
:param metadata: Metadata of current DB
"""
2017-08-06 07:23:26 +00:00
log.debug('Checking projector DB upgrade to version 2')
2017-06-09 12:12:39 +00:00
projector_table = Table('projector', metadata, autoload=True)
2017-08-06 07:23:26 +00:00
upgrade_db = 'mac_adx' not in [col.name for col in projector_table.c.values()]
if upgrade_db:
2017-06-09 12:12:39 +00:00
new_op = get_upgrade_op(session)
2017-06-01 22:35:57 +00:00
new_op.add_column('projector', Column('mac_adx', types.String(18), server_default=null()))
new_op.add_column('projector', Column('serial_no', types.String(30), server_default=null()))
new_op.add_column('projector', Column('sw_version', types.String(30), server_default=null()))
new_op.add_column('projector', Column('model_filter', types.String(30), server_default=null()))
new_op.add_column('projector', Column('model_lamp', types.String(30), server_default=null()))
2017-08-06 07:23:26 +00:00
log.debug('{status} projector DB upgrade to version 2'.format(status='Updated' if upgrade_db else 'Skipping'))
2018-01-13 05:41:42 +00:00
def upgrade_3(session, metadata):
"""
Version 3 upgrade.
Update Projector() table to inlcude PJLink class as part of record.
pjlink_version: Column(String(1))
:param session: DB Session instance
:param metadata: Metadata of current DB
"""
log.debug('Checking projector DB upgrade to version 3')
projector_table = Table('projector', metadata, autoload=True)
upgrade_db = 'pjlink_class' not in [col.name for col in projector_table.c.values()]
if upgrade_db:
new_op = get_upgrade_op(session)
2018-01-13 07:17:15 +00:00
new_op.add_column('projector', Column('pjlink_class', types.String(5), server_default=null()))
2018-01-13 05:41:42 +00:00
log.debug('{status} projector DB upgrade to version 3'.format(status='Updated' if upgrade_db else 'Skipping'))