Safe Haskell | None |
---|---|
Language | Haskell2010 |
Functions for migrating the database to create the necessary functions for the package.
Users can use these functions or copy and paste the tables to create these tables through a standalone migration system.
Synopsis
- migrationQueryString :: String -> String
- migrate :: Connection -> String -> IO ()
- teardown :: Connection -> IO ()
Documentation
The DDL statements to create the schema given a value type.
:: Connection | |
-> String | The type of the |
-> IO () |
This function creates a table and enumeration type that is appriopiate for the queue. The following sql is used.
DO $$ CREATE OR REPLACE FUNCTION notify_on(channel text) RETURNs VOID AS $$ BEGIN EXECUTE (format(E'NOTIFY %I', channel)); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION listen_on(channel text) RETURNS VOID AS $$ BEGIN EXECUTE (format(E'LISTEN %I', channel)); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION unlisten_on(channel text) RETURNS VOID AS $$ BEGIN EXECUTE (format(E'UNLISTEN %I', channel)); END; $$ LANGUAGE plpgsql; DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname =state_t
) THEN CREATE TYPE state_t AS ENUM (enqueued
,failed
); END IF; END$$; CREATE SEQUENCE IF NOT EXISTS modified_index START 1; CREATE TABLE IF NOT EXISTS payloads ( id BIGSERIAL PRIMARY KEY , attempts int NOT NULL DEFAULT 0 , state state_t NOT NULL DEFAULTenqueued
, modified_at int8 NOT NULL DEFAULT nextval(modified_index
) , value ${VALUE_TYPE} NOT NULL ); CREATE INDEX IF NOT EXISTS active_modified_at_idx ON payloads USING btree (modified_at, state) WHERE (state =enqueued
);
The VALUE_TYPE
needs to passed in through the second argument.