I wonder if it possible to get maximum column value from a certain table and set it as start sequence value with no pure sql. The following code doesn't work:
<property name="maxId" value="(select max(id)+1 from some_table)" dbms="h2,mysql,postgres"/>
<changeSet author="author (generated)" id="1447943899053-1">
<createSequence sequenceName="id_seq" startValue="${maxId}" incrementBy="1"/>
</changeSet>
Got an error:
Caused by: liquibase.parser.core.ParsedNodeException: java.lang.NumberFormatException: For input string: "${m"
I've tried it with no parentheses around select ...
etc. with the same result.
So it's not possible to use computed value as start sequence value?
So, such a solution worked for me:
<changeSet author="dfche" id="1448634241199-1">
<createSequence sequenceName="user_id_seq" startValue="1" incrementBy="1"/>
</changeSet>
<changeSet author="dfche" id="1448634241199-2">
<sql dbms="postgresql">select setval('user_id_seq', max(id)+1) from jhi_user</sql>
<sql dbms="h2">alter sequence user_id_seq restart with (select max(id)+1 from jhi_user)</sql>
</changeSet>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With