mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -07:00
Fix overwrite Tautulli database importing
This commit is contained in:
parent
95bdc000ca
commit
e999000102
1 changed files with 12 additions and 13 deletions
|
@ -78,12 +78,11 @@ def import_tautulli_db(database=None, method=None, backup=True):
|
|||
# Get the current number of used ids in the session_history table
|
||||
session_history_seq = db.select_single('SELECT seq FROM sqlite_sequence WHERE name = "session_history"')
|
||||
|
||||
if method == 'merge':
|
||||
# Create a temporary table so we can reindex session_history.reference_id after merging
|
||||
logger.info("Tautulli Database :: Creating temporary database table to re-index grouped session history.")
|
||||
db.action('CREATE TABLE IF NOT EXISTS temp (id INTEGER PRIMARY KEY, old_id, new_id)')
|
||||
db.action('INSERT INTO temp (old_id) SELECT id FROM import_db.session_history')
|
||||
db.action('UPDATE temp SET new_id = id + ?', [session_history_seq['seq']])
|
||||
# Create a temporary table so we can reindex session_history.reference_id
|
||||
logger.info("Tautulli Database :: Creating temporary database table to re-index grouped session history.")
|
||||
db.action('CREATE TABLE IF NOT EXISTS temp (id INTEGER PRIMARY KEY, old_id, new_id)')
|
||||
db.action('INSERT INTO temp (old_id) SELECT id FROM import_db.session_history')
|
||||
db.action('UPDATE temp SET new_id = id + ?', [session_history_seq['seq']])
|
||||
|
||||
# Keep track of all table columns so that duplicates can be removed after importing
|
||||
session_history_tables = ('session_history', 'session_history_metadata', 'session_history_media_info')
|
||||
|
@ -120,12 +119,12 @@ def import_tautulli_db(database=None, method=None, backup=True):
|
|||
|
||||
db.connection.execute('DETACH import_db')
|
||||
|
||||
if method == 'merge':
|
||||
# Reindex session_history.reference_id
|
||||
logger.info("Tautulli Database :: Re-indexing grouped session history.")
|
||||
db.action('UPDATE session_history SET reference_id = (SELECT new_id FROM temp WHERE old_id = reference_id)'
|
||||
'WHERE id > ?', [session_history_seq['seq']])
|
||||
# Reindex session_history.reference_id
|
||||
logger.info("Tautulli Database :: Re-indexing grouped session history.")
|
||||
db.action('UPDATE session_history SET reference_id = (SELECT new_id FROM temp WHERE old_id = reference_id)'
|
||||
'WHERE id > ?', [session_history_seq['seq']])
|
||||
|
||||
if method == 'merge':
|
||||
if session_history_columns:
|
||||
# Remove reference_id column from the list of session_history table columns to get unique rows
|
||||
columns = ', '.join([c for c in session_history_columns if c != 'reference_id'])
|
||||
|
@ -142,8 +141,8 @@ def import_tautulli_db(database=None, method=None, backup=True):
|
|||
db.action('DELETE FROM {table} WHERE id NOT IN '
|
||||
'(SELECT MIN(id) FROM {table} GROUP BY {columns})'.format(table=table, columns=columns))
|
||||
|
||||
logger.info("Tautulli Database :: Deleting temporary database table.")
|
||||
db.action('DROP TABLE temp')
|
||||
logger.info("Tautulli Database :: Deleting temporary database table.")
|
||||
db.action('DROP TABLE temp')
|
||||
|
||||
db.action('VACUUM')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue