Skip to content

Commit

Permalink
WIP - May need to run bisect to determine why project won't build now
Browse files Browse the repository at this point in the history
  • Loading branch information
underbluewaters committed Jul 5, 2023
1 parent 6e694ed commit 5f7cb26
Show file tree
Hide file tree
Showing 20 changed files with 2,344 additions and 43,617 deletions.
62 changes: 62 additions & 0 deletions packages/api/generated-schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -6226,6 +6226,32 @@ type GetParentCollectionIdPayload {
query: Query
}

"""All input for the `getSpriteDataForScreenshot` mutation."""
input GetSpriteDataForScreenshotInput {
bookmark: MapBookmarkInput

"""
An arbitrary string value with no semantic meaning. Will be included in the
payload verbatim. May be used to track mutations by the client.
"""
clientMutationId: String
}

"""The output of our `getSpriteDataForScreenshot` mutation."""
type GetSpriteDataForScreenshotPayload {
"""
The exact same `clientMutationId` that was provided in the mutation input,
unchanged and unused. May be used by a client to track mutations.
"""
clientMutationId: String
jsons: [JSON]

"""
Our root query field type. Allows us to run any query from our mutation payload.
"""
query: Query
}

"""All input for the `grantAdminAccess` mutation."""
input GrantAdminAccessInput {
"""
Expand Down Expand Up @@ -6866,6 +6892,34 @@ input MapBookmarkCondition {
visibleDataLayers: [String]
}

"""An input for mutations affecting `MapBookmark`"""
input MapBookmarkInput {
basemapName: String
basemapOptionalLayerStates: JSON
cameraOptions: JSON!

"""
Generated by clients. Should not be used if authorative thumbnail (image_id) is available.
"""
clientGeneratedThumbnail: String
createdAt: Datetime
id: UUID
imageId: String
isPublic: Boolean
layerNames: JSON
mapDimensions: [Int]!
postId: Int
projectId: Int
screenshotJobStatus: WorkerJobStatus
selectedBasemap: Int!
sidebarState: JSON
sketchNames: JSON
style: JSON!
userId: Int!
visibleDataLayers: [String]
visibleSketches: [Int]
}

"""A connection to a list of `MapBookmark` values."""
type MapBookmarksConnection {
"""
Expand Down Expand Up @@ -7930,6 +7984,12 @@ type Mutation {
"""
input: GetParentCollectionIdInput!
): GetParentCollectionIdPayload
getSpriteDataForScreenshot(
"""
The exclusive input argument for this mutation. An object type, make sure to see documentation for this object’s fields.
"""
input: GetSpriteDataForScreenshotInput!
): GetSpriteDataForScreenshotPayload

"""
Give a user admin access to a project. User must have already joined the project and shared their user profile.
Expand Down Expand Up @@ -9339,6 +9399,7 @@ type Post implements Node {
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
"""
nodeId: ID!
orderedAttachmentIds: [String]
sketchIds: [Int]

"""Reads a single `Topic` that is related to this `Post`."""
Expand Down Expand Up @@ -10549,6 +10610,7 @@ type Query implements Node {
"""
build: String!
camelCase(snakeCase: String): String
collectAttachmentIdsFromProsemirrorBody(body: JSON, type: String): [String]
collectTextFromProsemirrorBodyForLabel(body: JSON): String
communityGuideline(projectId: Int!): CommunityGuideline

Expand Down
69 changes: 69 additions & 0 deletions packages/api/migrations/current.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
-- Enter migration here
grant insert on table map_bookmarks to seasketch_superuser;
COMMENT ON TABLE "public"."map_bookmarks" IS E'@omit create';
COMMENT ON FUNCTION get_sprite_data_for_screenshot IS E'@arg0variant base @omit';
grant execute on function bookmark_by_id to anon;
drop trigger if exists assign_file_upload_attachment_post_ids_from_message_contents on posts;
drop function if exists assign_file_upload_node_post_ids;
drop function if exists assign_post_id_to_attached_file_uploads;
drop function if exists collect_file_upload_ids_from_prosemirror_body;
drop function if exists posts_file_uploads;
drop function if exists create_file_upload;
drop table if exists file_uploads;


drop type if exists file_upload_usage;
create type file_upload_usage as enum ('forum_attachment', 'survey_response');
COMMENT ON TYPE file_upload_usage IS E'@enum';
Expand All @@ -25,6 +34,9 @@ create table file_uploads (
cloudflare_images_id text
);

grant insert on table file_uploads to seasketch_superuser;
COMMENT ON TABLE "public"."file_uploads" IS E'@omit create';

comment on column file_uploads.content_type is 'Use a listed media type from https://www.iana.org/assignments/media-types/media-types.xhtml';

create index on file_uploads (post_id);
Expand All @@ -42,3 +54,60 @@ comment on function posts_file_uploads is '@simpleCollections only';
grant execute on function posts_file_uploads to anon;

grant select on file_uploads to anon;

CREATE OR REPLACE FUNCTION public.collect_attachment_ids_from_prosemirror_body(body jsonb, type text) RETURNS text[]
LANGUAGE plpgsql IMMUTABLE
AS $$
declare
output text[];
i jsonb;
attachment jsonb;
begin
output = '{}';
if body ? 'attrs' and (body -> 'attrs') ? 'type' then
if type is null or (body -> 'attrs') ->> 'type' = type then
select body ->> 'attrs' into attachment;
if attachment is not null and attachment->>'id' is not null then
output = (attachment->>'id')::text || output;
end if;
end if;
end if;
if body ? 'content' and (body ->> 'type' = 'attachments' or body ->> 'type' = 'doc') then
for i in (select * from jsonb_array_elements((body->'content')))
loop
output = output || collect_attachment_ids_from_prosemirror_body(i, type);
end loop;
end if;
return output;
end;
$$;

grant execute on function collect_attachment_ids_from_prosemirror_body to anon;

CREATE FUNCTION public.assign_post_id_to_attached_file_uploads(body jsonb, post_id integer) RETURNS boolean
LANGUAGE plpgsql SECURITY DEFINER
AS $$
declare
file_upload_ids text[];
begin
select collect_attachment_ids_from_prosemirror_body(body, 'FileUpload') into file_upload_ids;
update file_uploads set post_id = assign_post_id_to_attached_file_uploads.post_id where id::text = any(file_upload_ids);
return true;
end;
$$;


CREATE FUNCTION public.assign_file_upload_node_post_ids() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
perform assign_post_id_to_attached_file_uploads(NEW.message_contents, NEW.id);
RETURN NEW;
END;
$$;

CREATE TRIGGER assign_file_upload_attachment_post_ids_from_message_contents AFTER INSERT OR UPDATE ON public.posts FOR EACH ROW EXECUTE FUNCTION public.assign_file_upload_node_post_ids();

alter table posts add column if not exists ordered_attachment_ids text[] generated always as (collect_attachment_ids_from_prosemirror_body(message_contents, null)) stored;

grant select on table file_uploads to seasketch_user;
Loading

0 comments on commit 5f7cb26

Please sign in to comment.