Commit 81c2da37 authored by echel0n's avatar echel0n
Browse files

Bumped PyYaml

Bumped SQLAlchemy
Bumped SQLAlchemy-Utils
Added Greenlet v1.1.2 to requirements.txt
Refactored misc SQLAlchemy code to the latest spec
Bumped main database to v23
Bumped config database to v11
Bumped cache database to v6
parent 38653833
...@@ -30,6 +30,7 @@ fake-useragent==0.1.11 ...@@ -30,6 +30,7 @@ fake-useragent==0.1.11
feedparser==6.0.8 feedparser==6.0.8
future==0.18.2 future==0.18.2
gntp==1.0.3 gntp==1.0.3
greenlet==1.1.2
guessit==3.1.1 guessit==3.1.1
hachoir==3.1.1 hachoir==3.1.1
html5lib==1.1 html5lib==1.1
...@@ -73,7 +74,7 @@ python-keycloak-client==0.2.3 ...@@ -73,7 +74,7 @@ python-keycloak-client==0.2.3
python-twitter==3.5 python-twitter==3.5
pytz==2020.1 pytz==2020.1
pyxdg==0.26 pyxdg==0.26
PyYAML==5.3.1 PyYAML==5.4.1
rarfile==3.1 rarfile==3.1
rebulk==2.0.1 rebulk==2.0.1
requests==2.24.0 requests==2.24.0
...@@ -87,8 +88,8 @@ sgmllib3k==1.0.0 ...@@ -87,8 +88,8 @@ sgmllib3k==1.0.0
simplejson==3.17.2 simplejson==3.17.2
six==1.15.0 six==1.15.0
soupsieve==2.0.1 soupsieve==2.0.1
SQLAlchemy==1.3.18 SQLAlchemy==1.4.32
SQLAlchemy-Utils==0.36.8 SQLAlchemy-Utils==0.38.2
stevedore==3.2.0 stevedore==3.2.0
subliminal==2.1.0 subliminal==2.1.0
tornado==6.1 tornado==6.1
......
This diff is collapsed.
...@@ -31,13 +31,12 @@ from alembic.runtime.migration import MigrationContext ...@@ -31,13 +31,12 @@ from alembic.runtime.migration import MigrationContext
from alembic.script import ScriptDirectory from alembic.script import ScriptDirectory
from attrdict import AttrDict from attrdict import AttrDict
from sqlalchemy import create_engine, event, inspect, MetaData, Index, TypeDecorator from sqlalchemy import create_engine, event, inspect, MetaData, Index, TypeDecorator
from sqlalchemy.engine import Engine, reflection from sqlalchemy.engine import Engine, reflection, Row
from sqlalchemy.exc import OperationalError from sqlalchemy.exc import OperationalError
from sqlalchemy.ext.automap import automap_base from sqlalchemy.ext.automap import automap_base
from sqlalchemy.ext.serializer import loads, dumps from sqlalchemy.ext.serializer import loads, dumps
from sqlalchemy.orm import sessionmaker, mapper, scoped_session from sqlalchemy.orm import sessionmaker, mapper, scoped_session
from sqlalchemy.sql.ddl import CreateTable, CreateIndex from sqlalchemy.sql.ddl import CreateTable, CreateIndex
from sqlalchemy.util import KeyedTuple
import sickrage import sickrage
...@@ -169,12 +168,12 @@ class SRDatabase(object): ...@@ -169,12 +168,12 @@ class SRDatabase(object):
return current_rev return current_rev
def setup(self): def setup(self):
if self.engine.dialect.has_table(self.engine, 'migrate_version'): if inspect(self.engine).has_table('migrate_version'):
migrate_version = self.engine.execute("select version from migrate_version").fetchone().version migrate_version = self.engine.execute("select version from migrate_version").fetchone().version
alembic.command.stamp(self.get_alembic_config(), str(migrate_version)) alembic.command.stamp(self.get_alembic_config(), str(migrate_version))
self.engine.execute("drop table migrate_version") self.engine.execute("drop table migrate_version")
if not self.engine.dialect.has_table(self.engine, 'alembic_version'): if not inspect(self.engine).has_table('alembic_version'):
alembic.command.stamp(self.get_alembic_config(), 'head') alembic.command.stamp(self.get_alembic_config(), 'head')
sickrage.app.log.info("Performing initialization on {} database".format(self.name)) sickrage.app.log.info("Performing initialization on {} database".format(self.name))
self.initialize() self.initialize()
...@@ -207,7 +206,7 @@ class SRDatabase(object): ...@@ -207,7 +206,7 @@ class SRDatabase(object):
if db_version < alembic_version: if db_version < alembic_version:
# temp code to resolve a migration bug introduced from v10.0.0, fixed in v10.0.2+ # temp code to resolve a migration bug introduced from v10.0.0, fixed in v10.0.2+
if db_version < 21 and self.name == 'main': if db_version < 21 and self.name == 'main':
if self.engine.dialect.has_table(self.engine, 'indexer_mapping') and self.engine.dialect.has_table(self.engine, 'series_provider_mapping'): if inspect(self.engine).has_table('indexer_mapping') and inspect(self.engine).has_table('series_provider_mapping'):
sickrage.app.log.debug('Found offending series_provider_mapping table, removing!') sickrage.app.log.debug('Found offending series_provider_mapping table, removing!')
metadata = MetaData(self.engine, reflect=True) metadata = MetaData(self.engine, reflect=True)
table = metadata.tables.get('series_provider_mapping') table = metadata.tables.get('series_provider_mapping')
...@@ -227,7 +226,9 @@ class SRDatabase(object): ...@@ -227,7 +226,9 @@ class SRDatabase(object):
return config return config
def get_metadata(self): def get_metadata(self):
return MetaData(bind=self.engine, reflect=True) metadata_obj = MetaData(bind=self.engine)
metadata_obj.reflect()
return metadata_obj
def get_base(self): def get_base(self):
base = automap_base(metadata=self.get_metadata()) base = automap_base(metadata=self.get_metadata())
...@@ -274,6 +275,18 @@ class SRDatabase(object): ...@@ -274,6 +275,18 @@ class SRDatabase(object):
with open(filename, 'rb') as fh: with open(filename, 'rb') as fh:
backup_dict = pickle.load(fh) backup_dict = pickle.load(fh)
backup_version = int(backup_dict['version'])
restore_version_matrix = {
'main': 23,
'cache': 11,
'config': 6
}
if not backup_version >= restore_version_matrix[self.name]:
sickrage.app.log.warning(f'Backup v{backup_version} for {self.name} database cannot be restored, needs to be restored with an '
f'older copy of SiCKRAGE.')
return
# drop all tables # drop all tables
self.get_base().metadata.drop_all() self.get_base().metadata.drop_all()
...@@ -304,7 +317,7 @@ class SRDatabase(object): ...@@ -304,7 +317,7 @@ class SRDatabase(object):
rows = [] rows = []
for row in loads(data, meta, session): for row in loads(data, meta, session):
if isinstance(row, KeyedTuple): if isinstance(row, Row):
rows.append(row._asdict()) rows.append(row._asdict())
session.bulk_insert_mappings(table, rows) session.bulk_insert_mappings(table, rows)
session.commit() session.commit()
...@@ -9,6 +9,8 @@ import sqlalchemy as sa ...@@ -9,6 +9,8 @@ import sqlalchemy as sa
from alembic import op from alembic import op
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
from sqlalchemy import inspect
revision = '8' revision = '8'
down_revision = '7' down_revision = '7'
...@@ -17,10 +19,10 @@ def upgrade(): ...@@ -17,10 +19,10 @@ def upgrade():
conn = op.get_bind() conn = op.get_bind()
meta = sa.MetaData(bind=conn) meta = sa.MetaData(bind=conn)
if conn.engine.dialect.has_table(conn.engine, 'quicksearch_shows'): if inspect(conn).has_table('quicksearch_shows'):
op.drop_table('quicksearch_shows') op.drop_table('quicksearch_shows')
if conn.engine.dialect.has_table(conn.engine, 'quicksearch_episodes'): if inspect(conn).has_table('quicksearch_episodes'):
op.drop_table('quicksearch_episodes') op.drop_table('quicksearch_episodes')
......
...@@ -12,7 +12,7 @@ from json import JSONDecodeError ...@@ -12,7 +12,7 @@ from json import JSONDecodeError
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from keycloak.exceptions import KeycloakClientError from keycloak.exceptions import KeycloakClientError
from sqlalchemy import orm from sqlalchemy import orm, inspect
import sickrage import sickrage
...@@ -51,7 +51,7 @@ def upgrade(): ...@@ -51,7 +51,7 @@ def upgrade():
except (KeycloakClientError, orm.exc.NoResultFound): except (KeycloakClientError, orm.exc.NoResultFound):
pass pass
if conn.engine.dialect.has_table(conn.engine, 'oauth2_token'): if inspect(conn).has_table('oauth2_token'):
op.drop_table('oauth2_token') op.drop_table('oauth2_token')
......
"""Initial migration
Revision ID: 11
Revises:
Create Date: 2017-12-29 14:39:27.854291
"""
import json
import os
from json import JSONDecodeError
import sqlalchemy as sa
from alembic import op
from keycloak.exceptions import KeycloakClientError
from sqlalchemy import orm, inspect
import sickrage
# revision identifiers, used by Alembic.
from sickrage.core import ConfigDB
revision = '11'
down_revision = '10'
def upgrade():
pass
def downgrade():
# Operations to reverse the above upgrade go here.
pass
"""Initial migration
Revision ID: 6
Revises:
Create Date: 2017-12-29 14:39:27.854291
"""
import babelfish
from alembic import op
# revision identifiers, used by Alembic.
revision = '6'
down_revision = '5'
def upgrade():
pass
def downgrade():
pass
...@@ -9,6 +9,8 @@ import sqlalchemy as sa ...@@ -9,6 +9,8 @@ import sqlalchemy as sa
from alembic import op from alembic import op
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
from sqlalchemy import inspect
revision = '16' revision = '16'
down_revision = '15' down_revision = '15'
...@@ -17,7 +19,7 @@ def upgrade(): ...@@ -17,7 +19,7 @@ def upgrade():
conn = op.get_bind() conn = op.get_bind()
meta = sa.MetaData(bind=conn) meta = sa.MetaData(bind=conn)
if conn.engine.dialect.has_table(conn.engine, 'scene_numbering'): if inspect(conn).has_table('scene_numbering'):
scene_numbering = sa.Table('scene_numbering', meta, autoload=True) scene_numbering = sa.Table('scene_numbering', meta, autoload=True)
with op.get_context().begin_transaction(): with op.get_context().begin_transaction():
for row in conn.execute(scene_numbering.select()): for row in conn.execute(scene_numbering.select()):
......
"""Initial migration
Revision ID: 23
Revises:
Create Date: 2017-12-29 14:39:27.854291
"""
import babelfish
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = '23'
down_revision = '22'
def upgrade():
pass
def downgrade():
pass
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment