diff --git a/src/NzbDrone.Core/Datastore/Migration/148_remove_extra_naming_config.cs b/src/NzbDrone.Core/Datastore/Migration/148_remove_extra_naming_config.cs new file mode 100644 index 000000000..a5b41cb68 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/148_remove_extra_naming_config.cs @@ -0,0 +1,15 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(148)] + public class remove_extra_naming_config : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + // Remove all but 1 NamingConfig + Execute.Sql("DELETE FROM NamingConfig WHERE ID NOT IN(SELECT ID FROM NamingConfig LIMIT 1)"); + } + } +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 688604d79..0e225f074 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -125,6 +125,7 @@ + diff --git a/src/NzbDrone.Core/Organizer/NamingConfigService.cs b/src/NzbDrone.Core/Organizer/NamingConfigService.cs index 1cbe993dc..8cd9d3234 100644 --- a/src/NzbDrone.Core/Organizer/NamingConfigService.cs +++ b/src/NzbDrone.Core/Organizer/NamingConfigService.cs @@ -21,8 +21,16 @@ namespace NzbDrone.Core.Organizer if (config == null) { - _repository.Insert(NamingConfig.Default); - config = _repository.Single(); + lock (_repository) + { + config = _repository.SingleOrDefault(); + + if (config == null) + { + _repository.Insert(NamingConfig.Default); + config = _repository.Single(); + } + } } return config; @@ -33,4 +41,4 @@ namespace NzbDrone.Core.Organizer _repository.Upsert(namingConfig); } } -} \ No newline at end of file +}