git clone https://github.com/kgex/bigbbe
Install Postgresql
sudo -u postgres psql
\password
CREATE DATABASE bigbbe;
exit
\password
CREATE DATABASE bigbbe;
exit
sudo apt install virtualenv
virtualenv env
source env/bin/activate
pip install -r requirements.txt
pip install -m virtualenv
python -m venv env
./env/Scripts/activate
If you get an UnauthorizedAccess error, then open PowerShell in admin mode and type the following command
set Restriction-Policy Unrestricted
and rerun the above commands and finally
pip install -r requirements.txt
nano ~/.bashrc
and add the following lines at the end
export SQLALCHEMY_DATABASE_URL="postgresql://postgres:password@localhost/bigbbe"
export SENDGRID_API_KEY="<your api key goes here>"
export SENDER_EMAIL="<your authorized sender email address goes here>"
and in your terminal
source ~/.bashrc
Step 1:Open your search bar using the Windows
key and search for "Edit environment and system variables" and click on the first option
Step 3: In the System variables tab, click on new and you will see two input boxes called Variable name
and Variable value
The words on the left hand side of the =
go in the Variable name
box and the ones on the right hand side go in the Variable value
box
SQLALCHEMY_DATABASE_URL = postgresql://postgres:password@localhost/bigbbe
SENDGRID_API_KEY = <your api key goes here>
SENDER_EMAIL = <your authorized sender email address goes here>
If you have successfully completed the database setup as mentioned above, then we can migrate our models into our database using alembic
alembic init migrations
You should now see a folder called migrations
and a file called alembic.ini
postgresql://postgres:password@localhost/bigbbe
You need to replace password
with the password you entered changed to using \password
.
Keep this string stored somewhere accessible outside the project as this string will be used to connect bigbbe to your local database
import app.models as models
target.metadata = models.Base.metadata
Step 4: Migrate your models by opening your terminal inside the root directory of bigbbe and enter the commands
alembic revision --autogenerate -m "msg"
alembic upgrade head
Now the database has been setup completely.
To run the app, first the virtual env must be activated
./env/Scripts/activate
source env/bin/activate
and when your env has been activated, you can run the app using the following command
uvicorn app.main:app --reload
When you make any changes to the models and want to see them reflected on your database, you can use the following commands
alembic revision --autogenerate -m "msg"
alembic upgrade head