I have a table that has a composite primary key which consists of three columns.
+--------------+--------------+------+-----+
| field | type | Null | Key |
+--------------+--------------+------+-----+
| composed_at | TIMESTAMP | NO | PRI |
| index_at_day | INT | NO | PRI |
| panel_name | VARCHAR(20) | NO | PRI |
| meta | VARCHAR(255) | NO | |
| amount | DECIMAL(5,2) | NO | |
+--------------+--------------+------+-----+
This was quite ok for some time, but now I need to make a foreign key reference to this table. Which means that I need to add all three columns into table that will store the reference.
I don't really like the idea of adding all three columns and looking for an elegant way to replace them with something simpler. My initial approach is to generate a hashcode from these three columns in the application and use the hashcode as a surrogate key (e.g. ID).
Is there some sort of common approach for such situations, am I inventing another wheel?