Skip to content

Commit d475b98

Browse files
authored
fold sql into dd.sql (#29)
1 parent 289530c commit d475b98

3 files changed

Lines changed: 24 additions & 28 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ X-FMSG-Act-As: @user_bot@example.com
111111
The requested address must be granted to the authenticated user and must exist
112112
in fmsgid.
113113

114-
Apply [dd.sql](dd.sql) before enabling API-key auth. Existing
115-
deployments that already applied the earlier API-key table should apply
116-
[api_keys_delegation.sql](api_keys_delegation.sql).
114+
Apply [dd.sql](dd.sql) before enabling API-key auth. The file is idempotent and
115+
also upgrades deployments that previously applied the earlier API-key table.
117116

118117
To set a custom per-owner grant limit, insert an owner config row:
119118

api_keys_delegation.sql

Lines changed: 0 additions & 25 deletions
This file was deleted.

dd.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ CREATE TABLE IF NOT EXISTS fmsg_api_sub_account (
3131
CHECK (agent = '' OR agent NOT LIKE '%\_%' ESCAPE '\')
3232
);
3333
34+
ALTER TABLE fmsg_api_sub_account
35+
ADD COLUMN IF NOT EXISTS grant_type text NOT NULL DEFAULT 'derived_sub_account';
36+
37+
ALTER TABLE fmsg_api_sub_account
38+
ADD COLUMN IF NOT EXISTS display_name text;
39+
40+
ALTER TABLE fmsg_api_sub_account
41+
DROP CONSTRAINT IF EXISTS fmsg_api_sub_account_sub_addr_key;
42+
43+
DO $$
44+
BEGIN
45+
IF NOT EXISTS (
46+
SELECT 1
47+
FROM pg_constraint
48+
WHERE conname = 'fmsg_api_sub_account_grant_type_check'
49+
) THEN
50+
ALTER TABLE fmsg_api_sub_account
51+
ADD CONSTRAINT fmsg_api_sub_account_grant_type_check
52+
CHECK (grant_type IN ('derived_sub_account', 'delegated_identity'));
53+
END IF;
54+
END $$;
55+
3456
CREATE INDEX IF NOT EXISTS fmsg_api_sub_account_owner_idx
3557
ON fmsg_api_sub_account ((lower(owner_addr)));
3658

0 commit comments

Comments
 (0)