Remove upgrade code not needed since 2.2

This commit is contained in:
Philip Ridout 2016-08-21 12:04:18 +01:00
parent c763585250
commit dcd8d6f6b5

View File

@ -24,8 +24,6 @@ The :mod:`upgrade` module provides a way for the database and schema that is the
""" """
import logging import logging
from sqlalchemy import delete, func, insert, select
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
__version__ = 1 __version__ = 1
@ -35,166 +33,6 @@ def upgrade_1(session, metadata):
""" """
Version 1 upgrade. Version 1 upgrade.
This upgrade renames a number of keys to a single naming convention. This upgrade renamed a number of keys to a single naming convention.
""" """
metadata_table = metadata.tables['metadata'] log.info('No upgrades to perform')
# Copy "Version" to "name" ("version" used by upgrade system)
try:
session.execute(insert(metadata_table).values(
key='name',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'Version'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'Version'))
except:
log.exception('Exception when upgrading Version')
# Copy "Copyright" to "copyright"
try:
session.execute(insert(metadata_table).values(
key='copyright',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'Copyright'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'Copyright'))
except:
log.exception('Exception when upgrading Copyright')
# Copy "Permissions" to "permissions"
try:
session.execute(insert(metadata_table).values(
key='permissions',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'Permissions'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'Permissions'))
except:
log.exception('Exception when upgrading Permissions')
# Copy "Bookname language" to "book_name_language"
try:
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == 'Bookname language'
)
).scalar()
if value_count > 0:
session.execute(insert(metadata_table).values(
key='book_name_language',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'Bookname language'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'Bookname language'))
except:
log.exception('Exception when upgrading Bookname language')
# Copy "download source" to "download_source"
try:
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == 'download source'
)
).scalar()
log.debug('download source: {count}'.format(count=value_count))
if value_count > 0:
session.execute(insert(metadata_table).values(
key='download_source',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'download source'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'download source'))
except:
log.exception('Exception when upgrading download source')
# Copy "download name" to "download_name"
try:
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == 'download name'
)
).scalar()
log.debug('download name: {count}'.format(count=value_count))
if value_count > 0:
session.execute(insert(metadata_table).values(
key='download_name',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'download name'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'download name'))
except:
log.exception('Exception when upgrading download name')
# Copy "proxy server" to "proxy_server"
try:
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == 'proxy server'
)
).scalar()
log.debug('proxy server: {count}'.format(count=value_count))
if value_count > 0:
session.execute(insert(metadata_table).values(
key='proxy_server',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'proxy server'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'proxy server'))
except:
log.exception('Exception when upgrading proxy server')
# Copy "proxy username" to "proxy_username"
try:
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == 'proxy username'
)
).scalar()
log.debug('proxy username: {count}'.format(count=value_count))
if value_count > 0:
session.execute(insert(metadata_table).values(
key='proxy_username',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'proxy username'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'proxy username'))
except:
log.exception('Exception when upgrading proxy username')
# Copy "proxy password" to "proxy_password"
try:
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == 'proxy password'
)
).scalar()
log.debug('proxy password: {count}'.format(count=value_count))
if value_count > 0:
session.execute(insert(metadata_table).values(
key='proxy_password',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'proxy password'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'proxy password'))
except:
log.exception('Exception when upgrading proxy password')
try:
session.execute(delete(metadata_table).where(metadata_table.c.key == 'dbversion'))
except:
log.exception('Exception when deleting dbversion')
session.commit()