- Notifications
You must be signed in to change notification settings - Fork0
Sample project that describes how you can handle schema within your Django application.
License
willianantunes/django-multiple-schemas
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Here you'll find an honest project that shows how to use schema with Django. It has a script that creates all the scenario the project needs in PostgreSQL, it even has tests to guarantee that it is created as expected. Check more details below!
Executedocker-compose up -d remote-interpreter jafar-app iago-app jasmine-app
. After they are running, you can check the database through its port (you can use a client for that, likeDataGrip). If you'd like to accessremote-interpreter
service administration panel, accesshttp://0.0.0.0:8000/
and useadmin
forusername andpassword.
All the services can be accessed through their admin interface. Please seedocker-compose.yaml to figure out which port to use.
If you are in a scenario where there are many applications using the same database machine, it's advisable to create one single database, let's saydb_production
, and then separate each application by its own schema (we can understand it as a folder). This is quite important because if you are using a CDC (Change Database Capture) solution likeAmazon DMS, it consumes an entire session (know more about ithere) per database, which is a quite expensive resource.
Let's say you have three Apps and each one has its own database. If your company needs data from these three databases, then three sessions will be consumed. Now if you're using schemas, only one. To illustrate:
You can check it out consultinginitialize-database.sh file.
I created a test script where it guarantees the script executed as expected. Checktest_initialize_database.py to know more. Great place of referencehere.
The result is like the following (it may be outdated):
If you update Pipfile, you can issue the following command to refresh your lock file:
docker-compose run remote-interpreter pipenv update
First execute the following:
docker-compose up -d db
When it's UP, enter the container through the command:
docker exec -it django-multiple-schemas_db_1 bash
You can do this as well:
docker-compose exec db bash
We're accessing throughbash
, but you are able to accesspsql
directly.
Then execute the commandpsql -U boss_role
(check if the user matches with what is indocker-compose.yaml) to be able to execute SQL commands direct to the database.
Sample output of the commandselect schema_name from information_schema.schemata;
:
schema_name -------------------- pg_toast pg_catalog public information_schema(4 rows)
Sample output of the commandSELECT datname FROM pg_database WHERE datistemplate = false;
:
datname ----------------------------- postgres django_multiple_schemas_dev(2 rows)
About
Sample project that describes how you can handle schema within your Django application.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.