Working with async databases

Different configurations per environment in FastAPI apps

Want more?

This lesson for enrolled students only. Join the course to unlock it!

You can see the code changes implemented in this lecture below.

If you have purchased the course in a different platform, you still have access to the code changes per lecture here on Teclado. The lecture video and lecture notes remain locked.
Join course for $30

Modified files

storeapi/config.py
--- 
+++ 
@@ -6,12 +6,28 @@


 class BaseConfig(BaseSettings):
+    ENV_STATE: Optional[str] = None
+
     """Loads the dotenv file. Including this is necessary to get
     pydantic to load a .env file."""
-
     model_config = SettingsConfigDict(env_file=".env")


 class GlobalConfig(BaseConfig):
     DATABASE_URL: Optional[str] = None
     DB_FORCE_ROLL_BACK: bool = False
+
+
+class DevConfig(GlobalConfig):
+    model_config = SettingsConfigDict(env_prefix="DEV_")
+
+
+class ProdConfig(GlobalConfig):
+    model_config = SettingsConfigDict(env_prefix="PROD_")
+
+
+class TestConfig(GlobalConfig):
+    DATABASE_URL: str = "sqlite:///test.db"
+    DB_FORCE_ROLL_BACK: bool = True
+
+    model_config = SettingsConfigDict(env_prefix="TEST_")