Created
February 7, 2013 13:43
-
-
Save nshaw/4731003 to your computer and use it in GitHub Desktop.
In 5.1.7, this index is unique (create unique index IX_3463D95B on JournalArticle (uuid_, groupId)) but in the client's database, it's showing as a non-unique index. So that explains why the duplicate entries are allowed in the database. This script will remove all old versions of JournalArticles and only retain the newest therefore satisfying t…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop index IX_3463D95B on JournalArticle; | |
create temporary table temp_ja | |
select * from ( | |
select groupId, articleId, uuid_, type_, max(version) as 'maxVersionId', count(id_) as 'countId' from JournalArticle ja | |
group by groupId, uuid_ | |
) temp | |
where temp.countId > 1; | |
delete ja from JournalArticle ja | |
join temp_ja as tja on tja.groupId = ja.groupId and tja.uuid_ = ja.uuid_ and tja.articleId = ja.articleId | |
where ja.version < tja.maxVersionId; | |
drop table temp_ja; | |
create unique index IX_3463D95B on JournalArticle (uuid_, groupId); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment