Saturday, November 29, 2014

Planning stage

How to model the repository?

My starting point is to create a database model called Pages to hold the contents, with the following migration:
  class CreatePages < ActiveRecord::Migration
    def change
      create_table :pages do |t|
        t.string       :title
        t.text         :abstract
        t.text         :content
      end
    end
which I think is pretty self-explanatory. (Note: if you don't read rails, it basically creates a database table with three columns, title, abstract, and content, with string and text datatypes). Do I need another model for the categories? A category may not have much, or any, contents. It might be nice to have a little bit of abstract to say what it is about, but that's about all it needs. So it does look like I can represent them using the same Pages object, maybe by adding a boolean column to note that it is a category. 

However, when the webpage loads, it should display all the categories on the left hand side. If I keep all the categories in the same table as the Pages objects, it may slow things down once there is a lot of contents. I don't think it's very efficient having to scan the 'Page' table to pick out which ones are the categories, even when it is indexed. Plus, I do not see any benefit, unless I want to demote a category to a Pages object, or vice versa, and that is not something I should be doing anyway.

How about sub-categories? These will only be shown when a category is selected, and it is possible that I want to convert a Pages object into a sub-category of its own. So, I'll represent them using the Pages model.

Now, more importantly, how do you link Categories to Pages? Fortunately there is a gem (i.e. plugin) for this called Ancestry.

Should I add users?

At this point, there's only going to be one user in mind, me, but it does not take much effort to add users on the application using Devise. Each user should be able to choose which Pages and Categories are private, and displayed to everyone. I imagine a url structure like the following:
    http://<domain>/Users/1/Categories/1/Pages/1

So up till now we have the following three data models Users, Categories, and Pages.

No comments:

Post a Comment