You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1004 B
26 lines
1004 B
using FluentMigrator;
|
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
|
|
|
namespace NzbDrone.Core.Datastore.Migration
|
|
{
|
|
[Migration(31)]
|
|
public class add_artistmetadataid_constraint : NzbDroneMigrationBase
|
|
{
|
|
protected override void MainDbUpgrade()
|
|
{
|
|
// Remove any duplicate artists
|
|
Execute.Sql(@"DELETE FROM ""Artists""
|
|
WHERE ""Id"" NOT IN (
|
|
SELECT MIN(""Artists"".""Id"") from ""Artists""
|
|
JOIN ""ArtistMetadata"" ON ""Artists"".""ArtistMetadataId"" = ""ArtistMetadata"".""Id""
|
|
GROUP BY ""ArtistMetadata"".""Id"")");
|
|
|
|
// The index exists but will be recreated as part of unique constraint
|
|
Delete.Index().OnTable("Artists").OnColumn("ArtistMetadataId");
|
|
|
|
// Add a constraint to prevent any more duplicates
|
|
Alter.Column("ArtistMetadataId").OnTable("Artists").AsInt32().Unique();
|
|
}
|
|
}
|
|
}
|