• Building extensions for Pagekit Part #8 - The database design

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 modifiedfield.

Let's call this table @survey_survey.

@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 :)

@survey_question
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:

@survey_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.

{{ message }}

{{ 'Comments are closed.' | trans }}

Wait a second!

Did you know that there's are great support channels for Pagekit? Visit us today and sign up for free using email or your GitHub-, Twitter-, Google- or Facebook-Account.

Latest blog posts

Latest comments

  • How to fork a theme

  • spqr/toc updated

  • spqr/toc updated

Like my work?

If you would like to support my work, you are invited to do so.