Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
usage() {
echo "Usage: $0 <type> [<schema>.]<name> [r=<requirement>[,<requirement>]...] [<param_name>=<param_value>[,<param_value>]...] [<param1_name>:<param2_name>=<param1_value>:<param2_value>[,<param1_value>:<param2_value>]...]"
echo " arguments must be SQL safe strings (A-z 0-9 _ .)"
echo " schema defaults to public if not specified"
echo " specify 'schema' as <type> and the name of the schema as <name> to add a schema"
}
if [ "$BASH_VERSINFO" -lt 4 ]; then
-- Deploy [% project %]:[% change %] to [% engine %]
[% FOREACH item IN requires -%]
-- requires: [% item %]
[% END -%]
[% FOREACH item IN conflicts -%]
-- conflicts: [% item %]
[% END -%]
BEGIN;
CREATE OR REPLACE FUNCTION validate_user(
email TEXT
, token UUID
)
RETURNS BOOL
LANGUAGE plpgsql
AS $$
DECLARE
BEGIN
IF exists(SELECT
@deinspanjer
deinspanjer / verify_google_jwt.sql
Created October 6, 2016 00:34
A PostgreSQL function using the plv8 language that can validate a JWT token from Google Sign-In
CREATE EXTENSION plv8;
CREATE OR REPLACE FUNCTION verify_google_jwt(jwt_token TEXT)
RETURNS JSONB
LANGUAGE plv8 IMMUTABLE STRICT
AS $$
function logerror(msg) {
plv8.elog(ERROR, msg);
}
@deinspanjer
deinspanjer / application_function__benchmark.sql
Created September 24, 2016 17:33
Some Postgres audit logging customizations for use in PostgREST
-- Deploy myproject:application_function__benchmark to pg
-- requires: application__schema
BEGIN;
SET search_path TO application;
CREATE TYPE _bench_result AS (
function_name TEXT,
runtime REAL,
@deinspanjer
deinspanjer / pg_deploy_create_function.tmpl
Last active October 9, 2016 13:41
Sqitch create function templates for pg engine
-- Deploy [% project %]:[% change %] to [% engine %]
[% FOREACH item IN requires -%]
-- requires: [% item %]
[% END -%]
[% FOREACH item IN conflicts -%]
-- conflicts: [% item %]
[% END -%]
BEGIN;
@deinspanjer
deinspanjer / pg_deploy_create_schema.tmpl
Last active October 9, 2016 13:43
Sqitch create schema templates for pg engine
-- Deploy [% project %]:[% change %] to [% engine %]
[% FOREACH item IN requires -%]
-- requires: [% item %]
[% END -%]
[% FOREACH item IN conflicts -%]
-- conflicts: [% item %]
[% END -%]
BEGIN;
@deinspanjer
deinspanjer / pg_deploy_create_enum.tmpl
Last active October 9, 2016 13:44
Sqitch create enum templates for pg engine
-- Deploy [% project %]:[% change %] to [% engine %]
[% FOREACH item IN requires -%]
-- requires: [% item %]
[% END -%]
[% FOREACH item IN conflicts -%]
-- conflicts: [% item %]
[% END -%]
BEGIN;
@deinspanjer
deinspanjer / pg_deploy_create_type.tmpl
Last active October 9, 2016 13:50
Sqitch create type templates for pg engine
-- Deploy [% project %]:[% change %] to [% engine %]
[% FOREACH item IN requires -%]
-- requires: [% item %]
[% END -%]
[% FOREACH item IN conflicts -%]
-- conflicts: [% item %]
[% END -%]
BEGIN;
@deinspanjer
deinspanjer / pg_deploy_create_view.tmpl
Last active October 9, 2016 13:52
Sqitch create view templates for pg engine
-- Deploy [% project %]:[% change %] to [% engine %]
[% FOREACH item IN requires -%]
-- requires: [% item %]
[% END -%]
[% FOREACH item IN conflicts -%]
-- conflicts: [% item %]
[% END -%]
BEGIN;