Remove duplicates before adding a primary key to groupGroupings.
Fixes #11723.
This commit is contained in:
parent
18da6a8be7
commit
c95ef7a656
1 changed files with 13 additions and 0 deletions
|
|
@ -76,6 +76,19 @@ sub updateGroupGroupingsTable {
|
||||||
my ($field,$stmt) = $sth->array;
|
my ($field,$stmt) = $sth->array;
|
||||||
$sth->finish;
|
$sth->finish;
|
||||||
unless ($stmt =~ m/PRIMARY KEY/i) {
|
unless ($stmt =~ m/PRIMARY KEY/i) {
|
||||||
|
# clean up duplicates that would prevent applying a primary key
|
||||||
|
my $rs = $session->db->read(q{
|
||||||
|
select count(*) as num, groupId, inGroup
|
||||||
|
from groupGroupings
|
||||||
|
group by groupId, inGroup
|
||||||
|
having num > 1
|
||||||
|
});
|
||||||
|
my $dupSth = $session->db->prepare("delete from groupGroupings where groupId = ? and inGroup = ? limit ?");
|
||||||
|
while (my ($num, $groupId, $inGroup) = $rs->array) {
|
||||||
|
$dupSth->execute([$groupId, $inGroup, $num-1]);
|
||||||
|
}
|
||||||
|
$dupSth->finish;
|
||||||
|
# add the primary key
|
||||||
$session->db->write("alter table groupGroupings add primary key (groupId,inGroup)");
|
$session->db->write("alter table groupGroupings add primary key (groupId,inGroup)");
|
||||||
}
|
}
|
||||||
unless ($stmt =~ m/KEY `inGroup`/i) {
|
unless ($stmt =~ m/KEY `inGroup`/i) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue