From this repo, you can learn:
- How to connect to TiDB Serverless in Django.
- How to use branching GitHub integration.
This repo is a Django crud example. it consists of 3 small applications:
- books_cbv: Implement CRUD using CBV (Class Based Views).
- books_fbv: Implement CRUD using FBV (Function Based Views).
- books_fbv_user: add user interaction to books_fbv example.
The repo is based on the django_crud. Thanks for the author's excellent work.
- clone the code
git clone [email protected]:tidbcloud/branching-django-example.git
cd apps
- active virtual environment (Mac)
python3 -m venv env
source env/bin/activate
For Windows, use env/Scripts/activate.
- Install the dependencies
pip install -r ../requirements.txt
- Fill in the .env file with your TiDB Serverless connection information. You can find the information in the TiDB Serverless console.
DB_DATABASE=
DB_USER=
DB_PASSWORD=
DB_HOST=
SSL_CA=
- Migrate the schema
make sure you have already created the database in TiDB Serverless before running the migrate command.
./manage.py migrate
- Run the server
./manage.py runserver
Assume that you have run the Django project on a TiDB Serverless. Next, you can use the Branching GitHub integration to connect the TiDB Serverless to this repo. Then a database branch will be created for every pull request to test the changes before merging the code to the master branch.
This repo has already connected to a TiDB Serverless. Check this pull request to see how we check the migration changes!