Skip to content

Conversation

mrnicegyu11
Copy link
Member

@mrnicegyu11 mrnicegyu11 commented Jul 28, 2025

What do these changes do?

If one creates a new, PostgreSQL database, then runs the osparc-simcore migration microservice, then dumps the postgres DB to a backup .sql file using psql and lastly tries to import it, the import will fail with

ERROR: Uncountered errors trying tor estore DB: 
 psql:/tmp/tmp8zxoei_2.sql:3016: ERROR:  relation "groups" does not exist
LINE 1: type = 'EVERYONE' AND (SELECT COUNT(*) FROM groups WHERE gro...
                                                    ^
QUERY:  type = 'EVERYONE' AND (SELECT COUNT(*) FROM groups WHERE groups.type = 'EVERYONE') = 1
CONTEXT:  PL/pgSQL function public.check_group_uniqueness(text,text) line 3 at IF
COPY groups, line 1: "1 Everyone        all users       EVERYONE        2025-07-28 07:27:41.07941       2025-07-28 07:27:41.07941       \N      {}"
psql:/tmp/tmp8zxoei_2.sql:3016: STATEMENT:  COPY public.groups (gid, name, description, type, created, modified, thumbnail, inclusion_rules) FROM stdin;
psql:/tmp/tmp8zxoei_2.sql:5092: ERROR:  insert or update on table "products" violates foreign key constraint "fk_products_group_id"
DETAIL:  Key (group_id)=(3) is not present in table "groups".
psql:/tmp/tmp8zxoei_2.sql:5092: STATEMENT:  ALTER TABLE ONLY public.products
    ADD CONSTRAINT fk_products_group_id FOREIGN KEY (group_id) REFERENCES public.groups(gid) ON UPDATE CASCADE ON DELETE SET NULL;
psql:/tmp/tmp8zxoei_2.sql:5364: ERROR:  insert or update on table "services_access_rights" violates foreign key constraint "fk_services_gid_groups"
DETAIL:  Key (gid)=(1) is not present in table "groups".
psql:/tmp/tmp8zxoei_2.sql:5364: STATEMENT:  ALTER TABLE ONLY public.services_access_rights
    ADD CONSTRAINT fk_services_gid_groups FOREIGN KEY (gid) REFERENCES public.groups(gid) ON UPDATE CASCADE ON DELETE CASCADE;
psql:/tmp/tmp8zxoei_2.sql:5420: ERROR:  insert or update on table "groups_extra_properties" violates foreign key constraint "fk_tag_to_group_group_id"
DETAIL:  Key (group_id)=(1) is not present in table "groups".
psql:/tmp/tmp8zxoei_2.sql:5420: STATEMENT:  ALTER TABLE ONLY public.groups_extra_properties
    ADD CONSTRAINT fk_tag_to_group_group_id FOREIGN KEY (group_id) REFERENCES public.groups(gid) ON UPDATE CASCADE ON DELETE CASCADE;

This is due to a wrong function definition in the osparc-simcore alembic, where groups should be public.groups.
This change fixes the bug, and the .sql PG dump can then be imported.

Related issue/s

How to test

Dev-ops

@mrnicegyu11 mrnicegyu11 added t:enhancement Improvement or request on an existing feature bug buggy, it does not work as expected a:database associated to postgres service and postgres-database package labels Jul 28, 2025
@mrnicegyu11 mrnicegyu11 self-assigned this Jul 28, 2025
@mrnicegyu11 mrnicegyu11 added this to the Engage milestone Jul 28, 2025
@mrnicegyu11 mrnicegyu11 marked this pull request as ready for review July 28, 2025 09:39
Copy link

codecov bot commented Jul 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.14%. Comparing base (b5836c9) to head (32161dd).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8166      +/-   ##
==========================================
+ Coverage   88.05%   90.14%   +2.08%     
==========================================
  Files        1921     1604     -317     
  Lines       74458    63500   -10958     
  Branches     1305      562     -743     
==========================================
- Hits        65562    57239    -8323     
+ Misses       8502     6113    -2389     
+ Partials      394      148     -246     
Flag Coverage Δ
integrationtests 64.24% <ø> (+0.05%) ⬆️
unittests 88.55% <ø> (+1.85%) ⬆️
Components Coverage Δ
pkg_aws_library ∅ <ø> (∅)
pkg_celery_library ∅ <ø> (∅)
pkg_dask_task_models_library ∅ <ø> (∅)
pkg_models_library 93.08% <ø> (ø)
pkg_notifications_library 85.26% <ø> (ø)
pkg_postgres_database 88.02% <ø> (ø)
pkg_service_integration ∅ <ø> (∅)
pkg_service_library ∅ <ø> (∅)
pkg_settings_library ∅ <ø> (∅)
pkg_simcore_sdk 85.03% <ø> (ø)
agent 93.53% <ø> (ø)
api_server 92.73% <ø> (ø)
autoscaling 95.89% <ø> (ø)
catalog 92.34% <ø> (ø)
clusters_keeper 99.13% <ø> (ø)
dask_sidecar 92.37% <ø> (ø)
datcore_adapter 97.94% <ø> (ø)
director 75.81% <ø> (-0.09%) ⬇️
director_v2 90.89% <ø> (+0.04%) ⬆️
dynamic_scheduler 96.27% <ø> (ø)
dynamic_sidecar 90.10% <ø> (ø)
efs_guardian 89.62% <ø> (ø)
invitations 91.44% <ø> (ø)
payments 92.61% <ø> (ø)
resource_usage_tracker 92.08% <ø> (ø)
storage 86.36% <ø> (-0.21%) ⬇️
webclient ∅ <ø> (∅)
webserver 88.15% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b5836c9...32161dd. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pcrespov pcrespov removed the bug buggy, it does not work as expected label Jul 28, 2025
Copy link
Contributor

@wvangeit wvangeit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mrnicegyu11

Copy link
Member

@sanderegg sanderegg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. that migration is from 2020. not sure I understand why only that one would require the public prefix??

@@ -21,7 +22,7 @@ def upgrade():
"""
CREATE OR REPLACE FUNCTION check_group_uniqueness(name text, type text) RETURNS INT AS $$
BEGIN
IF type = 'EVERYONE' AND (SELECT COUNT(*) FROM groups WHERE groups.type = 'EVERYONE') = 1 THEN
IF type = 'EVERYONE' AND (SELECT COUNT(*) FROM public.groups WHERE groups.type = 'EVERYONE') = 1 THEN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public? this is the default name of the schema (SEE postgres/scripts). Why would this be needed.
if so, why do we need it here and not in other tables?

@mrnicegyu11 mrnicegyu11 modified the milestones: Engage, Voyager Aug 13, 2025
@mrnicegyu11
Copy link
Member Author

@pcrespov @sanderegg

I am not sure I can explain this better to you beyond "this is what fixed the import for me", maybe Matus knows from his background of postgres? I am myself not sure. If in doubt, we can lose this PR, let me know in case ;)

Copy link
Contributor

mergify bot commented Aug 13, 2025

🧪 CI Insights

Here's what we observed from your CI run for 32161dd.

🟢 All jobs passed!

But CI Insights is watching 👀

@mrnicegyu11
Copy link
Member Author

since it is not clear to me if there is anything I can do to get this merged, I will close it as stale :--)

@mrnicegyu11
Copy link
Member Author

mrnicegyu11 commented Aug 27, 2025

I encountered this issue again with @matusdrobuliak66 trying to import the postgres from aws-master locally. This would not work because of the precise issue in this PR. Adding the groups. prefix fixes the issue.

BUT: One can not just modify the check_group_uniqueness function, since it is "linked" with a constraint to the groups table. We managed by:

  • Running ALTER TABLE public.groups DROP CONSTRAINT groups_check;
  • Changing the type of the everyone group to STANDARD
  • Then modifying the check_group_uniqueness function
  • Changing the type of the everyone group back to EVERYONE
  • Running ALTER TABLE public.groups ADD CONSTRAINT groups_check CHECK ((check_group_uniqueness((name)::text, (type)::text) = 0))

@matusdrobuliak66 re-opening this and assigning to you thx!

@mrnicegyu11
Copy link
Member Author

So just to clarify: My proposed change will not work as is, there has to come an additional migration along the specified steps that fixes the current issue in the function ;)

Copy link

@matusdrobuliak66 matusdrobuliak66 modified the milestones: Voyager, Cheops Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:database associated to postgres service and postgres-database package t:enhancement Improvement or request on an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants