[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-merchant] 113/277: use unregister
From: |
gnunet |
Subject: |
[taler-merchant] 113/277: use unregister |
Date: |
Sun, 05 Jul 2020 20:50:26 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository merchant.
commit 75855e0fce31ff32654daad2e70e0f2186f3e9b0
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat May 16 11:14:34 2020 +0200
use unregister
---
src/backenddb/drop0001.sql | 5 +-
src/backenddb/merchant-0000.sql | 103 +++++++++++++++++++---------------------
src/backenddb/merchant-0001.sql | 2 +-
3 files changed, 53 insertions(+), 57 deletions(-)
diff --git a/src/backenddb/drop0001.sql b/src/backenddb/drop0001.sql
index caf85e6..81b7691 100644
--- a/src/backenddb/drop0001.sql
+++ b/src/backenddb/drop0001.sql
@@ -47,9 +47,8 @@ DROP TABLE IF EXISTS merchant_tips CASCADE;
DROP TABLE IF EXISTS merchant_tip_pickups CASCADE;
DROP TABLE IF EXISTS merchant_tip_pickup_signatures CASCADE;
--- Drop versioning (0000.sql)
--- FIXME: rename _mv to avoid conflicts with exchange versioning in tests!
-DROP SCHEMA IF EXISTS _mv CASCADE;
+-- Unregister patch (0001.sql)
+_v.unregister_patch('merchant-0001', NULL, NULL);
-- And we're out of here...
COMMIT;
diff --git a/src/backenddb/merchant-0000.sql b/src/backenddb/merchant-0000.sql
index 54553c6..98e7f66 100644
--- a/src/backenddb/merchant-0000.sql
+++ b/src/backenddb/merchant-0000.sql
@@ -34,9 +34,6 @@
--
-- Code origin:
https://gitlab.com/depesz/Versioning/blob/master/install.versioning.sql
--
--- MODIFICATION: changed "_v" to "_mv" to ensure that we do NOT conflict with
--- the table versioning of the exchange in case we share the
same DB
--- (problematic in particular with respect to drop0001.sql).
--
-- # NAME
--
@@ -60,7 +57,7 @@
-- # USAGE
--
-- In your files with patches to database, put whole logic in single
--- transaction, and use \_mv.\* functions - usually \_mv.register_patch() at
+-- transaction, and use \_v.\* functions - usually \_v.register_patch() at
-- least to make sure everything is OK.
--
-- For example. Let's assume you have patch files:
@@ -83,7 +80,7 @@
--
-- ```
-- BEGIN;
--- select _mv.register_patch('000-base', NULL, NULL);
+-- select _v.register_patch('000-base', NULL, NULL);
-- create table users (id serial primary key, username text);
-- COMMIT;
-- ```
@@ -92,7 +89,7 @@
--
-- ```
-- BEGIN;
--- select _mv.register_patch('001-users', ARRAY['000-base'], NULL);
+-- select _v.register_patch('001-users', ARRAY['000-base'], NULL);
-- insert into users (username) values ('depesz');
-- COMMIT;
-- ```
@@ -102,45 +99,45 @@
--
-- # AVAILABLE FUNCTIONS
--
--- ## \_mv.register_patch( TEXT )
+-- ## \_v.register_patch( TEXT )
--
-- Registers named patch, or dies if it is already registered.
--
--- Returns integer which is id of patch in \_mv.patches table - only if it
+-- Returns integer which is id of patch in \_v.patches table - only if it
-- succeeded.
--
--- ## \_mv.register_patch( TEXT, TEXT[] )
+-- ## \_v.register_patch( TEXT, TEXT[] )
--
--- Same as \_mv.register_patch( TEXT ), but checks is all given patches (given
as
+-- Same as \_v.register_patch( TEXT ), but checks is all given patches (given
as
-- array in second argument) are already registered.
--
--- ## \_mv.register_patch( TEXT, TEXT[], TEXT[] )
+-- ## \_v.register_patch( TEXT, TEXT[], TEXT[] )
--
--- Same as \_mv.register_patch( TEXT, TEXT[] ), but also checks if there are
no conflicts with preexisting patches.
+-- Same as \_v.register_patch( TEXT, TEXT[] ), but also checks if there are no
conflicts with preexisting patches.
--
-- Third argument is array of names of patches that conflict with current one.
So
-- if any of them is installed - register_patch will error out.
--
--- ## \_mv.unregister_patch( TEXT )
+-- ## \_v.unregister_patch( TEXT )
--
-- Removes information about given patch from the versioning data.
--
-- It doesn't remove objects that were created by this patch - just removes
-- metainformation.
--
--- ## \_mv.assert_user_is_superuser()
+-- ## \_v.assert_user_is_superuser()
--
-- Make sure that current patch is being loaded by superuser.
--
-- If it's not - it will raise exception, and break transaction.
--
--- ## \_mv.assert_user_is_not_superuser()
+-- ## \_v.assert_user_is_not_superuser()
--
-- Make sure that current patch is not being loaded by superuser.
--
-- If it is - it will raise exception, and break transaction.
--
--- ## \_mv.assert_user_is_one_of(TEXT, TEXT, ... )
+-- ## \_v.assert_user_is_one_of(TEXT, TEXT, ... )
--
-- Make sure that current patch is being loaded by one of listed users.
--
@@ -151,42 +148,42 @@ BEGIN;
-- This file adds versioning support to database it will be loaded to.
-- It requires that PL/pgSQL is already loaded - will raise exception
otherwise.
--- All versioning "stuff" (tables, functions) is in "_mv" schema.
+-- All versioning "stuff" (tables, functions) is in "_v" schema.
-- All functions are defined as 'RETURNS SETOF INT4' to be able to make them
to RETURN literally nothing (0 rows).
-- >> RETURNS VOID<< IS similar, but it still outputs "empty line" in psql
when calling.
-CREATE SCHEMA IF NOT EXISTS _mv;
-COMMENT ON SCHEMA _mv IS 'Schema for versioning data and functionality.';
+CREATE SCHEMA IF NOT EXISTS _v;
+COMMENT ON SCHEMA _v IS 'Schema for versioning data and functionality.';
-CREATE TABLE IF NOT EXISTS _mv.patches (
+CREATE TABLE IF NOT EXISTS _v.patches (
patch_name TEXT PRIMARY KEY,
applied_tsz TIMESTAMPTZ NOT NULL DEFAULT now(),
applied_by TEXT NOT NULL,
requires TEXT[],
conflicts TEXT[]
);
-COMMENT ON TABLE _mv.patches IS 'Contains information about what
patches are currently applied on database.';
-COMMENT ON COLUMN _mv.patches.patch_name IS 'Name of patch, has to be unique
for every patch.';
-COMMENT ON COLUMN _mv.patches.applied_tsz IS 'When the patch was applied.';
-COMMENT ON COLUMN _mv.patches.applied_by IS 'Who applied this patch
(PostgreSQL username)';
-COMMENT ON COLUMN _mv.patches.requires IS 'List of patches that are
required for given patch.';
-COMMENT ON COLUMN _mv.patches.conflicts IS 'List of patches that conflict
with given patch.';
+COMMENT ON TABLE _v.patches IS 'Contains information about what
patches are currently applied on database.';
+COMMENT ON COLUMN _v.patches.patch_name IS 'Name of patch, has to be unique
for every patch.';
+COMMENT ON COLUMN _v.patches.applied_tsz IS 'When the patch was applied.';
+COMMENT ON COLUMN _v.patches.applied_by IS 'Who applied this patch
(PostgreSQL username)';
+COMMENT ON COLUMN _v.patches.requires IS 'List of patches that are required
for given patch.';
+COMMENT ON COLUMN _v.patches.conflicts IS 'List of patches that conflict
with given patch.';
-CREATE OR REPLACE FUNCTION _mv.register_patch( IN in_patch_name TEXT, IN
in_requirements TEXT[], in_conflicts TEXT[], OUT versioning INT4 ) RETURNS
setof INT4 AS $$
+CREATE OR REPLACE FUNCTION _v.register_patch( IN in_patch_name TEXT, IN
in_requirements TEXT[], in_conflicts TEXT[], OUT versioning INT4 ) RETURNS
setof INT4 AS $$
DECLARE
t_text TEXT;
t_text_a TEXT[];
i INT4;
BEGIN
-- Thanks to this we know only one patch will be applied at a time
- LOCK TABLE _mv.patches IN EXCLUSIVE MODE;
+ LOCK TABLE _v.patches IN EXCLUSIVE MODE;
- SELECT patch_name INTO t_text FROM _mv.patches WHERE patch_name =
in_patch_name;
+ SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name =
in_patch_name;
IF FOUND THEN
RAISE EXCEPTION 'Patch % is already applied!', in_patch_name;
END IF;
- t_text_a := ARRAY( SELECT patch_name FROM _mv.patches WHERE patch_name =
any( in_conflicts ) );
+ t_text_a := ARRAY( SELECT patch_name FROM _v.patches WHERE patch_name =
any( in_conflicts ) );
IF array_upper( t_text_a, 1 ) IS NOT NULL THEN
RAISE EXCEPTION 'Versioning patches conflict. Conflicting patche(s)
installed: %.', array_to_string( t_text_a, ', ' );
END IF;
@@ -194,7 +191,7 @@ BEGIN
IF array_upper( in_requirements, 1 ) IS NOT NULL THEN
t_text_a := '{}';
FOR i IN array_lower( in_requirements, 1 ) .. array_upper(
in_requirements, 1 ) LOOP
- SELECT patch_name INTO t_text FROM _mv.patches WHERE patch_name =
in_requirements[i];
+ SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name =
in_requirements[i];
IF NOT FOUND THEN
t_text_a := t_text_a || in_requirements[i];
END IF;
@@ -204,35 +201,35 @@ BEGIN
END IF;
END IF;
- INSERT INTO _mv.patches (patch_name, applied_tsz, applied_by, requires,
conflicts ) VALUES ( in_patch_name, now(), current_user, coalesce(
in_requirements, '{}' ), coalesce( in_conflicts, '{}' ) );
+ INSERT INTO _v.patches (patch_name, applied_tsz, applied_by, requires,
conflicts ) VALUES ( in_patch_name, now(), current_user, coalesce(
in_requirements, '{}' ), coalesce( in_conflicts, '{}' ) );
RETURN;
END;
$$ language plpgsql;
-COMMENT ON FUNCTION _mv.register_patch( TEXT, TEXT[], TEXT[] ) IS 'Function to
register patches in database. Raises exception if there are conflicts,
prerequisites are not installed or the migration has already been installed.';
+COMMENT ON FUNCTION _v.register_patch( TEXT, TEXT[], TEXT[]) IS 'Function to
register patches in database. Raises exception if there are conflicts,
prerequisites are not installed or the migration has already been installed.';
-CREATE OR REPLACE FUNCTION _mv.register_patch( TEXT, TEXT[] ) RETURNS setof
INT4 AS $$
- SELECT _mv.register_patch( $1, $2, NULL );
+CREATE OR REPLACE FUNCTION _v.register_patch( TEXT, TEXT[] ) RETURNS setof
INT4 AS $$
+ SELECT _v.register_patch( $1, $2, NULL );
$$ language sql;
-COMMENT ON FUNCTION _mv.register_patch( TEXT, TEXT[] ) IS 'Wrapper to allow
registration of patches without conflicts.';
-CREATE OR REPLACE FUNCTION _mv.register_patch( TEXT ) RETURNS setof INT4 AS $$
- SELECT _mv.register_patch( $1, NULL, NULL );
+COMMENT ON FUNCTION _v.register_patch( TEXT, TEXT[] ) IS 'Wrapper to allow
registration of patches without conflicts.';
+CREATE OR REPLACE FUNCTION _v.register_patch( TEXT ) RETURNS setof INT4 AS $$
+ SELECT _v.register_patch( $1, NULL, NULL );
$$ language sql;
-COMMENT ON FUNCTION _mv.register_patch( TEXT ) IS 'Wrapper to allow
registration of patches without requirements and conflicts.';
+COMMENT ON FUNCTION _v.register_patch( TEXT ) IS 'Wrapper to allow
registration of patches without requirements and conflicts.';
-CREATE OR REPLACE FUNCTION _mv.unregister_patch( IN in_patch_name TEXT, OUT
versioning INT4 ) RETURNS setof INT4 AS $$
+CREATE OR REPLACE FUNCTION _v.unregister_patch( IN in_patch_name TEXT, OUT
versioning INT4 ) RETURNS setof INT4 AS $$
DECLARE
i INT4;
t_text_a TEXT[];
BEGIN
-- Thanks to this we know only one patch will be applied at a time
- LOCK TABLE _mv.patches IN EXCLUSIVE MODE;
+ LOCK TABLE _v.patches IN EXCLUSIVE MODE;
- t_text_a := ARRAY( SELECT patch_name FROM _mv.patches WHERE in_patch_name
= ANY( requires ) );
+ t_text_a := ARRAY( SELECT patch_name FROM _v.patches WHERE in_patch_name =
ANY( requires ) );
IF array_upper( t_text_a, 1 ) IS NOT NULL THEN
RAISE EXCEPTION 'Cannot uninstall %, as it is required by: %.',
in_patch_name, array_to_string( t_text_a, ', ' );
END IF;
- DELETE FROM _mv.patches WHERE patch_name = in_patch_name;
+ DELETE FROM _v.patches WHERE patch_name = in_patch_name;
GET DIAGNOSTICS i = ROW_COUNT;
IF i < 1 THEN
RAISE EXCEPTION 'Patch % is not installed, so it can''t be
uninstalled!', in_patch_name;
@@ -241,22 +238,22 @@ BEGIN
RETURN;
END;
$$ language plpgsql;
-COMMENT ON FUNCTION _mv.unregister_patch( TEXT ) IS 'Function to unregister
patches in database. Dies if the patch is not registered, or if unregistering
it would break dependencies.';
+COMMENT ON FUNCTION _v.unregister_patch( TEXT ) IS 'Function to unregister
patches in database. Dies if the patch is not registered, or if unregistering
it would break dependencies.';
-CREATE OR REPLACE FUNCTION _mv.assert_patch_is_applied( IN in_patch_name TEXT
) RETURNS TEXT as $$
+CREATE OR REPLACE FUNCTION _v.assert_patch_is_applied( IN in_patch_name TEXT )
RETURNS TEXT as $$
DECLARE
t_text TEXT;
BEGIN
- SELECT patch_name INTO t_text FROM _mv.patches WHERE patch_name =
in_patch_name;
+ SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name =
in_patch_name;
IF NOT FOUND THEN
RAISE EXCEPTION 'Patch % is not applied!', in_patch_name;
END IF;
RETURN format('Patch %s is applied.', in_patch_name);
END;
$$ language plpgsql;
-COMMENT ON FUNCTION _mv.assert_patch_is_applied( TEXT ) IS 'Function that can
be used to make sure that patch has been applied.';
+COMMENT ON FUNCTION _v.assert_patch_is_applied( TEXT ) IS 'Function that can
be used to make sure that patch has been applied.';
-CREATE OR REPLACE FUNCTION _mv.assert_user_is_superuser() RETURNS TEXT as $$
+CREATE OR REPLACE FUNCTION _v.assert_user_is_superuser() RETURNS TEXT as $$
DECLARE
v_super bool;
BEGIN
@@ -267,9 +264,9 @@ BEGIN
RAISE EXCEPTION 'Current user is not superuser - cannot continue.';
END;
$$ language plpgsql;
-COMMENT ON FUNCTION _mv.assert_user_is_superuser() IS 'Function that can be
used to make sure that patch is being applied using superuser account.';
+COMMENT ON FUNCTION _v.assert_user_is_superuser() IS 'Function that can be
used to make sure that patch is being applied using superuser account.';
-CREATE OR REPLACE FUNCTION _mv.assert_user_is_not_superuser() RETURNS TEXT as
$$
+CREATE OR REPLACE FUNCTION _v.assert_user_is_not_superuser() RETURNS TEXT as $$
DECLARE
v_super bool;
BEGIN
@@ -280,9 +277,9 @@ BEGIN
RETURN 'assert_user_is_not_superuser: OK';
END;
$$ language plpgsql;
-COMMENT ON FUNCTION _mv.assert_user_is_not_superuser() IS 'Function that can
be used to make sure that patch is being applied using normal (not superuser)
account.';
+COMMENT ON FUNCTION _v.assert_user_is_not_superuser() IS 'Function that can be
used to make sure that patch is being applied using normal (not superuser)
account.';
-CREATE OR REPLACE FUNCTION _mv.assert_user_is_one_of(VARIADIC
p_acceptable_users TEXT[] ) RETURNS TEXT as $$
+CREATE OR REPLACE FUNCTION _v.assert_user_is_one_of(VARIADIC
p_acceptable_users TEXT[] ) RETURNS TEXT as $$
DECLARE
BEGIN
IF current_user = any( p_acceptable_users ) THEN
@@ -291,6 +288,6 @@ BEGIN
RAISE EXCEPTION 'User is not one of: % - cannot continue.',
p_acceptable_users;
END;
$$ language plpgsql;
-COMMENT ON FUNCTION _mv.assert_user_is_one_of(TEXT[]) IS 'Function that can be
used to make sure that patch is being applied by one of defined users.';
+COMMENT ON FUNCTION _v.assert_user_is_one_of(TEXT[]) IS 'Function that can be
used to make sure that patch is being applied by one of defined users.';
COMMIT;
diff --git a/src/backenddb/merchant-0001.sql b/src/backenddb/merchant-0001.sql
index 2f1efd3..9eb60e5 100644
--- a/src/backenddb/merchant-0001.sql
+++ b/src/backenddb/merchant-0001.sql
@@ -18,7 +18,7 @@
BEGIN;
-- Check patch versioning is in place.
-SELECT _mv.register_patch('merchant-0001', NULL, NULL);
+SELECT _v.register_patch('merchant-0001', NULL, NULL);
---------------- Exchange information ---------------------------
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-merchant] 117/277: get simple pay test to pass, (continued)
- [taler-merchant] 117/277: get simple pay test to pass, gnunet, 2020/07/05
- [taler-merchant] 94/277: fix ftbfs, gnunet, 2020/07/05
- [taler-merchant] 98/277: implement POST /transfers, gnunet, 2020/07/05
- [taler-merchant] 107/277: implement GET /transfers, gnunet, 2020/07/05
- [taler-merchant] 106/277: implement merchant_api_post_transfers.c, gnunet, 2020/07/05
- [taler-merchant] 111/277: fix link errors in test, gnunet, 2020/07/05
- [taler-merchant] 90/277: starting with get-orders-ID logic, gnunet, 2020/07/05
- [taler-merchant] 92/277: fix backenddb, gnunet, 2020/07/05
- [taler-merchant] 97/277: integrate POST /tranfers handler, gnunet, 2020/07/05
- [taler-merchant] 105/277: API design for /transfers, gnunet, 2020/07/05
- [taler-merchant] 113/277: use unregister,
gnunet <=
- [taler-merchant] 112/277: rename _v to _mv for merchant, gnunet, 2020/07/05
- [taler-merchant] 118/277: implement POST /reserves, gnunet, 2020/07/05
- [taler-merchant] 122/277: fixed bool casts in plugin initialization, gnunet, 2020/07/05
- [taler-merchant] 129/277: fixed coding style in db tests and double callbacks in lookup_instances, gnunet, 2020/07/05
- [taler-merchant] 131/277: towards POST tips pickup impl, gnunet, 2020/07/05
- [taler-merchant] 120/277: implement insert_reserve, gnunet, 2020/07/05
- [taler-merchant] 125/277: more work on GET /reserves logic, gnunet, 2020/07/05
- [taler-merchant] 99/277: more work on post /transfers and the like, gnunet, 2020/07/05
- [taler-merchant] 93/277: updates, gnunet, 2020/07/05
- [taler-merchant] 100/277: more work on POST /transfer, gnunet, 2020/07/05