Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,52 @@ addons:
packages:
- expect-dev # provides unbuffer utility

before_install:
- psql --version
- sudo /etc/init.d/postgresql stop
- sudo apt-get -y --purge remove postgresql libpq-dev libpq5 postgresql-client-common postgresql-common
- sudo rm -rf /var/lib/postgresql
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
- sudo sh -c "echo deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main $PGVERSION >> /etc/apt/sources.list.d/postgresql.list"
- sudo sh -c "echo deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg-testing main $PGVERSION >> /etc/apt/sources.list.d/postgresql.list"
- sudo apt-get update -qq
- sudo apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::="--force-confnew" install postgresql-$PGVERSION postgresql-server-dev-$PGVERSION
- sudo chmod 777 /etc/postgresql/$PGVERSION/main/pg_hba.conf
- sudo echo "local all postgres trust" > /etc/postgresql/$PGVERSION/main/pg_hba.conf
- sudo echo "local all all trust" >> /etc/postgresql/$PGVERSION/main/pg_hba.conf
- sudo echo "host all all 128.0.0.1/32 trust" >> /etc/postgresql/$PGVERSION/main/pg_hba.conf
- sudo echo "host all all ::1/128 trust" >> /etc/postgresql/$PGVERSION/main/pg_hba.conf
- sudo /etc/init.d/postgresql restart
- psql --version

before_script:
- createuser -U postgres -s travis
- psql -c "CREATE USER myflow WITH PASSWORD 'myflow';" -U postgres
- psql -c 'CREATE DATABASE myflow WITH OWNER myflow;' -U postgres

env:
global:
- DBFLOW=myflow
matrix:
- PGVERSION=9.4
- PGVERSION=9.5
- PGVERSION=9.6
- PGVERSION=10
- PGVERSION=11

before_install:
- psql --version
- sudo /etc/init.d/postgresql stop
- sudo apt-get -y --purge remove postgresql libpq-dev libpq5 postgresql-client-common postgresql-common
- sudo rm -rf /var/lib/postgresql
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
- sudo sh -c "echo deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main $PGVERSION >> /etc/apt/sources.list.d/postgresql.list"
- sudo sh -c "echo deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg-testing main $PGVERSION >> /etc/apt/sources.list.d/postgresql.list"
- sudo apt-get update -qq
- sudo apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::="--force-confnew" install postgresql-$PGVERSION postgresql-server-dev-$PGVERSION postgresql-$PGVERSION-pgtap
- sudo chmod 777 /etc/postgresql/$PGVERSION/main/pg_hba.conf
- sudo echo "local all postgres trust" > /etc/postgresql/$PGVERSION/main/pg_hba.conf
- sudo echo "local all all trust" >> /etc/postgresql/$PGVERSION/main/pg_hba.conf
- sudo echo "host all all 128.0.0.1/32 trust" >> /etc/postgresql/$PGVERSION/main/pg_hba.conf
- sudo echo "host all all ::1/128 trust" >> /etc/postgresql/$PGVERSION/main/pg_hba.conf
- sudo /etc/init.d/postgresql restart
- psql --version

before_script:
- createuser -U postgres -s travis
- psql -c "CREATE USER myflow WITH PASSWORD 'myflow';" -U postgres
- psql -c 'CREATE DATABASE myflow WITH OWNER myflow;' -U postgres
- psql -c 'CREATE EXTENSION pgtap;' -U postgres -d $DBFLOW

install:
- git clone https://github.com/sql-flow/pg-extension.git $HOME/pg-extension
- export PATH=$HOME/pg-extension/scripts:$PATH
- echo "Install OK"
- git clone https://github.com/sql-flow/pg-extension.git $HOME/pg-extension
- export PATH=$HOME/pg-extension/scripts:$PATH
- echo "Install OK"

