|
1 | 1 | <?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
2 | 2 | <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
|
3 | 3 | <changeSet author="chuinetri" id="1704818243021-1">
|
4 |
| - <comment>Deduplicate rows before adding unique constraint</comment> |
| 4 | + <comment>Deduplicate rows before adding unique constraints</comment> |
5 | 5 | <delete tableName="user_infos">
|
6 | 6 | <where>id in (select id from (select row_number() over (partition by sub) as rnb, * from user_infos) subquery where rnb > 1)</where>
|
7 | 7 | </delete>
|
8 | 8 |
|
9 | 9 | <sql stripComments="true" dbms="!oracle">
|
10 | 10 | update connection c1 set
|
11 | 11 | first_connexion_date = (select min(c2.first_connexion_date) from connection c2 where c2.sub=c1.sub group by c2.sub),
|
12 |
| - last_connexion_date = (select max(c2.last_connexion_date) from connection c2 where c2.sub=c1.sub group by c2.sub), |
13 |
| - connection_accepted = (select connection_accepted from connection c2 where (c2.sub, c2.last_connexion_date) in ( |
| 12 | + last_connexion_date = (select max(c2.last_connexion_date) from connection c2 where c2.sub=c1.sub group by c2.sub), |
| 13 | + connection_accepted = (select connection_accepted from connection c2 where (c2.sub, c2.last_connexion_date) in ( |
14 | 14 | select c3.sub, max(c3.last_connexion_date) from connection c3 where c3.sub=c1.sub group by c3.sub) limit 1);
|
15 | 15 | </sql>
|
16 | 16 | <sql stripComments="true" dbms="oracle">
|
17 | 17 | --oracle use fetch instead of limit
|
18 | 18 | update connection c1 set
|
19 |
| - first_connexion_date = (select min(c2.first_connexion_date) from connection c2 where c2.sub=c1.sub group by c2.sub), |
20 |
| - last_connexion_date = (select max(c2.last_connexion_date) from connection c2 where c2.sub=c1.sub group by c2.sub), |
21 |
| - connection_accepted = (select connection_accepted from connection c2 where (c2.sub, c2.last_connexion_date) in ( |
22 |
| - select c3.sub, max(c3.last_connexion_date) from connection c3 where c3.sub=c1.sub group by c3.sub) FETCH FIRST 1 ROW ONLY); |
| 19 | + first_connexion_date = (select min(c2.first_connexion_date) from connection c2 where c2.sub=c1.sub group by c2.sub), |
| 20 | + last_connexion_date = (select max(c2.last_connexion_date) from connection c2 where c2.sub=c1.sub group by c2.sub), |
| 21 | + connection_accepted = (select connection_accepted from connection c2 where (c2.sub, c2.last_connexion_date) in ( |
| 22 | + select c3.sub, max(c3.last_connexion_date) from connection c3 where c3.sub=c1.sub group by c3.sub) FETCH FIRST 1 ROW ONLY); |
23 | 23 | </sql>
|
24 | 24 | <delete tableName="connection">
|
25 | 25 | <where>id in (select id from (select row_number() over (partition by sub) as rnb, * from connection) subquery where rnb > 1)</where>
|
26 | 26 | </delete>
|
| 27 | + |
| 28 | + <rollback/><!--no rollback possible because delete, but no need as we just removed duplicate records--> |
27 | 29 | </changeSet>
|
28 | 30 |
|
29 | 31 | <changeSet author="chuinetri" id="1704818243021-2">
|
|
0 commit comments