Create table indices after table upgrades

This commit is contained in:
JonnyWong16 2017-07-26 15:42:27 -07:00
commit 81dca01302

View file

@ -547,9 +547,6 @@ def dbcheck():
'rating_key INTEGER, thetvdb_id INTEGER, imdb_id TEXT, '
'tvmaze_id INTEGER, tvmaze_url TEXT, tvmaze_json TEXT)'
)
c_db.execute(
'CREATE UNIQUE INDEX IF NOT EXISTS idx_tvmaze_lookup ON tvmaze_lookup (rating_key)'
)
# themoviedb_lookup table :: This table keeps record of the TheMovieDB lookups
c_db.execute(
@ -557,9 +554,6 @@ def dbcheck():
'rating_key INTEGER, thetvdb_id INTEGER, imdb_id TEXT, '
'themoviedb_id INTEGER, themoviedb_url TEXT, themoviedb_json TEXT)'
)
c_db.execute(
'CREATE UNIQUE INDEX IF NOT EXISTS idx_themoviedb_lookup ON themoviedb_lookup (rating_key)'
)
# Upgrade sessions table from earlier versions
try:
@ -1109,10 +1103,10 @@ def dbcheck():
'ALTER TABLE tvmaze_lookup ADD COLUMN rating_key INTEGER'
)
c_db.execute(
'DROP INDEX idx_tvmaze_lookup_thetvdb_id'
'DROP INDEX IF EXISTS idx_tvmaze_lookup_thetvdb_id'
)
c_db.execute(
'DROP INDEX idx_tvmaze_lookup_imdb_id'
'DROP INDEX IF EXISTS idx_tvmaze_lookup_imdb_id'
)
# Upgrade themoviedb_lookup table from earlier versions
@ -1124,10 +1118,10 @@ def dbcheck():
'ALTER TABLE themoviedb_lookup ADD COLUMN rating_key INTEGER'
)
c_db.execute(
'DROP INDEX idx_themoviedb_lookup_thetvdb_id'
'DROP INDEX IF EXISTS idx_themoviedb_lookup_thetvdb_id'
)
c_db.execute(
'DROP INDEX idx_themoviedb_lookup_imdb_id'
'DROP INDEX IF EXISTS idx_themoviedb_lookup_imdb_id'
)
# Add "Local" user to database as default unauthenticated user.
@ -1135,6 +1129,14 @@ def dbcheck():
if not result.fetchone():
logger.debug(u"User 'Local' does not exist. Adding user.")
c_db.execute('INSERT INTO users (user_id, username) VALUES (0, "Local")')
# Create table indices
c_db.execute(
'CREATE UNIQUE INDEX IF NOT EXISTS idx_tvmaze_lookup ON tvmaze_lookup (rating_key)'
)
c_db.execute(
'CREATE UNIQUE INDEX IF NOT EXISTS idx_themoviedb_lookup ON themoviedb_lookup (rating_key)'
)
conn_db.commit()
c_db.close()