Skip to content

Commit 594ae0f

Browse files
authored
Merge pull request #11 from launchql/fix/sync-ext-from-lql-pg
sync exts from lql pg back here
2 parents 1e0f4db + 10b4421 commit 594ae0f

39 files changed

Lines changed: 139 additions & 29 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-
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
-- Deploy schemas/public/domains/origin to pg
2-
32
-- requires: schemas/public/schema
43

54
BEGIN;
6-
7-
CREATE DOMAIN origin AS text CHECK (VALUE = substring(VALUE from '^(https?://[^/]*)') );
5+
CREATE DOMAIN origin AS text CHECK (VALUE = substring(VALUE from '^(https?://[^/]*)'));
86
COMMENT ON DOMAIN origin IS E'@name launchqlInternalTypeOrigin';
9-
107
COMMIT;
8+

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/data-types/types/revert/schemas/public/domains/origin.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ BEGIN;
55
DROP TYPE public.origin;
66

77
COMMIT;
8+

packages/data-types/types/verify/schemas/public/domains/origin.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ BEGIN;
55
SELECT verify_type ('public.origin');
66

77
ROLLBACK;
8+

packages/security/defaults/__tests__/__snapshots__/defaults.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports[`defaults security configurations configuration verification should crea
66
{
77
"current_user": "postgres",
88
"database_name": "test-database",
9-
"default_func_acl_count": "1",
9+
"default_func_acl_count": "2",
1010
"public_db_connect": false,
1111
"public_db_create": false,
1212
"public_schema_create": false,

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/defaults/sql/launchql-defaults--0.9.0.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ $EOFCODE$;
1212
ALTER DEFAULT PRIVILEGES
1313
REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC RESTRICT;
1414

15-
REVOKE CREATE ON SCHEMA public FROM PUBLIC RESTRICT;
15+
REVOKE CREATE ON SCHEMA public FROM PUBLIC RESTRICT;
16+
17+
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public
18+
TO authenticated, anonymous, administrator;
19+
20+
ALTER DEFAULT PRIVILEGES IN SCHEMA public
21+
GRANT EXECUTE ON FUNCTIONS TO authenticated, anonymous, administrator;

packages/security/jwt-claims/deploy/schemas/ctx/procedures/ip_address.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ AS $$
1111
$$
1212
LANGUAGE 'sql' STABLE;
1313

14-
COMMIT;
14+
COMMIT;
15+

0 commit comments

Comments
 (0)