-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
1,019 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,46 @@ | ||
ALTER TABLE tenants ADD COLUMN IF NOT EXISTS cursor_id SERIAL; | ||
ALTER TABLE tenants ADD COLUMN IF NOT EXISTS created_at TIMESTAMP DEFAULT current_timestamp; | ||
ALTER TABLE tenants ADD COLUMN IF NOT EXISTS migrations_version text null DEFAULT null; | ||
ALTER TABLE tenants ADD COLUMN IF NOT EXISTS migrations_status text null DEFAULT null; | ||
|
||
create index if not exists tenants_migration_version_idx on tenants(cursor_id, migrations_version, migrations_status); | ||
|
||
CREATE TABLE IF NOT EXISTS tenants_s3_credentials ( | ||
id UUID PRIMARY KEY default gen_random_uuid(), | ||
description text NOT NULL, | ||
tenant_id text REFERENCES tenants(id) ON DELETE CASCADE, | ||
access_key text NOT NULL, | ||
secret_key text NOT NULL, | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS tenants_s3_credentials_tenant_id_idx ON tenants_s3_credentials(tenant_id); | ||
CREATE UNIQUE INDEX IF NOT EXISTS tenants_s3_credentials_access_key_idx ON tenants_s3_credentials(tenant_id, access_key); | ||
|
||
|
||
CREATE FUNCTION tenants_s3_credentials_update_notify_trigger () | ||
RETURNS TRIGGER | ||
AS $$ | ||
BEGIN | ||
PERFORM | ||
pg_notify('tenants_s3_credentials_update', '"' || NEW.id || ':' || NEW.access_key || '"'); | ||
RETURN NULL; | ||
END; | ||
$$ | ||
LANGUAGE plpgsql; | ||
|
||
CREATE FUNCTION tenants_s3_credentials_delete_notify_trigger () | ||
RETURNS TRIGGER | ||
AS $$ | ||
BEGIN | ||
PERFORM | ||
pg_notify('tenants_s3_credentials_update', '"' || OLD.id || ':' || OLD.access_key || '"'); | ||
RETURN NULL; | ||
END; | ||
$$ | ||
LANGUAGE plpgsql; | ||
|
||
CREATE TRIGGER tenants_s3_credentials_update_notify_trigger | ||
AFTER UPDATE ON tenants_s3_credentials | ||
FOR EACH ROW | ||
EXECUTE PROCEDURE tenants_s3_credentials_update_notify_trigger (); | ||
|
||
CREATE TRIGGER tenants_s3_credentials_delete_notify_trigger | ||
AFTER DELETE ON tenants_s3_credentials | ||
FOR EACH ROW | ||
EXECUTE PROCEDURE tenants_s3_credentials_delete_notify_trigger (); |
3 changes: 3 additions & 0 deletions
3
migrations/multitenant/0009-add-scope-token-column-to-tenants-s3.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
ALTER TABLE tenants_s3_credentials ADD COLUMN scopes json NOT NULL DEFAULT '{}'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
ALTER TABLE storage._s3_multipart_uploads ALTER COLUMN in_progress_size TYPE bigint; | ||
ALTER TABLE storage._s3_multipart_uploads_parts ALTER COLUMN size TYPE bigint; | ||
ALTER TABLE storage.s3_multipart_uploads ALTER COLUMN in_progress_size TYPE bigint; | ||
ALTER TABLE storage.s3_multipart_uploads_parts ALTER COLUMN size TYPE bigint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
create or replace function storage.search ( | ||
prefix text, | ||
bucketname text, | ||
limits int default 100, | ||
levels int default 1, | ||
offsets int default 0, | ||
search text default '', | ||
sortcolumn text default 'name', | ||
sortorder text default 'asc' | ||
) returns table ( | ||
name text, | ||
id uuid, | ||
updated_at timestamptz, | ||
created_at timestamptz, | ||
last_accessed_at timestamptz, | ||
metadata jsonb | ||
) | ||
as $$ | ||
declare | ||
v_order_by text; | ||
v_sort_order text; | ||
begin | ||
case | ||
when sortcolumn = 'name' then | ||
v_order_by = 'name'; | ||
when sortcolumn = 'updated_at' then | ||
v_order_by = 'updated_at'; | ||
when sortcolumn = 'created_at' then | ||
v_order_by = 'created_at'; | ||
when sortcolumn = 'last_accessed_at' then | ||
v_order_by = 'last_accessed_at'; | ||
else | ||
v_order_by = 'name'; | ||
end case; | ||
|
||
case | ||
when sortorder = 'asc' then | ||
v_sort_order = 'asc'; | ||
when sortorder = 'desc' then | ||
v_sort_order = 'desc'; | ||
else | ||
v_sort_order = 'asc'; | ||
end case; | ||
|
||
v_order_by = v_order_by || ' ' || v_sort_order; | ||
|
||
return query execute | ||
'with folders as ( | ||
select path_tokens[$1] as folder | ||
from storage.objects | ||
where objects.name ilike $2 || $3 || ''%'' | ||
and bucket_id = $4 | ||
and array_length(objects.path_tokens, 1) <> $1 | ||
group by folder | ||
order by folder ' || v_sort_order || ' | ||
) | ||
(select folder as "name", | ||
null as id, | ||
null as updated_at, | ||
null as created_at, | ||
null as last_accessed_at, | ||
null as metadata from folders) | ||
union all | ||
(select path_tokens[$1] as "name", | ||
id, | ||
updated_at, | ||
created_at, | ||
last_accessed_at, | ||
metadata | ||
from storage.objects | ||
where objects.name ilike $2 || $3 || ''%'' | ||
and bucket_id = $4 | ||
and array_length(objects.path_tokens, 1) = $1 | ||
order by ' || v_order_by || ') | ||
limit $5 | ||
offset $6' using levels, prefix, search, bucketname, limits, offsets; | ||
end; | ||
$$ language plpgsql stable; |
Empty file.
Oops, something went wrong.