表单输入字段的动态扩展

I have been working on a web-based device management system for work, and I have ran into an issue with presenting the user the option of adding more fields as needed. For example, some devices will have say 4x drives, 6x ram modules, etc. My options so far are...

  • Hard-code the MySQL Database to have X amount of each type of field. 4 disk drive fields, 6 ram module fields, etc. However, most machines will have less than this, and some may have considerably more.

  • Create a table for each type that will possibly have more than one
    value. Such as a device_drives table, device_memory table, etc.

Would there be a more efficient (and dynamic) method of doing this? Both methods I have considered seem pretty silly. Here is a visual example of it, the red arrows representing icons that the user could click to add another of that type.

enter image description here

Why does it sound silly? Let's say you have one hundred million items in database. Do you alter that table every time a new field type is added? Does that sound smart?

I would suggest another solution. You could create a table for field types and another table for field values. This way you can separate the configuration data from the device data, which can be a good idea. No matter how many field types a device has, how many values every field has or in case of addition of a field type or value, you are still safe with this architecture.

As for visual creating of fields, you can simply add "+" at the right side, which is click-able and creates another similar field under the current one.