Skip to content

Database

Here we show the schema that is used in the Web Evaluator application. Is is a PostgreSQL database, using some of PSQL triggers and functions.

INFO

The databse schema is stored in scripts/qtrvsim_web_eval.sql file.

Tables

public.results

ColumnData TypeConstraints
useridbigintNOT NULL
taskidbigintNOT NULL
result_filetext
last_sourcetext
best_sourcetext
score_lastintegerDEFAULT '-1'
score_bestintegerDEFAULT '-1'
timetimestamp with time zoneDEFAULT CURRENT_TIMESTAMP
resultsmallintDEFAULT '-1'

public.submissions

ColumnData TypeConstraints
idintegerNOT NULL, PRIMARY KEY
useridintegerNOT NULL
taskidintegerNOT NULL
filetext
evaluatedbooleanDEFAULT false
timetimestamp with time zoneDEFAULT CURRENT_TIMESTAMP

public.tasks

ColumnData TypeConstraints
idintegerNOT NULL, PRIMARY KEY
namevarchar(64)NOT NULL
pathvarchar(256)NOT NULL
availablebooleanDEFAULT true
sequenceintegerDEFAULT 0

public.users

ColumnData TypeConstraints
idintegerNOT NULL, PRIMARY KEY
emailvarchar(128)NOT NULL
passwordvarchar(128)NOT NULL
saltvarchar(128)NOT NULL
tokenvarchar(128)DEFAULT NULL
verifiedbooleanDEFAULT false
usernamevarchar(128)NOT NULL
adminbooleanDEFAULT false
display_namevarchar(64)
countryvarchar(128)
organizationvarchar(256)
groupvarchar(128)
visibilityintegerDEFAULT 0

Functions

public.delete_evaluated_submission

sql
CREATE FUNCTION public.delete_evaluated_submission() RETURNS trigger
    LANGUAGE plpgsql
AS $$
BEGIN
  IF NEW.evaluated = TRUE THEN
    DELETE FROM submissions WHERE id = NEW.id;
    RETURN NULL;
  ELSE
    RETURN NEW;
  END IF;
END;
$$;

public.update_best_score

sql
CREATE FUNCTION public.update_best_score() RETURNS trigger
    LANGUAGE plpgsql
AS $$
BEGIN
  IF NEW.score_best = -1 OR NEW.score_best = 0 OR (NEW.score_last <= NEW.score_best AND NEW.result = 0) THEN
    NEW.score_best := NEW.score_last;
    NEW.best_source := NEW.last_source;
    RETURN NEW;
  END IF;
  RETURN NEW;
END;
$$;

public.update_results_timestamp

sql
CREATE FUNCTION public.update_results_timestamp() RETURNS trigger
    LANGUAGE plpgsql
AS $$
BEGIN
  UPDATE results
  SET time = CURRENT_TIMESTAMP AT TIME ZONE 'Europe/Prague'
  WHERE userid = NEW.userid AND taskid = NEW.taskid;
  RETURN NEW;
END;
$$;

Triggers

after_submission_update on public.submissions

sql
CREATE TRIGGER after_submission_update
AFTER UPDATE ON public.submissions
FOR EACH ROW
WHEN ((OLD.evaluated IS DISTINCT FROM NEW.evaluated) AND (NEW.evaluated = TRUE))
EXECUTE FUNCTION public.delete_evaluated_submission();

update_best_score_trigger on public.results

sql
CREATE TRIGGER update_best_score_trigger
BEFORE INSERT OR UPDATE ON public.results
FOR EACH ROW
EXECUTE FUNCTION public.update_best_score();

update_results_after_insert on public.submissions

sql
CREATE TRIGGER update_results_after_insert
AFTER INSERT ON public.submissions
FOR EACH ROW
EXECUTE FUNCTION public.update_results_timestamp();