commit f56e2962da5602b9859ba2555ee6d14f50763cc5
parent 94a4d5f9958c8787530b1be1348435fd32badd7a
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Thu, 11 Dec 2025 12:15:50 +0900
dd77: draft migration DB
Diffstat:
1 file changed, 53 insertions(+), 0 deletions(-)
diff --git a/design-documents/077-merchant-self-provisioning.rst b/design-documents/077-merchant-self-provisioning.rst
@@ -82,6 +82,59 @@ Currently, authentication is tied to the instance itself, which is protected by
The current design can be migrated by (automatically) creating a user for each existing instance and its password moved to the new user.
The ID of the new user is then also immediately associated with the instance as a valid (admin) user.
+Example:
+
+::
+
+ BEGIN;
+
+ -- Check patch versioning is in place.
+ SELECT _v.register_patch('merchant-0028', NULL, NULL);
+
+ SET search_path TO merchant;
+
+ -------------------------- Users ---------------------------
+
+ CREATE TABLE IF NOT EXISTS merchant_users
+ (user_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
+ ,user_id TEXT NOT NULL UNIQUE
+ ,auth_hash BYTEA CHECK(LENGTH(auth_hash)=64)
+ ,auth_salt BYTEA CHECK(LENGTH(auth_salt)=32)
+ );
+ COMMENT ON TABLE merchant_users
+ IS 'all the users enrolled in this backend';
+ COMMENT ON COLUMN merchant_users.user_id
+ IS 'identifier of the user (required)';
+ COMMENT ON COLUMN merchant_users.auth_hash
+ IS 'hash used for merchant back office authorization, may be NULL (unset)';
+ COMMENT ON COLUMN merchant_users.auth_salt
+ IS 'salt to use when hashing password before comparing with auth_hash';
+
+
+ --- FIXME not sure if that is what we want...
+ CREATE TABLE IF NOT EXISTS merchant_instance_users
+ (user_serial BIGINT
+ REFERENCES merchant_users (user_serial) ON DELETE CASCADE,
+ merchant_serial BIGINT
+ REFERENCES merchant_instances (merchant_serial) ON DELETE CASCADE );
+ COMMENT ON COLUMN merchant_instance_users.user_serial
+ IS 'identifies an the admin user of the instance';
+
+ COMMENT ON COLUMN merchant_login_tokens.merchant_serial
+ IS 'identifies the instance for which the user is admin';
+
+
+ INSERT INTO merchant_users (user_id, auth_hash, auth_salt)
+ SELECT merchant_id, auth_hash, auth_salt FROM merchant_instances;
+
+ ALTER TABLE merchant_instances
+ DROP COLUMN auth_hash;
+
+ ALTER TABLE merchant_instances
+ DROP COLUMN auth_salt;
+
+ COMMIT;
+
Test Plan
=========