i am thinking of a way to design my database but i want to do it right, which in my opinion includes:
- the DB design should not have any redundancies
- the design by itself should set the limits for what is possible and what is not
- the DB design should not need any business logic to achieve the persistance of the objects
This is where i am now: i have a design in my brain and want to transport that into mysql (any other DBMS would be fine but i don't think this is the issue). Afterwards i want to build a java application on top of the database architecture.
My Problem seems rather simple (for simplicity i removed many things):
i have two distinct objects/tables:
- Ships
- id
- name
- speed
- Weapons
- id
- name
- damage
What i want to do is to build something like a tech-tree:
- if you want to build Ship "Y" then you have to research Ship "X" first.
- if you want to use Weapon "B" then you have to research Weapon "A" first.
- if you want to use Weapon "C" then you have to research Weapon "A" first.
This would be pretty easy but now to the next constraints:
- if you want to build Ship "Z" then you have to research Ship "Y" and Weapon "B" and "Weapon "C" first
Here is a visual representation of the tree:

To represent a tree i came up with only one solution:
create a new table called "entities" with the fields "id" and "table_name"; also create a m2m-table which has two fields "id_entity" and "id_entity_prequisite"; the tables "ships" and "weapons" do not have a real primary key "id" anymore, but instead use a foreign key to the table "entities->id"
- good: the full tree can be represented
- bad & ugly: i need businesslogic to create an entity first, use the id and can then create a new ship or weapon
is there any other (better yet, THE) way to do this?