|
You are here: Home / Documentation / Creating Custom Content Types (Collections) in Sitellite |
Creating Custom Content Types (Collections) in SitelliteThe Database SchemaLet's create a database table to store a list of our favourite 80's tunes, including lyrics. Here's an adequate database table for such a collection: CREATE TABLE myapp_tunes (
# Collection-specific fields:
id INT NOT NULL AUTO_INCREMENT,
title CHAR(72) NOT NULL,
artist CHAR(72) NOT NULL,
album CHAR(72) NOT NULL,
style CHAR(72) NOT NULL,
year YEAR NOT NULL,
lyrics TEXT NOT NULL,
# Sitellite-specific fields:
sitellite_access CHAR(16) NOT NULL,
sitellite_status CHAR(16) NOT NULL,
sitellite_startdate DATETIME default NULL,
sitellite_expirydate DATETIME default NULL,
sitellite_owner CHAR(48) NOT NULL default '',
sitellite_team CHAR(48) NOT NULL default '',
PRIMARY KEY (id),
INDEX (artist, album, style, year)
);
As a "best practice" rule of thumb, I generally encourage app developers to prefix their database table names with the name of their app, to distinguish them from one another, and to clearly identify which app they belong to. This helps avoid conflicts where five apps all want a table named "category". ;) The Sitellite-specific fields have the following purposes:
Before we continue, to store our style list let's create a simple secondary table. We'll use this table via a Selector widget later on. CREATE TABLE myapp_styles (
id INT(11) NOT NULL AUTO_INCREMENT,
name CHAR(72) NOT NULL,
PRIMARY KEY (id),
INDEX (name)
);
So far, we haven't seen very much that is different from what you would do to create any type of database table/collection. Now, we'll add the table Rex will use to store our revision history for each item in our myapp_tunes table. CREATE TABLE myapp_tunes_sv (
# Rex-specific fields:
sv_autoid INT(11) NOT NULL AUTO_INCREMENT,
sv_author VARCHAR(48) NOT NULL default '',
sv_action ENUM('created', 'modified', 'republished', 'replaced', 'restored', 'deleted') NOT NULL default 'created',
sv_revision TIMESTAMP(14) NOT NULL,
sv_changelog TEXT NOT NULL,
sv_deleted ENUM('yes','no') NOT NULL default 'no',
sv_current ENUM('yes','no') NOT NULL default 'yes',
# Collection-specific fields:
id INT NOT NULL,
title CHAR(72) NOT NULL,
artist CHAR(72) NOT NULL,
album CHAR(72) NOT NULL,
style CHAR(72) NOT NULL,
year YEAR NOT NULL,
lyrics TEXT NOT NULL,
# Sitellite-specific fields:
sitellite_access CHAR(16) NOT NULL,
sitellite_status CHAR(16) NOT NULL,
sitellite_startdate DATETIME default NULL,
sitellite_expirydate DATETIME default NULL,
sitellite_owner CHAR(48) NOT NULL default '',
sitellite_team CHAR(48) NOT NULL default '',
PRIMARY KEY (sv_autoid),
INDEX sv_author (sv_author,sv_action,sv_revision,sv_deleted,sv_current),
INDEX (artist, album, style, year)
);
As you can see, this table is the same as our myapp_tunes table, with the addition of seven new fields used to track changes by Rex. For every change made to a single item in the myapp_tunes table, a new entry is made in myapp_tunes_sv. Here is a list of additional fields and properties of this table, so that you know what each does:
Now, we have done all that is necessary at the database level, and we are ready to create our collection definition file so that Sitellite knows how to handle our collection for us. Page 1: Creating a Rex Collection |
|
Copyright © 2008, SIMIAN systems Inc. All rights reserved. Privacy policy Some of the icons on this site were created by the Gnome Project. |