Index for pkgforge

Dumped on 2010-12-15

# Index of database - pkgforge

- public

- build_log
- builder
- job
- job_status
- platform
- task
- task_status
- check_task(p integer, t integer)
- update_job_status()
- update_modification_time()

## Table: build_log

build_log Structure
F-Key | Name | Type | Description
--- | --- | --- | ---
| id | serial | PRIMARY KEY
task.id | task | integer |
builder.id | builder | integer |
| modtime | timestamp with time zone | NOT NULL DEFAULT now()

Index - Schema public

## Table: builder

builder Structure
F-Key | Name | Type | Description
--- | --- | --- | ---
| id | serial | PRIMARY KEY
| name | character varying(50) | UNIQUE NOT NULL
platform.id | platform | integer | NOT NULL
task.id | current | integer | UNIQUE
| modtime | timestamp with time zone | NOT NULL DEFAULT now()

builder Constraints
Name | Constraint
--- | ---
task_platform | CHECK (check_task(current, platform))

Tables referencing this one via Foreign Key Constraints:

- build_log

Index - Schema public

## Table: job

job Structure
F-Key | Name | Type | Description
--- | --- | --- | ---
| id | serial | PRIMARY KEY
| uuid | character varying(50) | UNIQUE NOT NULL
| submitter | character varying(50) |
job_status.id | status | integer | NOT NULL
| size | integer |
| modtime | timestamp with time zone | NOT NULL DEFAULT now()

Tables referencing this one via Foreign Key Constraints:

- task

Index - Schema public

## Table: job_status

job_status Structure
F-Key | Name | Type | Description
--- | --- | --- | ---
| id | serial | PRIMARY KEY
| name | character varying(20) | UNIQUE NOT NULL

Tables referencing this one via Foreign Key Constraints:

- job

Index - Schema public

## Table: platform

platform Structure
F-Key | Name | Type | Description
--- | --- | --- | ---
| id | serial | PRIMARY KEY
| name | character varying(10) | UNIQUE#1 NOT NULL
| arch | character varying(10) | UNIQUE#1 NOT NULL
| active | boolean | NOT NULL DEFAULT false

Tables referencing this one via Foreign Key Constraints:

- builder

- task

Index - Schema public

## Table: task

task Structure
F-Key | Name | Type | Description
--- | --- | --- | ---
| id | serial | PRIMARY KEY
job.id | job | integer | UNIQUE#1 NOT NULL
platform.id | platform | integer | UNIQUE#1 NOT NULL
task_status.id | status | integer | NOT NULL
| modtime | timestamp with time zone | NOT NULL DEFAULT now()

Tables referencing this one via Foreign Key Constraints:

- build_log

- builder

Index - Schema public

## Table: task_status

task_status Structure
F-Key | Name | Type | Description
--- | --- | --- | ---
| id | serial | PRIMARY KEY
| name | character varying(20) | UNIQUE NOT NULL

Tables referencing this one via Foreign Key Constraints:

- task

Index - Schema public

## Function: check_task(p integer, t integer)

### Returns: boolean

### Language: PLPGSQL

    DECLARE correct BOOLEAN;
    BEGIN
            SELECT  (platform = $2) INTO correct
            FROM    task
            WHERE   id = $1;

            RETURN correct;
    END;

## Function: update_job_status()

### Returns: trigger

### Language: PLPGSQL

    DECLARE
       total_count      INTEGER := 0;
       fail_count       INTEGER := 0;
       success_count    INTEGER := 0;
       cancel_count     INTEGER := 0;
       task_id          INTEGER := NEW.id;
       job_id           INTEGER;
       job_status_name  VARCHAR(20) := NULL;
    BEGIN

       SELECT job INTO job_id
           FROM task
           WHERE id = task_id
           LIMIT 1;

       IF NOT FOUND THEN
         RAISE NOTICE 'Could not find a job for task %', task_id;
         RETURN NEW;
       END IF;

       SELECT COUNT(t.id) INTO total_count
           FROM task AS t
           WHERE t.job = job_id;

       SELECT COUNT(t.id) INTO fail_count
           FROM task AS t
           JOIN task_status AS s ON t.status = s.id
           WHERE t.job = job_id AND s.name = 'fail';

       SELECT COUNT(t.id) INTO success_count
           FROM task AS t
           JOIN task_status AS s ON t.status = s.id
           WHERE t.job = job_id AND s.name = 'success';

       SELECT COUNT(t.id) INTO cancel_count
           FROM task AS t
           JOIN task_status AS s ON t.status = s.id
           WHERE t.job = job_id AND s.name = 'cancelled';

       IF total_count > 0 THEN

         IF fail_count > 0 THEN

           IF fail_count = total_count THEN
             job_status_name := 'fail';
           ELSE
             job_status_name := 'partial fail';
           END IF;

         ELSIF success_count > 0 THEN

           IF success_count = total_count THEN
             job_status_name := 'success';
           ELSE
             job_status_name := 'partial success';
           END IF;

         ELSIF cancel_count = total_count THEN
             job_status_name := 'cancelled';
         END IF;

         IF job_status_name IS NOT NULL THEN

           UPDATE job SET status =
             ( SELECT id FROM job_status WHERE name = job_status_name LIMIT 1)
             WHERE id = job_id;

         END IF;

       END IF;

       RETURN NEW;
    END;

## Function: update_modification_time()

### Returns: trigger

### Language: PLPGSQL

    BEGIN
       NEW.modtime = now();
       RETURN NEW;
    END;

Generated by PostgreSQL Autodoc

W3C HTML 4.01 Strict