#!/usr/bin/env ruby -w
# ex:ts=10000
# vim:sts=4:sw=4:tw=0
#
# Copyright (C) 2003, 2004 Eivind Eklund <eivind@FreeBSD.org>
# All rights reserved.  (Licensing available on request.)
#
# Definition of tables for use in Idevaluate

require 'relation'

#
# Now set up the content of the various tables.
# The tables are automatically named the same as the class unless a separate
# name is provided.
#
# NOTE: The relation system provides an identifier (unique id) column *BY DEFAULT*.
# This column is named "#{self.class.name.downcase}_id", and contains some sort
# of integer value (what kind varies by backing database).  This identifier is
# used as the primary key if nothing else is supplied.
#

class DescriptionBase < Relation
    virtual             # This table should NOT be instantiated in the database, nor referenced
    # Description of / introduction to this item
    column(:description, "TEXT")
end

#
# Helper table for description of scores
#
class Score < Relation
    column(:title, "VARCHAR(255)")

    # FIXME This should not use SQL directly.
    ['Unrated', 'Not Applicable', 'Very Good', 'Good', 'Neutral', 'Bad', 'Very Bad'].each { |descr|
        init_sql("INSERT INTO Score (title) VALUES (?)", descr)
    }
end

#
# A single "article", which is an evaluation set w/description
# and associated ideas and goals
#
class Article < DescriptionBase; end
class Goal < DescriptionBase; end
class Idea < DescriptionBase; end

class ArticleGoal < Relation
    pkey :goal_id, :article_id      # By defining a pkey, we remove the automatic identifier creation
    reference(Article)              # References default to using the name of the primary key for that relation
    reference(Goal)                 # If the primary key contains several components, any missing components are
                                    # introduced, using the same name as in the referenced relation.  (default behaviour)
end

# FIXME This is very similar to ArticleGoal, and the similarity should be factored out
class ArticleIdea < Relation
    pkey :idea_id, :article_id
    reference(Article)
    reference(Idea)
end

# FIXME This is very similar to ArticleGoal and ArticleIdea, and the similarity
# should be factored out.
class Evaluation < DescriptionBase
    pkey(:goal_id, :idea_id)
    reference(Goal)
    reference(Idea)
    reference(Score)
end

