Issue with relationships not showing in a database and cannot be configured (web interface)

Feature(s) impacted

I can’t use / display the relationship inside a database.
Here is an example (the companyPlanId should be a relation field) :

Observed behavior

We have the same database in a staging environment and the relationships are displayed correctly:

I’ve tried to refresh the schema and to unlink / link again the main database with no success. I can’t see any relationships in the whole database

Expected behavior

We expect to have our field relationship in our production database on Forest Admin, since they have the same schemas.

Context

  • Project name: 34 Trucs - Production (+ see 34 Trucs - Staging for reference)
  • Team name: 33 Trucs
  • Environment name: Production
  • Agent technology: web version used
  • Agent (forest package) name & version: no agent, only the cloud version is used
  • Database type: PostgreSQL
  • Recent changes made on your end if any: none since the account creation
  • ORM : Prisma

Hello @mathieu_33trucs and welcome to our community.

I have looked into the schema that the Forest Admin cloud agent has analyzed from your databases, and I could see a lot of differences between staging and production projects, which explain what you are seeing above.

In particular, the field CompanyPlan of the table Company is seen as a plain field, not part of a relationship, but also many other differences (fields missing on one schema or the other, or different validation rules, like a field being required in one of the schemas but not the other).

You might want to check again the schemas of your datasources. Alternatively there might have been a mistake when entering your database credentials, which means that one or the other of your projects is not targeting the database that you mean.
Unfortunately if this is the latter, there is no way to check the credentials from your Forest Admin panel since those are “write only” for security purposes. The only way is to make sure is to re-enter them by going in your project settings / environment → select Production environment → then select your datasource in the list at the end and lastly Update datasource to re-enter your credentials.

I hope this helps :pray:

Hi @Nicolas.M,

Thanks for your reply.

So, I’ve clicked on “Update credentials”.
Next, I’ve updated all the credentials + clicked on “Sync database schema”

It takes a few seconds to apply changes:

After that, I’ve refreshed my browser but nothing change:

No error encountered during the process.

I did it a few minutes ago.

This is strange.

Could you please share the postgre schema of the tables with the missing relationship, as well as the schema of the relationship itself ? In private message if you prefer :pray:
Thanks

I have received your message, thanks :pray:

Thanks for all the details provided in private.

I’m following up with a public resolution.

It appears that the issue was caused by insufficient rights given to the database user accessing your data on behalf of the Forest Admin cloud agent.
Althought it dit have CRUD permission on all tables of the given schema it was lacking a specific permissions to list records in the information_schema.constraint_column_usage, which prevented the agent for properly detecting relationships.

The way postgre handles this is to only return records for which the user has rights, and unfortunately it does not throw any errors that we could catch and return, which means that the introspection failure was silent.
This may even be specific to the google cloud postgre implementation:

I’m currently looking for a way to catch and handle this error correctly so that it may be correctly returned by the Forest Admin agent and shown to the user.

I will follow up on this post if and when a fix is applied.

In the meantime, I would advise you to ensure that the user created to accessing the database has the rights to view all records in information_schema

:pray:

@Nicolas.M thanks a lot for the following! :pray:

I’ll check the grant permission on my side and post here any technical solution.

Best,

1 Like

Hi there :waving_hand:

Thanks to your message, we found why relationships are not discovered, but unfortunately we haven’t been able to solve the problem.

We have the following setup using Postgres:

  • Admin user, used to run database migrations.
  • API user, used by the API.
  • Forest Admin user, used by the Forest Admin agent (we’re self-hosting).

When running locally, it’s easy enough to use the admin user for Forest Admin so we get relationships; however, when the app is deployed, we’d prefer to avoid that.

I cannot get the Forest Admin user to access records in the information_schema.constraint_column_usage view; access itself is fine, the SELECT statement works, but the result set is empty.

We found several people with the same problem (see this Stack Overflow post for example), however the solution seems to be either:

  1. Get the constraint information some other way, which we can’t change as that’s implemented in Forest Admin, or
  2. Change the ownership of the schema/tables to the Forest Admin user, which we can’t do either as that would impact the ability of the migrations user to run migrations.

Any chance you’ve come across this and found a way to get a non-admin user to view records in information_schema.constraint_column_usage?

Hello @mderriey-makerx,
Thanks for your message,

Thinking about your question, it seems like it should not cause an issue since your production should not have to perfom a schema analysis (since you are self-hosted). This step only has to occur in dev environment, and generates a schema (usually named .forestadmin-schema.json, and part of your code version control) that you can then push along your production code.

If the above does not help, and for us to better pinpoint the issue, could you please create a new forum post ? You may link this current post to indicate it is related, but since it has been solved by the OP, I think it is best to create a new one.

Please include the following info: :folded_hands:

Feature(s) impacted

Observed behavior

Expected behavior

Failure Logs

Context

  • Project name: …
  • Team name: …
  • Environment name: …
  • Agent technology: (nodejs, php, rails, python)
  • Agent (forest package) name & version: …
  • Database type: …
  • Recent changes made on your end if any: …

Thanks, apologies for reviving an old, solved thread.

I created a new one here: Self-hosting, schema, and database permissions.

Cheers.

1 Like