Skip to content

Commit cdb000e

Browse files
committed
fix(0.3/2014-02-11--categories.xml): let the database to autogenerate id instead of providing our own.
This change should fix 2017-01-06--top_categories.xml migration on PostgreSQL. Prior this commit, we were inserting 'Prehistoric animals' category with explicitly provided id=1 By doing this, we didn't update the sequence generator. When next time we were trying to add another category without id, the sequence generator gave us the value 1 and migration were failing as a category with such id already exist. See for details: https://stackoverflow.com/questions/44744365/liquibase-postgresql-spring-jpa-id-auto-increment-issue There were two ways to fix this: always specify id explicitly and adjust the sequence generator manually after that or never provide an id and let the generator do all the work for us. This change implements the second approach because the first one would be specific to PostgreSQL (as on MySQL we don't need to adjust generators at all). The failure was: MigrationFailedException: Migration failed for change set classpath:/liquibase/version/0.4/2017-01-06--top_categories.xml::add-sport-category::php-coder: Reason: liquibase.exception.DatabaseException: ERROR: duplicate key value violates unique constraint "pk_categories" Detail: Key (id)=(1) already exists. [Failed SQL: INSERT INTO public.categories (name, name_ru, slug, created_at, created_by, updated_at, updated_by) VALUES ('Sport', 'Спорт', 'sport', NOW(), (SELECT id FROM users WHERE role = 'ADMIN' ORDER by id LIMIT 1), NOW(), (SELECT id FROM users WHERE role = 'ADMIN' ORDER by id LIMIT 1))] Addressed to #1034
1 parent 04316e6 commit cdb000e

File tree

1 file changed

+0
-1
lines changed

1 file changed

+0
-1
lines changed

src/main/resources/liquibase/version/0.3/2014-02-11--categories.xml

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
<comment>Creates category for Prehistoric animals</comment>
3939

4040
<insert tableName="categories">
41-
<column name="id" value="1" />
4241
<column name="name" value="Prehistoric animals" />
4342
<column name="name_ru" value="Доисторические животные" />
4443
<column name="created_at" valueComputed="${NOW}" />

0 commit comments

Comments
 (0)