Any way to remove siebel responsibilities for multiple users from backend? - siebel

While removing multiple responsibilities for user facing unique constraint violation error.
Try to update party_id with null value but sometimes users have multiple party id’s which causes unique constraint violation

Related

Unable to update many-to-many relation using Amplify DataStore

I have a data model that consist in three models Profile, Company, Profession. Profile is a model that I am using in order to link a Cognito user with structured data (such as Company and Profession). Profile has a many-to-many relation with Company and Profession.
When we go to towards the AWS documentation it is clear that we need to create models and then create a new record on the join table amplify generates when we talk about many-to-many relations.
Nonetheless, the link above doesn't provide information to delete or update many-to-many relations. I assume that in order to update I need to delete the entry on the Join table and then add the new entries (so I avoid duplicated entries and make the job done)
But when I try to delete an entry from the join table I receive the following error:
Error of type "ConditionalCheckFailedException"
Going into the glossary of errors on DynamoDB I don't see which condition I may be created from my side unintended as the error suggest my condition is failing
In summary, in order to allow users to manipulate the professions on their profiles, I am trying to:
Add a new entry to the ProfileProfession table, and it works
But when I try to update by:
Delete previous entries -> This fails with the error above
Add new entries -> This works
In case of more context needed here a snippet of the important code I have: https://gist.github.com/duranmla/a8caf14f61ba25fd30610cdb470ee58f
Perhaps my code is not great but I just want to understand how this things work before move further. Thanks in advance to everyone for taking the time to read. ❤️
The answer was:
Yes, for many-to-many relations you need to manipulate the join Table
Yes, to update you need to remove or add entries to the join table
Also, the unexpected behaviour one get by seeing and then not seeing data that is persisted in DynamoDB, or Error ConditionalCheckFailedException one need to:
Check policies applied to the model
Understand how DataStore subscription works (I am currently DataStore.clear() on logout and DataStore.start() on signIn)
In my specific case once I did the following:
Create a Profile record on post user confirmation to tie the Cognito User to all other models I will have on Amplify Data Model
Update the authorization Policies on my Profile model (check image below)
Clean local data on user logout using DataStore.clear()
Start a subscription when user signIn using DataStore.start()
I was able to make things work as expected 🎉
An image of how the policies look like for Profile: https://i.stack.imgur.com/aqXxk.png
Allow any signed-in users authenticated with Cognito User Pool can Read, Update, and Delete Profile and Enable owner authorization while deny non owners to Update or Delete
Good resources to check:
https://docs.amplify.aws/lib/datastore/datastore-events/q/platform/js/#usage
https://docs.amplify.aws/lib/datastore/sync/q/platform/js/#clear-local-data
https://docs.amplify.aws/lib/datastore/setup-auth-rules/q/platform/js/#configure-multiple-authorization-types

Handling multiple users concurrently populating a PostgreSQL database

I'm currently trying to build a web app that would allow many users to query an external API (I cannot retrieve all the data served by this API at regular intervals to populate my PostgreSQL database for various reasons). I've read several thing about ACID and MVCC but still, I'm not sure there won't be any problem if several users are populating/reading my PostgreSQL database at the very same time. So here I'm asking for advice (I'm very new to this field)!
Let's say my users query the external API to retrieve articles. They make their search via a form, the back end gets it, queries the api, populates the database, then query the database to return some data to the front end.
Would it be okay to simply create a unique table to store the articles returned by the API when users are querying it ?
Shall I rather store the articles returned by the API and associate each of them to the user that requested it (the Article model will contain a foreign key mapping to a User model)?
Or shall I give each user a table (data isolation would be good but that sounds very inefficient)?
Thanks for your help !
Would it be okay to simply create a unique table to store the articles returned by the API when users are querying it ?
Yes. If the articles have unique keys (doi?) you could use INSERT...ON CONFLICT DO NOTHING to handle the (presumably very rare) case that an article is requested by two people nearly simultaneously.
Shall I rather store the articles returned by the API and associate each of them to the user that requested it (the Article model will contain a foreign key mapping to a User model)?
Do you want to? Is there a reason to? Do you care who requested each article? It sounds like you anticipating storing only the first person to request each article, and not every request?
Or shall I give each user a table (data isolation would be good but that sounds very inefficient)?
Right, you would be hitting the API a lot more often (assuming some large fraction of articles are requested more than once) and storing a lot of duplicates. It might not even solve the problem, if one person hits "submit" twice in a row, or has multiple tabs open, or writes a bot to hit your service in parallel.

Why are primary keys and unique constraints disappearing from tables?

We are using Django with PostgreSQL on Heroku. We have tables with primary keys and unique constraints (created with class Meta / unique_together in Django). But the problem is, we found at least a few times that tables don't have primary keys and unique constraints - they disappeared for unknown reasons.
Does anyone know why the constraints disappeared? We didn't get any error messages but there were duplicate values in the tables where the unique constraints should have prevented them. The primary keys and unique constraints just disappeared.
What happened and how do we prevent it from happening again?

How best to handle m2m relationships within an API

I'm busy creating an API using django with tastypie. I'm at a bit of a loss on how I should manage the foreign key relationship updates. I have User and Group objects related in a many-to-many fashion. Tastypie offers functionality for me to update the related set within each update, ie when I update a group I must supply the whole corresponding user set.
Ideally I'd like to have separate functionality to add and remove relationships. Consider the fact that 1 group has 1000 users, and I simply want to remove 2 users. I would love to access a url and give the 2 users that need to be deleted instead of loading the group object with its 1000 users, removing 2, then sending 998 users back along with the group details.
What is the correct design method to handle this case? Considering my use of tastypie, how can I best implement this practically?

one primary key column foreign key to 2 other table columns.How to resolve data entry issue

I have a requirement according to which I have to create a central Login system.We have 2 things Corporate and Brand each represented by tables "Corporate" and "Brand".
When a corporate gets registered,corporateID is given,When a user under that corporate gets registered there is a table corporateuser in which corporateID is a foreign key and CorporateUserID is a primary key.Similarly in the case of a brand.
So we have CorporateUserId and BrandUserID.
Now i have a table called RegisteredUsers in which i want to have corporate as well as brand users.UserID is a primary key in this table which is a foreign key to both corporateuser as well as Branduser.
now when i enter a corporateuser,I do an entry to corporateuser as well as RegisteredUsers.When i enter CorporateUserID in userID for RegisteredUsers.It gives foreign key violation error.
I fully understand this error.How can i achieve this.This requirement is very rigid.Please tell a workaround
What you're trying to do is not totally clear, but it seems that you want the primary key of all three user tables to be the same. This is not a strict foreign key relationship, but it seems reasonable in your application.
You need to assign the userID in RegisteredUsers first, and use that key when you create your Corporate User or Brand User. Then the user id's will be unique across the whole system.
If that's not what you want, edit your entry with the table layouts to make the problem clearer.
If you are trying to insert records into tables with relational conatraints, you will need do all inserts under one SQL Transaction.