Creating a PostgreSQL database container

We need to test our code against a PostgreSQL database. This is the database that we will be deploying the code in production against.

While the abstraction layer in SQLAlchemy aims to reduce the differences, there are some differences in the behavior of the databases.

For example, in /thoughts_backend/api_namespace.py, the following line is case-insensitive, which is the behavior that we want:

query = (query.filter(ThoughtModel.text.contains(search_param)))

Translating that to PostgreSQL, it is case-sensitive, which requires you to check it. This would be a bug in production if testing with SQLite and running in PostgreSQL.

The replaced code, using ilike for the expected behavior, is as follows: ...

Get Hands-On Docker for Microservices with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.