`This schema does not exists` when running ` forest schema:update`

I am trying to add a table to FA. There are only a few tables from this database that are displayed in the project but I can’t find how we a limiting the tables included - I see in the documentation how to accomplish this but I don’t see that we’ve done that in our code. So, I’m messing around trying to figure it out and, on my understanding, forest schema:update should update all of the models for both of our databases instead, I get this error.

In searching for an answer, I saw a help topic on this board that mentions that the default schema is public. I notice that, when using DBeaver, this database does not have a designated schema which is something I’ve not noticed nor encountered before.

This DB is mySQL and our “primary” DB in this project is postgreSQL if that lends any clarification to the issue.

Feature(s) impacted

forest schema:update

Observed behavior

This schema does not exists. error returned when running commnd.

Expected behavior

Updates schema

Context

  • Project name: scratch-payment-service
  • Team name: all
  • Environment name: development
  • Agent type & version: …
  • Recent changes made on your end if any: …

Hi @Brett_Belka :wave: can you share with us the whole error logs please?

For your include/exclude models question please refer to the documentation and do the modification inside middlewares/forestadmin.js.

forest schema:update as the documentation said create all missing needed files for a new table, or help you to update your Sequelize model if you change some fields or relations.

Let me know if that help :pray:

HI @Arnaud_Moncel

√ Connecting to your database(s)
× This schema does not exists.

That’s it.

As I mentioned previously, I have already read this documentation regarding including/excluding specific models. Our middleware is not excluding any models, so they should all be there but only select models are there for this database (the other database includes all models in FA). I also tried specifically including just the model I need to add and I got the same error as above.

forest schema:update only returns the error above. It does nothing else.

My thought is that liana is looking for a public schema but, as far as I can tell, this database does not have anything referred to as a schema at all - it’s just a data base with tables…

Normally, when viewing through a db visualization tool (in this case DBeaver) I would expect:

-Connection
  -databases
    -DB_name
      -schemas
        -public
          -tables

But for this database, I see

-Connection
  -databases
    -DB_name
      -tables

I’m thinking the error might be resultant of liana looking for a default (public) schema but not seeing it because it doesn’t exist.

It may be worth noting that this is a mySQL database and the other database (which seems to work as expected) is postgreSQL.

Can you check if you have DATABASE_SCHEMA env var in your .env file and remove it if it is the case?
Can you check if your connection uri begin like mysql://....?
let me know if that help.

@Arnaud_Moncel

Thanks for the help!

We do have a DATABASE_SCHEMA env var but it is only utilized in the models for the database that does have the public schema. (The one that appears to be working correctly).

The DATABASE_SCHEMA var isn’t utilized in the models for this database.

As for the connections string, yes, it starts mysql://...

@Arnaud_Moncel I re-thought and then tried removing the DATABASE_SCHEMA env var as suggested and that indeed worked! Thanks!

However, it didn’t update the existing models files. Rather, it produced duplicates. Of everything.

I’ve tried excluding all models I don’t want, as well as including only those that I do as indicated here: Include/exclude models - Developer guide but the result is the same.

As I was reviewing everything related to this, I also notice that there are a numbe of models in our FA code that are missing certain columns that have been added to the database. My reading of the FA documentation indicates to me that our schema should be updated everytime the program is run. The existing models in our FA code were last committed 3 years ago. I’m wondering if an older method was used to set up these models and whether I should be approaching this from a different angle than merely trying to add a single model. Perhaps a more comprehensive overhaul is necessary??

Or if, perhaps, it’s possible to simply add the specific model I need manually and I’m just not finding the method in the documentation…

Do you run the update command with some options ?
This command should only create missing models, route and forest files. To really update models after a column addition in the database or something like that you should remove impacted models and re-run the command.

If you use only includedModels and put the right model name it should work, i’ve juste tested now.
Please be sure the name you put in string inside the included array is the one defined on your Sequelize models like below

// the model name here is `user` not `User`
const User = sequelize.define('user', {

No options. It did create the missing models but it also created duplicate models for the models that already existed. The strangest part in my mind is that they were the exact same filename. I’m not sure how that was allowed…

My interpretation was that using includedModels or excludedModels would not create them in the first place but now that I think more about it, that doesn’t really make sense. So, forest schema:update creates models/route/etc. for all tables regardless and then we can exclude or include them for use?

Pretty much all of our models have been updated but most of that data is not data that we need to actually view in FA, so I’m I’m looking at a complete overhaul, right?
I’ll have to

  1. Delete all models/routes files
  2. run forest schema:update (update is a misnomer)
  3. go through and manually change the view for each model to exclude unnecessary fields
  4. go through and manually add all of the routes to disable the count middleware (unnecessary and are the most time-intensive queries on our database).

Are there any shortcuts to any of this that I’m not thinking of?

Yeah pretty strange indeed.

You are right ! We perform introspection on the whole database locally. Next you can exclude model for the UI. Sometimes you maybe want to uses some model internally and don’t want forest to be aware of.

It is not really necessary to remove route files.
I suggest you to remove only models, especially if you already configured some behavior.
Unfortunately we does not have shortcut to hide unnecessary field.

Let me know if that help :pray:

@Arnaud_Moncel Thanks!

Don’t hesitate to ask more questions.
Can I mark as resolve this thread?

@Arnaud_Moncel yes. Thanks again!