Right now I have the following table:
+----------------+
| Sale table |
+----------------+
| ID |
| sale |
| ... |
| receiver_name |
| receiver_email |
| ... |
+----------------+
The important columns are receiver_name
and receiver_email
. The receiver is the person 'receiving' the object of a sale. Until now it was only possible to receive an object by mail. But in the next update it will also be possible to receive that object by other communication methods like for example SMS.
So for each sale the receiver of the sold object can select a communication method. For this question let's only consider e-mail and SMS. The new database-structure will have a extra table.
+----------------+
| Receiver table |
+----------------+
| ID |
| receive_method |
| receiver_name |
| receiver_email |
| receiver_telnr |
+----------------+
The updated sale table will have a foreign key to the new Receiver table
:
+----------------+
| Sale table |
+----------------+
| ID |
| sale |
| ... |
| receiver_id |
| ... |
+----------------+
This is necessary because my business logic can't know what method the user selected. Depending on the value of receive_method
having the domain ("email", "SMS")
I'll collect the data from column receiver_email
(if receive_method == "email"
) or from column receiver_telnr
(if receive_method == "SMS"
).
I think this logic is pretty solid.
The problem, however, is that the Sale table is already filled with data! So I need a way to put the values of receiver_name
and receiver_email
from the old Sale table into the new version of the Sale table. And put the correct foreign key in place so the new Sale table still contains the information of the old sales before the update.
To complete this update, this are the steps I will take:
- Create the new Receiver table
- Put the values of
receiver_name
andreceiver_email
from the old Sale table into the new Receiver table. - Add the column
receiver_id
to the Sale table. - (Here I am stuck...)
- Delete
receiver_name
andreceiver_email
from Sale table because it is referenced by the new columnreceiver_id
.
I am stuck at step 4 though. How do I insert the foreign key in the new column receiver_id
so the data stays correct?
method
anENUM
? Or aSET
? Your table names don't 'speak to me'. Seems like you have "customers" and "sales"? And the question is how to record that a particular customer has been sent notice of a sale?