Skip to content

Commit

Permalink
Fix creation of unique index for url and remove wrong ones
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandog committed Mar 7, 2016
1 parent b9fbfe3 commit 579839f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sickbeard/tvcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,22 @@ def __init__(self, providerName):
# Create the table if it's not already there
try:
if not self.hasTable(providerName):
logger.log(u"Creating cache table for provider {}".format(providerName), logger.DEBUG)
self.action(
"CREATE TABLE [" + providerName + "] (name TEXT, season NUMERIC, episodes TEXT, indexerid NUMERIC, url TEXT UNIQUE, time NUMERIC, quality TEXT, release_group TEXT)")
"CREATE TABLE [" + providerName + "] (name TEXT, season NUMERIC, episodes TEXT, indexerid NUMERIC, url TEXT, time NUMERIC, quality TEXT, release_group TEXT)")
else:
sql_results = self.select("SELECT url, COUNT(url) AS count FROM [" + providerName + "] GROUP BY url HAVING count > 1")

for cur_dupe in sql_results:
self.action("DELETE FROM [" + providerName + "] WHERE url = ?", [cur_dupe["url"]])

# remove wrong old index
logger.log(u"Deleting wrong idx_url index for {}".format(providerName), logger.DEBUG)
self.action("DROP UNIQUE INDEX IF EXISTS idx_url ON [" + providerName + "] (url)")

# add unique index to prevent further dupes from happening if one does not exist
self.action("CREATE UNIQUE INDEX IF NOT EXISTS idx_url ON [" + providerName + "] (url)")
logger.log(u"Creating UNIQUE URL index for {}".format(providerName), logger.DEBUG)
self.action("CREATE UNIQUE INDEX IF NOT EXISTS idx_url_" + providerName + " ON [" + providerName + "] (url)")

# add release_group column to table if missing
if not self.hasColumn(providerName, 'release_group'):
Expand Down

0 comments on commit 579839f

Please sign in to comment.