How do i auto update backend from postgres schema

I added 5 more tables to my existing connected database, how do make it show up in the existing dashboard?

It seem’s like the correct way to do this would be manually editing .forestadmin-schema.json? But that seems like a lot of work given total number of tables I added is around 10 if you consider joining tables for many2many relationships.

Another way would be to generate another project using lumber-cli but that doesn’t seem like a recommended approach.

Let me know if I am missing anything here :slight_smile:

Hi @BK42,

The recommended approach to add new tables to an existing lumber generated project is to define the models related to the new tables manually in the models directory of your project (attributes and relationships).
Once done properly, your server restart in your development environment should automatically update the .forestadmin-schema.json. By the way this file is automatically generated and you should never edit it manually, more about that here.

If the manual creation of the new models seems to be to much work, you can create a new temporary “draft” project based on the same database connection URL with lumber generate.
The new project repository should contain the old and new tables models. Then you just have to copy-paste the models directory from the draft project to your current one.
Be sure that the changes won’t erase manual update you’ve done in your current project and then you’re good to commit the new models and .forestadmin-schema.json.

Hope it helps.

3 Likes

Just wanted to take a moment to say that I am in awe of what you have build (ignoring rough edges because it is still early) and keep on keeping on :slight_smile:

I like the idea of creating “draft” project. Because, I am process of creating/migrating to database out of old data store so I am adding lots of new tables everyday.

Is there easy way to create draft project without adding new project to UI and hence polluting your DB?
Because as per my screenshot below.:

  1. I don’t see a way to generate “draft” project without giving a new project name
  2. I don’t want to create a pollution on frontend by having 10’s of draft projects.

Hi @BK42,

Depending on how many tables you’re intending to add and at what frequency I see 3 options for you:

  • If you can create the all DB tables before hand, you’d have to do only one “draft project” to populate the models.
  • If you can add a lot of those tables and only add a couple more after that, I’d recommend doing one draft project and then manually create the missing models (if there ain’t many that might be quicker that doing a draft project project)
  • If you want to iterate a lot and have batch of several tables at each time, then you’ll need to create a lot of draft (and so, pollution). But it is to be noted that you can clean those drafts directly from the UI to keep both our DB and the list of your project on a sane state. This is achieved by dropping the draft project by clicking on the trash icon when sliding your mouse over a project:

I do hope those steps will fit you need!

1 Like

I created and added the following file to my repo which reduces the model regeneration process into a single step:

Let me know what y’all think :slight_smile:

2 Likes

Hello @BK42 :wave:

Nice bash script here!

Sadly I have to point out a few stuff that will prevent your script from running :slightly_frowning_face:

1 - If you run this script twice in a row, you will receive an error message stating that the project “draft” already exists. In fact by running it twice you will perform two project creation (under the hood) and the second attempt will fail. To tackle this you could generate the project name as a random value, and then store it to keep track of the project name you are currently using. The drawback though, is that running this command will create a fresh new project that you would be able to see in the project list page. (You can delete it, not a big deal but still…)

2 - Your authentication token will expire some day, or you might not have one. Running lumber generate command without a valid token will make the prompt ask for username/password. These are information you can easily pass to the lumber generate command using -e (email, you already did it) and -P (password) options.

Thanks for sharing this with the community, congrats for the code :clap:, this a nice content :+1:

Steve.

  1. hmmm, i did ran multiple times and it did not throw error for me. i thought draft was a special project name in that sense

  2. feel free to make improvements, i can push this in some repo if you’d like to improve over there, instead of just a gist.

let me know :slight_smile:

Few adjustment on the script to make it compatible will the lumber CLI 3.0.0+

#!/bin/sh
EMAIL=<<your_email_here>>
DUMMY_NAME=dummy007
set -o allexport
. ./.env
set +o allexport
DIR=`pwd`
pushd .
cd ..
rm -rf $DUMMY_NAME
echo $DATABASE_URL
lumber generate $DUMMY_NAME --email $EMAIL --connection-url $DATABASE_URL --schema $DATABASE_SCHEMA --ssl $DATABASE_SSL --application-host localhost --application-port $APPLICATION_PORT
cp -r $DUMMY_NAME/models/ $DIR/models/
2 Likes