DROP SEQUENCE IF EXISTS calamus_seq;
CREATE SEQUENCE calamus_seq;

DROP TABLE IF EXISTS artifact;
CREATE TABLE artifact (
  id          BIGINT       NOT NULL PRIMARY KEY,
  group_id    VARCHAR(100) NOT NULL,
  artifact_id VARCHAR(100) NOT NULL,
  version     VARCHAR(100) NOT NULL,
  classifier  VARCHAR(100),
  extension   VARCHAR(100) NOT NULL,
  level       VARCHAR(100) NOT NULL,
  git_hash    CHAR(40)
);

DROP TABLE IF EXISTS process;
CREATE TABLE process (
  id         BIGINT       NOT NULL PRIMARY KEY,
  name       VARCHAR(100) NOT NULL,
  process_id VARCHAR(100) NOT NULL
);

DROP TABLE IF EXISTS process_trigger;
CREATE TABLE process_trigger (
  id      BIGINT        NOT NULL PRIMARY KEY,
  process BIGINT        NOT NULL REFERENCES process,
  mvel    VARCHAR(1000) NOT NULL
);

INSERT INTO process (id, name, process_id)
VALUES ((SELECT
           nextval('calamus_seq')), 'Deploy', 'io.trygvis.calamus.Deploy');

INSERT INTO process_trigger (id, process, mvel)
VALUES ((SELECT
           nextval('calamus_seq')),
        (SELECT
           id
         FROM process
         WHERE process_id = 'io.trygvis.calamus.Deploy'),
        'artifact.groupId == "demo"');
