Skip to content

Commit dcb9757

Browse files
committed
sync ext from launchql pg
1 parent 1e0f4db commit dcb9757

11 files changed

Lines changed: 48 additions & 16 deletions

File tree

packages/data-types/types/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ Core PostgreSQL data types with SQL scripts.
2222

2323
- **email**: Case-insensitive email address validation
2424
- **url**: HTTP/HTTPS URL validation
25+
- **origin**: Origin URL validation (scheme + host)
2526
- **hostname**: Domain name validation
2627
- **image**: JSON-based image metadata with URL and MIME type
27-
- **attachment**: JSON-based file attachment metadata with URL and MIME type
28+
- **attachment**: File attachment metadata as a URL string or JSON with URL and MIME type
2829
- **upload**: File upload metadata
2930
- **single_select**: Single selection field
3031
- **multiple_select**: Multiple selection field
@@ -156,7 +157,7 @@ INSERT INTO customers (domain) VALUES
156157

157158
### Image and Attachment Domains
158159

159-
The `image` and `attachment` domains store JSON objects with URL and MIME type information.
160+
The `image` domain stores JSON objects with URL and MIME type information. The `attachment` domain accepts either that JSON shape or a plain URL string.
160161

161162
```sql
162163
-- Valid image
@@ -166,19 +167,23 @@ INSERT INTO customers (profile_image) VALUES
166167
-- Valid attachment
167168
INSERT INTO customers (document) VALUES
168169
('{"url": "https://storage.example.com/file.pdf", "mime": "application/pdf"}'::json);
170+
171+
-- Valid attachment as plain URL
172+
INSERT INTO customers (document) VALUES ('https://storage.example.com/favicon.ico');
169173
```
170174

171-
**Structure**: Both domains expect JSON objects with `url` and `mime` properties.
175+
**Structure**: Image values and JSON-form attachments expect `url` and `mime` properties; attachments also allow a bare URL string.
172176

173177
## Domain Types Reference
174178

175179
| Domain | Base Type | Description | Example |
176180
|--------|-----------|-------------|---------|
177181
| `email` | `citext` | Case-insensitive email address | `user@example.com` |
178182
| `url` | `text` | HTTP/HTTPS URL | `https://example.com/path` |
183+
| `origin` | `text` | Origin (scheme + host) | `https://example.com` |
179184
| `hostname` | `text` | Domain name without protocol | `example.com` |
180185
| `image` | `json` | Image metadata with URL and MIME | `{"url": "...", "mime": "image/jpeg"}` |
181-
| `attachment` | `json` | File attachment metadata | `{"url": "...", "mime": "application/pdf"}` |
186+
| `attachment` | `json` | File attachment URL or metadata | `{"url": "...", "mime": "application/pdf"}` or `https://example.com/favicon.ico` |
182187
| `upload` | `text` | File upload identifier | Various formats |
183188
| `single_select` | `text` | Single selection value | Text value |
184189
| `multiple_select` | `text[]` | Multiple selection values | Array of text values |

packages/data-types/types/deploy/schemas/public/domains/attachment.sql

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33

44
BEGIN;
55
CREATE DOMAIN attachment AS jsonb CHECK (
6-
value ?& ARRAY['url', 'mime']
7-
AND
8-
value->>'url' ~ '^(https?)://[^\s/$.?#].[^\s]*$'
6+
(
7+
jsonb_typeof(VALUE) = 'object'
8+
AND VALUE ?& ARRAY['url', 'mime']
9+
AND VALUE->>'url' ~ '^(https?)://[^\\s/$.?#].[^\\s]*$'
10+
)
11+
OR (
12+
jsonb_typeof(VALUE) = 'string'
13+
AND VALUE #>> '{}' ~ '^(https?)://[^\\s/$.?#].[^\\s]*$'
14+
)
915
);
1016
COMMENT ON DOMAIN attachment IS E'@name launchqlInternalTypeAttachment';
1117
COMMIT;
12-

