I have following data structure containing sample data:
Groups Table
| id (PK) | name | foreign_id |
|---|---|---|
| A | DUPLICATED_NAME | X |
| B | DUPLICATED_NAME | X |
| C | string | Y |
| D | string | Z |
Items Table (related to Groups)
| id (PK) | group_id |
|---|---|
| uuid value1 | A |
| uuid value2 | B |
| uuid value3 | C |
| uuid value4 | D |
My goal is to get rid of id column in Groups and make name and foreign_id columns new composite primary key.
For this, I need to migrate existing items to distinct occurrences of groups. In example I've posted it means, that I need to delete group which id = B because of DUPLICATED_NAME clashing with group A, and then reassign all items with group_id = B to A, since B no longer exists, and so on, for all rows.
I'm using PostgresSQL and Liquibase.