Based on the requirements you've provided, we can design a database schema that includes:
This structure ensures that changes can only be made when they are approved by at least 3 users and gives the ability to track the history of each modification.
dbml
Copy
Table users {
id bigint [pk, increment]
username varchar
email varchar [unique]
password varchar
created_at timestamp
updated_at timestamp
}
Table people {
id bigint [pk, increment]
created_by bigint [ref: > users.id]
first_name varchar
last_name varchar
birth_name varchar
middle_names varchar
date_of_birth date
created_at timestamp
updated_at timestamp
}
Table relationships {
id bigint [pk, increment]
created_by bigint [ref: > users.id]
parent_id bigint [ref: > people.id]
child_id bigint [ref: > people.id]
created_at timestamp
updated_at timestamp
}
Table modifications {
id bigint [pk, increment]
proposer_id bigint [ref: > users.id]
person_id bigint [ref: > people.id]
relationship_id bigint [ref: > relationships.id, null]
change_type varchar
new_data json
status varchar [default: "pending"]
created_at timestamp
updated_at timestamp
}
Table modifications_history {
id bigint [pk, increment]
modification_id bigint [ref: > modifications.id]
user_id bigint [ref: > users.id]
action varchar // 'accept' or 'reject'
created_at timestamp
}
Ref: modifications.proposer_id > users.id
Ref: modifications.person_id > people.id
Ref: modifications.relationship_id > relationships.id
Ref: modifications_history.modification_id > modifications.id
Ref: modifications_history.user_id > users.id
Ref: relationships.created_by > users.id
Ref: relationships.parent_id > people.id
Ref: relationships.child_id > people.id
Ref: people.created_by > users.id
Schema Diagram :

created_by field).status field indicating whether it’s pending, accepted, or rejected.