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 authored and medariox committed Mar 8, 2016
1 parent dea4f6c commit 58fa733
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sickbeard/tvcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ 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
self.action("DROP INDEX IF EXISTS idx_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 58fa733

Please sign in to comment.