I have a table that we've run into an issue because we made a wrong assumption that Table A associates with Table B but it should be Table C. It's only an issue now that we're adding a feature but I'm not sure how to properly migrate it.
Best way I can describe it is say you have an account
, vehicle
, vehicleHistory
, carLot
.
Currently vehicleHistory
ties to vehicle
but really vehicleHistory
should be tied to carLot
. Example tables. Here's what the table looks like today:
account
id |
-----
001 |
002 |
003 |
vehicle
id | accountId
----------------
101 | 001
102 | 002
103 | 003
vehicleHistory
id | vehicleId
----------------
201 | 101
202 | 102
203 | 103
carLot
id | accountId
----------------
301 | 001
302 | 002
303 | 003
But it should be like this:
account
id |
-----
001 |
002 |
003 |
vehicle
id | accountId
----------------
101 | 001
102 | 002
103 | 003
vehicleHistory
id | carLotId
---------------
201 | 301
202 | 302
203 | 303
carLot
id | accountId
----------------
301 | 001
302 | 002
303 | 003
Is this something I should even attempt in PSQL or should I just write a script in the app's language (Node or Scala)?