-
Notifications
You must be signed in to change notification settings - Fork 4
two migration errors #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
two migration errors #224
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| -- complete migration 20250610201801_create_access_table.sql | ||
|
|
||
| revoke delete on table "public"."access_token" from "anon"; | ||
|
|
||
| revoke references on table "public"."access_token" from "anon"; | ||
|
|
||
| revoke trigger on table "public"."access_token" from "anon"; | ||
|
|
||
| revoke truncate on table "public"."access_token" from "anon"; | ||
|
|
||
| revoke update on table "public"."access_token" from "anon"; | ||
|
|
||
| -- rename in schema was not ported to migration 20250611180757_concept_upsert_functions.sql | ||
|
|
||
| alter function "public".local_concept_to_db_concept(data concept_local_input) rename to _local_concept_to_db_concept; | ||
maparent marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| CREATE OR REPLACE FUNCTION public.upsert_concepts(v_space_id bigint, data jsonb) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What error is this fixing? Could you link the the source of the error?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because I renamed the function to indicate it's private in the schema but forgot to do so in the migration. So in this migration I rename the private function, and I have to re-define the function that uses it to use the new name. It is the only change to that function. Here I'm clearly migrating to align to the schema as source of truth.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| RETURNS SETOF bigint | ||
| LANGUAGE plpgsql | ||
| AS $function$ | ||
| DECLARE | ||
| v_platform public."Platform"; | ||
| local_concept public.concept_local_input; | ||
| db_concept public."Concept"%ROWTYPE; | ||
| concept_row JSONB; | ||
| concept_id BIGINT; | ||
| BEGIN | ||
| SELECT platform INTO STRICT v_platform FROM public."Space" WHERE id=v_space_id; | ||
| FOR concept_row IN SELECT * FROM jsonb_array_elements(data) | ||
| LOOP | ||
| -- first set defaults | ||
| local_concept := jsonb_populate_record(NULL::public.concept_local_input, '{"epistemic_status": "unknown", "literal_content":{},"reference_content":{},"is_schema":false}'); | ||
| -- then input values | ||
| local_concept := jsonb_populate_record(local_concept, concept_row); | ||
| local_concept.space_id := v_space_id; | ||
| db_concept := public._local_concept_to_db_concept(local_concept); | ||
| BEGIN | ||
| -- cannot use db_concept.* because of refs. | ||
| INSERT INTO public."Concept" ( | ||
| epistemic_status, name, description, author_id, created, last_modified, space_id, schema_id, literal_content, is_schema, represented_by_id, reference_content | ||
| ) VALUES ( | ||
| db_concept.epistemic_status, db_concept.name, db_concept.description, db_concept.author_id, db_concept.created, db_concept.last_modified, db_concept.space_id, db_concept.schema_id, db_concept.literal_content, db_concept.is_schema, db_concept.represented_by_id, db_concept.reference_content | ||
| ) | ||
| ON CONFLICT (represented_by_id) DO UPDATE SET | ||
| epistemic_status = db_concept.epistemic_status, | ||
| name = db_concept.name, | ||
| description = db_concept.description, | ||
| author_id = db_concept.author_id, | ||
| created = db_concept.created, | ||
| last_modified = db_concept.last_modified, | ||
| space_id = db_concept.space_id, | ||
| schema_id = db_concept.schema_id, | ||
| literal_content = db_concept.literal_content, | ||
| is_schema = db_concept.is_schema, | ||
| reference_content = db_concept.reference_content | ||
| -- ON CONFLICT (space_id, name) DO NOTHING... why can't I specify two conflict clauses? | ||
| RETURNING id INTO concept_id; | ||
| RETURN NEXT concept_id; | ||
| EXCEPTION | ||
| WHEN unique_violation THEN | ||
| -- a distinct unique constraint failed | ||
| RAISE WARNING 'Concept with space_id: % and name % already exists', v_space_id, local_concept.name; | ||
| RETURN NEXT -1; -- Return a special value to indicate conflict | ||
| END; | ||
| END LOOP; | ||
| RAISE DEBUG 'Completed upsert_content successfully'; | ||
| END; | ||
| $function$ | ||
| ; | ||
Uh oh!
There was an error while loading. Please reload this page.