script:
- psql -v "ON_ERROR_STOP=1" -f ./sql/sqlflow-structure.sql -U postgres myflow
- psql -v "ON_ERROR_STOP=1" -f ./sql/sqlflow-instance.sql -U postgres myflow
- psql -v "ON_ERROR_STOP=1" -f ./sql/sqlflow-structure.sql -U postgres $DBFLOW
- psql -v "ON_ERROR_STOP=1" -f ./sql/sqlflow-instance.sql -U postgres $DBFLOW
- psql -v "ON_ERROR_STOP=1" -f ./sql/sqlflow-functions.sql -U postgres $DBFLOW
- pg_prove -U postgres -d $DBFLOW test/*.sql

after_success:
- echo "Success OK"
- psql -f ./sql/uninstall_sqlflow.sql -U postgres myflow
- echo "Success OK"
- psql -f ./sql/uninstall_sqlflow.sql -U postgres $DBFLOW

12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
TESTS = $(wildcard test/sql/*.sql)
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --inputdir=test --load-language=plpgsql
PG_CONFIG ?= pg_config
PG92 = $(shell $(PG_CONFIG) --version | grep -qE " 8\.| 9\.0| 9\.1" && echo no || echo yes)

ifeq ($(PG92),no)
$(error $(EXTENSION) requires PostgreSQL 9.2 or higher)
endif

PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
31 changes: 31 additions & 0 deletions sql/sqlflow-functions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
function: GET_WORKFLOW_ID()
argument: 1> a_ref: the unique reference of the workflow
return: Primary key of the workflow
*/
CREATE OR REPLACE FUNCTION get_workflow_id(
a_ref CHARACTER VARYING(36)
) RETURNS integer AS
$BODY$

DECLARE
t_workflow_id INTEGER DEFAULT NULL;
BEGIN

BEGIN
SELECT id INTO STRICT t_workflow_id
FROM sqlflow.workflow
WHERE uref=a_ref;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE EXCEPTION 'Workflow "%" not found', a_ref;
WHEN TOO_MANY_ROWS THEN
RAISE EXCEPTION 'Workflow "%" not unique', a_ref;
END;

RETURN t_workflow_id;

END;
$BODY$
LANGUAGE plpgsql IMMUTABLE;

1 change: 0 additions & 1 deletion sql/sqlflow-instance.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ SET search_path TO sqlflow, public;
CREATE TABLE sqlflow.instance
(
id bigserial,
-- workflow_id integer REFERENCES sqlflow.workflow ON DELETE CASCADE,
version_id integer REFERENCES sqlflow.version ON DELETE CASCADE ON UPDATE CASCADE,
rel_table character varying(127) NOT NULL,
flow_type flow_type NOT NULL DEFAULT 'row',
Expand Down
1 change: 1 addition & 0 deletions sql/sqlflow-structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
--
-- Add user to manage sqlflow object s in database
--
DROP ROLE IF EXISTS sqlflow;
CREATE ROLE sqlflow WITH
NOLOGIN
NOSUPERUSER
Expand Down
21 changes: 21 additions & 0 deletions test/base.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Start transaction and plan the tests.
BEGIN;
SELECT plan(10);

-- Run test on sqlflow structure
SELECT has_schema('sqlflow');

SELECT has_type('sqlflow', 'flow_type', 'flow_type exists');
SELECT has_type('sqlflow', 'flow_cond', 'flow_cond exists');
SELECT has_type('sqlflow', 'flow_state', 'flow_state exists');

SELECT has_table('sqlflow', 'workflow', 'workflow table exists');
SELECT has_column('sqlflow', 'workflow', 'id', 'id column exists');
SELECT has_column('sqlflow', 'workflow', 'uref', 'uref column exists');
SELECT has_column('sqlflow', 'workflow', 'title', 'title column exists');
SELECT has_column('sqlflow', 'workflow', 'rel_table', 'rel_table column exists');
SELECT has_column('sqlflow', 'workflow', 'flow_type', 'flow_type column exists');

-- Finish the tests and clean up.
SELECT * FROM finish();
ROLLBACK;