Fix DB integration quality: dependency injection, idempotent seeding, price precision, and test isolation#8
Merged
goldlabelapps merged 3 commits intostagingfrom Mar 19, 2026
Conversation
…ing, main() guards, precision fix, tests Co-authored-by: goldlabelapps <244006120+goldlabelapps@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add PostgreSQL database integration for product data management
Fix DB integration quality: dependency injection, idempotent seeding, price precision, and test isolation
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses all review comments on the PostgreSQL integration PR: per-request DB connections leaking, duplicate router declaration,
ON CONFLICT DO NOTHINGbeing a no-op (no unique constraint), price losing precision viafloat(), scripts executing at import time, missing dependencies inrequirements.txt, and tests requiring a live DB.API / Routes (
app/api/routes.py)router = APIRouter()load_dotenv()to module levelget_db_connection()generator dependency injected viaDepends()— connection lifecycle guaranteed bytry/finallystr(row[3])instead offloat(row[3])to preserveNUMERICexactnessSeeding (
app/seed_product_table.py)UNIQUEconstraint onnamesoON CONFLICT (name) DO NOTHINGis a real conflict target — re-running the script is now idempotentmain()+if __name__ == "__main__":guardUtility scripts (
app/print_products.py,app/test_db_connection.py)main()+ guard to prevent side effects on importtest_db_connection.pyreturns a non-zero exit code on failure viasys.exit()Dependencies (
requirements.txt)python-dotenv>=1.0.0andpsycopg2-binary>=2.9.0Metadata (
app/main.py)versionfromapp.__version__instead of the hard-coded"1.0.0"Tests (
tests/test_routes.py)get_db_connectionwith a mock dependency — tests run without a live PostgreSQL instancetest_root_returns_welcome_messagewith tests validating the{meta, data}response shape; mock rows useDecimalto accurately reflect DB types📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.