packages/data-types/types/pgpm.plan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ schemas/public/domains/email [schemas/public/schema] 2017-08-11T08:11:51Z skitch
88
schemas/public/domains/hostname [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/hostname
99
schemas/public/domains/image [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/image
1010
schemas/public/domains/multiple_select [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/multiple_select
11+
schemas/public/domains/origin [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/origin
1112
schemas/public/domains/single_select [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/single_select
1213
schemas/public/domains/upload [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/upload
1314
schemas/public/domains/url [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/url

packages/security/defaults/deploy/defaults/public.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ $$;
1313
-- NOTE: don't alter this as new schemas inherit this behavior
1414
ALTER DEFAULT PRIVILEGES REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;
1515
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
16+
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO authenticated, anonymous, administrator;
17+
ALTER DEFAULT PRIVILEGES IN SCHEMA public
18+
GRANT EXECUTE ON FUNCTIONS TO authenticated, anonymous, administrator;
1619
COMMIT;
17-

packages/security/jwt-claims/launchql-jwt-claims.control

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
comment = 'launchql-jwt-claims extension'
33
default_version = '0.9.0'
44
module_pathname = '$libdir/launchql-jwt-claims'
5-
requires = 'plpgsql,uuid-ossp,launchql-verify'
5+
requires = 'plpgsql,uuid-ossp,launchql-types,launchql-verify'
66
relocatable = false
77
superuser = false
8-
8+

packages/security/jwt-claims/pgpm.plan

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22
%project=launchql-jwt-claims
33
%uri=launchql-jwt-claims
44

5+
schemas/ctx/schema 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/ctx/schema
6+
schemas/ctx/procedures/ip_address [schemas/ctx/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/ctx/procedures/ip_address
7+
schemas/ctx/procedures/origin [schemas/ctx/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/ctx/procedures/origin
8+
schemas/ctx/procedures/user_agent [schemas/ctx/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/ctx/procedures/user_agent
9+
schemas/ctx/procedures/user_id [schemas/ctx/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/ctx/procedures/user_id
10+
schemas/ctx/procedures/security_definer [schemas/ctx/schema] 2021-04-20T04:04:08Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/ctx/procedures/security_definer
511
schemas/jwt_public/schema 2020-12-17T06:47:29Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_public/schema
6-
schemas/jwt_private/schema 2020-12-17T06:47:34Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_private/schema
712
schemas/jwt_public/procedures/current_user_id [schemas/jwt_public/schema] 2020-12-17T06:48:56Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_public/procedures/current_user_id
813
schemas/jwt_public/procedures/current_ip_address [schemas/jwt_public/schema] 2020-12-17T23:19:17Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_public/procedures/current_ip_address
914
schemas/jwt_public/procedures/current_user_agent [schemas/jwt_public/schema] 2020-12-17T23:20:04Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_public/procedures/current_user_agent
10-
schemas/jwt_private/procedures/current_database_id [schemas/jwt_private/schema] 2020-12-17T23:22:28Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_private/procedures/current_database_id
15+
schemas/jwt_public/procedures/current_origin [schemas/jwt_public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/jwt_public/procedures/current_origin
1116
schemas/jwt_public/procedures/current_group_ids [schemas/jwt_public/schema] 2020-12-17T23:30:50Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_public/procedures/current_group_ids
17+
schemas/jwt_private/schema 2020-12-17T06:47:34Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_private/schema
18+
schemas/jwt_private/procedures/current_database_id [schemas/jwt_private/schema] 2020-12-17T23:22:28Z Dan Lynch <dlynch@Dans-MBP-3> # add schemas/jwt_private/procedures/current_database_id
19+
schemas/jwt_private/procedures/current_token_id [schemas/jwt_private/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/jwt_private/procedures/current_token_id

packages/security/jwt-claims/revert/schemas/ctx/procedures/security_definer.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
BEGIN;
44

55
DROP FUNCTION ctx.security_definer;
6+
DROP FUNCTION ctx.is_security_definer;
67

78
COMMIT;

packages/security/jwt-claims/verify/schemas/ctx/procedures/security_definer.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
BEGIN;
44

55
SELECT verify_function ('ctx.security_definer');
6+
SELECT verify_function ('ctx.is_security_definer');
67

78
ROLLBACK;

packages/utils/inflection/deploy/schemas/inflection/procedures/underscore.sql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,12 @@ FROM
4848
$$
4949
LANGUAGE 'sql'
5050
IMMUTABLE;
51-
COMMIT;
5251

52+
CREATE FUNCTION inflection.underscore (parts text[])
53+
RETURNS text
54+
AS $$
55+
SELECT inflection.underscore( array_to_string(parts, '_') );
56+
$$
57+
LANGUAGE 'sql'
58+
IMMUTABLE;
59+
COMMIT;

packages/utils/inflection/revert/schemas/inflection/procedures/underscore.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
BEGIN;
44

5-
DROP FUNCTION inflection.underscore;
5+
DROP FUNCTION inflection.underscore(text[]);
6+
DROP FUNCTION inflection.underscore(text);
67

78
COMMIT;

0 commit comments

Comments
 (0)