Building extensions for Pagekit Part #8 - The database design
Potentially outdated
This post is older than 365 days and may be outdated. Please use the site-search to search for updated information.
Huh - time flies! I released the last part of my blog series "Building extensions for Pagekit" a few weeks ago.
Let's continue on that.
Do you remember what we learned? We focussed on databases. Using databases in Pagekit is pretty easy - but designing a database isn't that simple at all.
We need to know what we want to do exactly.
Database design
In our extension we would like to create surveys. A survey can have one question with different answers or it could have multiple questions.
First of all we need a table where the survey itself is defined. We need an ID
, a slug
, title
, a status
, date
and a modified
field.
Let's call this table @survey_survey
.
ID | Slug | title |
---|---|---|
1 | test-survey | Test Survey |
2 | test-survey-2 | Test Survey 2 |
3 | test-survey-3 | Test Survey 3 |
Now let's think about the next table: The questions (@survey_question
). We need an unique ID for the question - but we also need a field to reference the survey
. In this case I named it survey_id
. We need a field for the question
, the page
and the position
. I also added a data
field; we need that later :)
ID | survey_id | question | page | position | data |
---|---|---|---|---|---|
1 | 2 | How are you today? | 1 | 1 | {} |
2 | 2 | Do you like coffee? | 1 | 2 | {} |
Okay - let's have a look at the answers (@survey_answer
). Just like we did before, we need an unique ID
, we also need to reference the question_id
and of course we need a field for the possbile answer
:
ID | question_id | answer |
---|---|---|
1 | 1 | Fine |
2 | 1 | Bad |
3 | 1 | I don't understand this question |
4 | 2 | Who doesn't? |
5 | 2 | I prefer tea |
Homework
For sure you noticed that one more table is needed: We need to store the user-input.
Think about the desing of that table - I am going to update this post within the next days and add a possible solution. Of course I'm going to announce this on Twitter and on the pagekit-forum.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}