Skip to content

dking1342/fastapi-ansible-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ansible setup of FastAPI API with database

Step 1: Run app.yaml

Run the following command to set up the folder:

ansible-playbook app.yaml

Step 2: Configure db with migration folder

Go to the migration folder and run the script:

./db_init.sh

This will create the database.

Go to the alembic/versions folder and locate the file that was just created for this migration. Inside the file replace the upgrade and downgrade with:

def upgrade() -> None:
    op.create_table(
        'todos',
        sa.Column('id', UUID(as_uuid=True), primary_key=True, default=uuid.uuid4),
        sa.Column('name', sa.String(100), nullable=False),
        sa.Column('status', sa.Boolean, default=False)
    )


def downgrade() -> None:
    op.drop_table('todos')

Then in the import section add the following:

from sqlalchemy.dialects.postgresql import UUID
import uuid

Run the following script to run the migration:

./db_migrate.sh

Once that is successful run the following script to spin up the server:

./server_start.sh

You can curl the server to make sure that everything is working properly:

curl http://localhost:8000/api/v1/todos/

Step 3: Run cleanup.yaml

Run the following command to clean up the folder:

ansible-playbook cleanup.yaml

About

Setup folder that uses ansible to create a fastapi API with a postgres database

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published