contest_domains is the table that holds general information
about each contest:
create table contest_domains (
domain_id integer not null primary key,
domain varchar(21) not null unique,
-- the unique constraint creates an index for us
entrants_table_name varchar(30),
pretty_name varchar(100) not null,
-- where the contest starts
home_url varchar(200),
-- arbitrary HTML text that goes at the top of
-- the auto-generated entry form
blather varchar(4000),
-- where to send users after they enter
-- (if blank, we use a generated form)
post_entry_url varchar(200),
maintainer not null references users(user_id),
notify_of_additions_p char(1) default 'f' check (notify_of_additions_p in ('t', 'f')), -- send email when a person enters
us_only_p char(1) default 'f' check (us_only_p in ('t', 'f')),
start_date date, -- these are optional
end_date date
);
In earlier versions of this module, the domain column was
the primary key. It has been changed to an integer
(domain_id) because of performance enhancements to the
site-wide search. There is some backwards-compatibility code in the
contest module that uses the domain column if there is no
domain_id provided in the form data.
When a new contest is created, a new row is added to contest_domains,
and a new table called contest_entrants_$domain (where
$domain is the value of the domain column). This new
entrants table looks like this:
We don't really care how many times they enter. We'll do a "distinct" query when choosing the winners. For contests that allow extra information to be provided by the user, we may want them to be able to enter multiple times.create table contest_entrants_whatever ( entry_date date not null, user_id not null references users );
Now, how is this extra information handled? When you add a custom
column to a contest, a row gets added to the table
contest_extra_columns:
Thecreate table contest_extra_columns ( domain_id not null references contest_domains, column_pretty_name varchar(30), column_actual_name varchar(200) not null, column_type varchar(200) not null, -- things like 'boolean' or 'text' column_extra_sql varchar(200) -- things like 'not null' or 'default 5' );
column_pretty_name is what is displayed to the user,
while column_actual_name> is the name of the column in
the contest specific contest_entrants_$domain table.
These new columns get added to the entrants table as the contest
gets customized. (e.g. at any time)