Skip to content

Commit

Permalink
merge branch.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Oct 30, 2019
1 parent 07bd1dc commit 0cb2952
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 30 deletions.
29 changes: 0 additions & 29 deletions sql/branch.sql

This file was deleted.

30 changes: 30 additions & 0 deletions sql/currencies.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,36 @@ CREATE OPERATOR * (
commutator = *
);

CREATE FUNCTION currency_amount_mul(numeric, currency_amount)
RETURNS currency_amount AS $$
BEGIN
RETURN ($2.amount * $1, $2.currency);
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT;

CREATE OPERATOR * (
leftarg = numeric,
rightarg = currency_amount,
procedure = currency_amount_mul,
commutator = *
);

CREATE FUNCTION currency_amount_div(currency_amount, currency_amount)
RETURNS numeric AS $$
BEGIN
IF ($1.currency <> $2.currency) THEN
RAISE 'currency mistmatch: % != %', $1.currency, $2.currency;
END IF;
RETURN $1.amount / $2.amount;
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT;

CREATE OPERATOR / (
leftarg = currency_amount,
rightarg = currency_amount,
procedure = currency_amount_div
);


-- Aggregate functions

Expand Down
28 changes: 28 additions & 0 deletions sql/migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2397,3 +2397,31 @@ UPDATE participants

-- migration #110
DELETE FROM notifications WHERE event = 'identity_required';

-- migration #111
CREATE FUNCTION currency_amount_mul(numeric, currency_amount)
RETURNS currency_amount AS $$
BEGIN
RETURN ($2.amount * $1, $2.currency);
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT;
CREATE OPERATOR * (
leftarg = numeric,
rightarg = currency_amount,
procedure = currency_amount_mul,
commutator = *
);
CREATE FUNCTION currency_amount_div(currency_amount, currency_amount)
RETURNS numeric AS $$
BEGIN
IF ($1.currency <> $2.currency) THEN
RAISE 'currency mistmatch: % != %', $1.currency, $2.currency;
END IF;
RETURN $1.amount / $2.amount;
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT;
CREATE OPERATOR / (
leftarg = currency_amount,
rightarg = currency_amount,
procedure = currency_amount_div
);
2 changes: 1 addition & 1 deletion sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ COMMENT ON EXTENSION pg_stat_statements IS 'track execution statistics of all SQ

-- database metadata
CREATE TABLE db_meta (key text PRIMARY KEY, value jsonb);
INSERT INTO db_meta (key, value) VALUES ('schema_version', '110'::jsonb);
INSERT INTO db_meta (key, value) VALUES ('schema_version', '111'::jsonb);


-- app configuration
Expand Down

0 comments on commit 0cb2952

Please sign in to comment.