Skip to content

Commit b8bf42e

Browse files
committed
fix: DuplicateKeyException has been thrown when user tried to add the same series to a collection.
Co-authored-by: Mukesh Katariya <[email protected]> Fix #986
1 parent f713bd9 commit b8bf42e

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

src/main/resources/liquibase/changelog.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
<include file="version/0.3.xml" relativeToChangelogFile="true" />
1313
<include file="version/0.4.xml" relativeToChangelogFile="true" />
1414
<include file="version/0.4.1.xml" relativeToChangelogFile="true" />
15+
<include file="version/0.4.2.xml" relativeToChangelogFile="true" />
1516

1617
</databaseChangeLog>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
6+
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
7+
8+
<include file="0.4.2/2019-11-17--drop_unique_series_from_collection.xml" relativeToChangelogFile="true" />
9+
10+
</databaseChangeLog>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
6+
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
7+
8+
<!--
9+
We have to create a non-existing index first in order to prevent
10+
11+
ERROR 1025 (HY000): Error on rename of './mystamps/#sql-488_b7' to './mystamps/collections_series'
12+
(errno: 150 - Foreign key constraint is incorrectly formed)
13+
14+
from happening on MySQL.
15+
16+
It occurs because fk_collections_series_collection_id index hasn't been created when the table was created.
17+
MySQL is smart enough to understand that it can use uc_collections_series_collection_id_series_id
18+
compound index instead. Now, when we want to remove this index, MySQL refuses an attempt as in this case
19+
there will be no index for collection_id field. That's why we create it explicitly.
20+
-->
21+
<changeSet id="add-collections_series_series_id-index" author="php-coder" context="scheme" dbms="mysql">
22+
23+
<createIndex tableName="collections_series" indexName="fk_collections_series_collection_id">
24+
<column name="collection_id" />
25+
</createIndex>
26+
27+
</changeSet>
28+
29+
<changeSet id="drop-unique-constraint-from-collections_series-table" author="php-coder" context="scheme">
30+
31+
<dropUniqueConstraint
32+
tableName="collections_series"
33+
constraintName="uc_collections_series_collection_id_series_id" />
34+
35+
<rollback
36+
changeSetId="add-unique-constraint-to-collections_series-table"
37+
changeSetAuthor="cssru"
38+
changeSetPath="classpath:/liquibase/version/0.4/2016-01-04--unique_series_in_collection.xml" />
39+
40+
</changeSet>
41+
42+
</databaseChangeLog>

0 commit comments

Comments
 (0)