app.dataSource() function is needed for DataSourceBooter - loopbackjs

getting this while running app after I created datasource using lb4 datasource
just don't know is it compulsory

Related

Django multitenant using middleware - can you persist connections

I'm using django with django-tenants for a SaaS app and it is using the user's subdomain to set the db schema in postgresql. So a call to user1.app.com will use the 'user1' schema.
Each call to a view creates a new database connection by default. If the view call ajax, a new connect/disconnect happens. Using this method works as each call gets it's postgresql search path set to the correct schema using the django-tenants middleware.
My question is if I set CONN_MAX_AGE to persist connections for a period of time to reduce the heavy connect/disconnect load on the server, will django pool connections from multiple users potentially using different schemas? I am concerned, because:
All users are using the 'default' DATABASE. (just the search path changes)
I don't see any logic that binds a connection to a unique user session.
The built in development server ignores the CONN_MAX_AGE setting so I can't test locally.
I have looked into the connection_created signal, but I would be duplicating logic with django-tenants and I'm not sure of any unintended consequences.
Using django 4.0.7 and posgresql 12.

How can I call a custom Django manage.py command directly from code with specific database connection

i followed this solution to run customer django command programmatically , but it is limited for just one database connection.
I have django app configured with multiple database , is it possible to run custom django command using specific database connection?
exactly like when we use connections["DB_NAME_CONNECTION"].cursor() to execute an sql query
thanks a lot for your help!
One option is to create a new settings module (here's a guide) that contains your specific database connection configuration, and then use that settings module when using call_command():
management.call_command('mycommand', '--settings=mysite.settings.specificconnection')

What is my App Maker database key/name for published apps

Context
The Database Key for the preview version of an App Maker app can be found in SETTINGS>DATABASE as the Database Key. In GCP, App Maker uses a SQL instance, and within that instance many Databases are listed - including the Database Key/Name from the App Maker preview.
By default, when publishing an App Maker app, a new Database within the MySQL instance is created.
Question
How do I find the Database Key/Name that the newly published app is using?
You need to go to the deployments settings and click on the EDIT option. Then you should be able to retrieve the database key. Here, for your reference:
This is documented right here: https://developers.google.com/appmaker/deployment/#databases

How to use a different database for Heroku review apps?

I have a deployment pipeline on Heroku which recently started using review apps. This means I have an app - let's call it CI-APP -- which is being created from the master branch.
Every time a pull request is made, a review app is created. We are using Django in our project and so I also added the migrate command to the release phase in the project, so that database migrations can be done automatically.
Today, a coworker submitted a pull request which contained some database changes. The problem is that the migration was ran, and since review apps seem to be using the same database as the app they are suppose to merge to, the migration was applied and now my app CI-APP stopped working...since the code base no longer matches the database structure.
I searched a lot about how to use completely different databases for the review apps compared to the parent app, but to no avail (there are some resources mentioning how you can copy db contents, but that is not what I need).
Any suggestion ?
Update
Ok, so it seems that Heroku does create a new database for the review app, however: the review app copies all of its environment variables from the parent, including the DATABASE_URL (this seems to be the only way to actually create the review app : https://s3.amazonaws.com/heroku-devcenter-files/article-images/1461071037-initial_set_up_review_apps.png)
I think I can do some black magic in the postdeploy script, but since the database generated url can be something such as HEROKU_POSTGRESQL_{color}_URL, I am not sure how to find it ....
To do that, create the app.json file at the root of your project instead of using the heroku dashboard. In this file, you can specify what environment variables to inherit from the parent.
From the heroku docs:
"env": {
"INHERIT_THIS_CONFIG_VAR": {
"required": true
},
"DONT_INHERIT_THIS_CONFIG_VAR": "production"
},
This allows you to specify which database you want to use for the review app. Looking at the documentation of the heroku postgres addon (i assume you're using postgres):
As part of the provisioning process, a DATABASE_URL config var is
added to your app’s configuration. This contains the URL your app uses
to access the database.
So the database_url config variable will be created by the adddon. You simply need to not put it in the app.json file, and it will be created automatically.
Check that you do not have the DATABASE_URL set in the Pipeline Settings CONFIG VARS in Heroku either.. if it is set there, then it seems the Review App will use that as the DB link and not the one created when the Review App is created.

How to use a mysql table of a particular django app in another django app if the is same?

I am trying my hand at Python. I have a created a simple app with MySQL as a back end and I want to use the application's table in another app.
Both of the applications are for the same project. Please help
Make sure all your app in registered in settings.py.Then import the model to other by appname.models.Modelname.
Execute Query:
ModelName.objects.all()