From 7b8032418ae7f26ddb485c81144cc5cb5b2f83d3 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 27 Jul 2026 00:49:13 -0400 Subject: [PATCH] Update Database Migration --- Database-Migration.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Database-Migration.md b/Database-Migration.md index f5732b4..add9315 100644 --- a/Database-Migration.md +++ b/Database-Migration.md @@ -1 +1,21 @@ -- Migrate from TinyDB to something else \ No newline at end of file +# Migrations from TinyDB to MongoDB Atlas +Steps to include in migration: + +1. Migration script should be created to migrate TinyDB json files to mongo +2. The mongo uri string is in environment variable MONGO_URI +3. Refactor from TinyDB should use a minimal set of changes +4. try to reuse function names +5. handle unit test with `mongomock` when possible +6. for integration tests run a local docker container +7. for end to end playwright tests, use a dedicated isolated test db (chore_db_e2e) - the connection string resides in .env.test. wipe test db between tests +8. keep in mind multi-worker gunicorn. do not initialize MongoClient globally at the module root level. Initialize MongoClient lazily within Flask's app factory or use Gunicorn’s post_fork hook +9. Make sure your migration script or application startup routine explicitly creates unique and secondary indexes on fields that are queried often +10. configure mongo to fail fast when developing: +``` +client = MongoClient( + os.getenv("MONGO_URI"), + serverSelectionTimeoutMS=5000, # 5-second timeout instead of 30s + connectTimeoutMS=5000, # 5-second connection handshake limit + maxPoolSize=20 # Prevents hitting Atlas free-tier limits +) +``` \ No newline at end of file