-
Notifications
You must be signed in to change notification settings - Fork 7
2_4_Database schema, migration and model
VMS backend uses a relational database, like MySQL and MariaDB for storing data.
The database schema defines in database/migrations/
(the directory). It helps create
, drop
, alter
database tables by Laravel Database Migration.
For example, The volunteers
table is created by database/migrations/2015_09_15_055905_create_volunteers_table.php
. The up()
function contains the columns, types and relation in volunteers
table.
Model implements by Laravel Eloquent ORM for manipulating the database. Each table has a corresponding Model which MUST inherits Illuminate\Database\Eloquent\Model
and MAY defines the relationship with other models/tables. Models exists in app/*.php
, like app/Volunteer.php
The Volunteer
model represents a volunteer. It also stores user's credentials including username
and hashed password
for authentication. The is_actived
and is_locked
mean that the volunteer was verified by email or locked.
-
City
: The volunteer lives in a city. -
VerificationCode
: The verification code belongs to the volunteer for email verification. -
Skill
: The volunteer has skills. -
Education
: The volunteer's educations. -
Experience
: The volunteer's experience. -
Project
: There are two relationships withProject
including that the project is managed by the volunteer and the volunteer attends the project.
The Project
model represents a crowdsourcing project which project managers (Volunteer
model) manage and volunteers attend.
It includes the following main fields:
-
name
anddescription
: It provides useful information for volunteers. -
is_published
: It controls if the project is viewable by volunteers or not. -
permission
: It defines whom are able to view the project.
-
Hyperlink
: The hyperlinks are shown in the project for volunteers. -
Volunteer
: There are two relationships withVolunteer
model including project managers and project members. They are defined inmanagers()
andmembers()
. -
ProjectCustomField
: VMS makes project managers create custom fields in the project for recording more information about project members flexibly. -
MemberCustomFieldData
: Project members input the custom field data in the project. The relationship withMemberCustomFieldData
is throughProjectCustomField
by foreign keys.
The ProjectCustomField
model represents a custom field in a project. It includes the following main fields:
-
name
: The custom field name displays for volunteer's. -
description
: The description of the custom field. -
required
: It defines if the custom field is mandatory or not. -
type
: The custom field type is defined incustom_field_type
inconfig/constants.php
and the value MUST be one of thecustom_field_type.*.number
-
is_published
: It controls the visibility of the custom field. -
metadata
: It stores the serialization of thecustom_field_type.*.metadata
. For example, theApp\CustomField\RadioButtonMetadata
class provides the options in radio button. -
order
: The sequence of the custom field.
-
Project
: It defines that the custom field belongs toProject
model. -
MemberCustomFieldData
: It defines the relationship between data from that project members input and custom field.
The MemberCustomFieldData
model represents project members' input data.
The main fields include:
-
data
: The input data from project member is serialized viaPayload
class.
-
ProjectCustomField
: EachMemberCustomFieldData
model corresponds toProjectCustomField
model. It represents the meaning of the data. -
ProjectMember
: The relationship represents that the data belongs to project member.