I'm using PostgreSQL.
I have tables A, B, C & D.
Table A has a foreign key to table B (so one-to-many).
Tables C & D have foreign keys to table A (one-to-many). So it looks like:
B :-> A :-> C & D
Now i want to add a intermediate table E to make relations:
E :-> C & D (one-to-many)
B -> E (one-to-one with fk)
B :-> A (one-to-many)
I need it to introduce table F which will also has a foreign key to table E.
Table E has just a one identity column 'id'.
Now i have to write a migration and have no idea how to add rows to E and update B simultaneously
In pseudo-SQL it must be look like:
UPDATE B SET A_id = id INSERT INTO A (id)