Skip to content

Commit a7ee7a6

Browse files
committed
docs: add a database migration checklist
1 parent b3d7327 commit a7ee7a6

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Database Migration Checklist
2+
3+
This document provides a checklist for developers and reviewers to ensure that database migrations are implemented
4+
correctly, safely, and consistently across the project. Following these steps is mandatory for any change that alters
5+
the database schema.
6+
7+
## Phase 1: Development
8+
9+
The developer implementing the migration is responsible for completing these steps.
10+
11+
### 1. Schema and Versioning:
12+
13+
- [ ] **Bump the Database Version:** The `DB_VERSION` constant in `legacy/storage/src/main/java/com/fsck/k9/storage/StoreSchemaDefinition.java` has been incremented by exactly **1**.
14+
- [ ] **Update the database schema definition:** Any changes to the database schema have been reflected in the `dbCreateDatabaseFromScratch` within the `StoreSchemaDefinition.java` file.
15+
- [ ] **Create a New Migration Class:** A new `MigrationToXX` class within the `legacy/storage/src/main/java/com/fsck/k9/storage/migrations` folder has been created. Where XX is the new database version number.
16+
- [ ] **Migration Logic Implemented:** The new migration class contains the necessary SQL statements to transition the database from the previous version to the new version.
17+
- [ ] **Register the Migration:** The new migration class has been registered in the `Migrations.kt` file in the `legacy/storage/src/main/java/com/fsck/k9/storage/migrations` folder.
18+
19+
### 2. Migration Logic:
20+
21+
- [ ] **Data Integrity:** The migration logic has been designed to preserve existing data and ensure data integrity.
22+
- [ ] **Idempotency:** The migration can be safely re-run without causing issues or data corruption.
23+
- [ ] **Error Handling:** Appropriate error handling has been implemented to manage potential issues during the migration process.
24+
- [ ] **No Network Calls:** The migration does not make any network calls. If network calls are absolutely necessary, they are handled gracefully and do not fail the migration.
25+
- [ ] **Self-contained Logic:** The migration logic is self-contained within the migration class and does not depend on application logic outside of it.
26+
- [ ] **Performance Considerations:** Long running migrations will block the app startup (a dedicated loading screen will be shown). Consider breaking them into smaller steps if necessary.
27+
- [ ] **Documentation:** The migration class includes comments explaining the purpose of the migration and any non-obvious logic.
28+
29+
### 3. Testing:
30+
31+
- [ ] **Unit Tests:** Unit tests for the migration have been written to cover various scenarios, including edge cases.
32+
- [ ] **Test Schema Changes:** The test validates that the schema is correct after the migration runs. It should check for:
33+
- New tables exist.
34+
- New columns exist in the correct tables.
35+
- Correct column types, nullability, and default values.
36+
- [ ] **Test Data Migration:** The test validates that existing data is correctly migrated. This includes:
37+
- Data in existing tables remains intact.
38+
- Data transformations (if any) are correctly applied.
39+
40+
### 4. Holistic testing:
41+
42+
- [ ] Run migration **Beta -> Beta** and verify no issues.
43+
- [ ] Run migration **Beta -> Release** and verify no issues.
44+
- [ ] Run migration **Release -> Release** and verify no issues.
45+
46+
## Phase 2: Review
47+
48+
The reviewer is responsible for validating these steps during the code review process.
49+
50+
### 1. Code and Logic Review:
51+
52+
- [ ] **Verify Version Bump:** Confirm that the database version has been incremented correctly by 1.
53+
- [ ] **Schema Definition Update:** Ensure that the database schema definition has been updated to reflect the new schema.
54+
- [ ] **Review Migration Class:** Ensure the new migration class is correctly named and placed in the appropriate directory.
55+
- [ ] **Validate Migration Logic:** Review the SQL statements in the migrate() method for correctness and safety.
56+
- [ ] **Check for Data Integrity:** Ensure that the migration logic preserves existing data and does not introduce data loss unless explicitly intended.
57+
- [ ] **Performance Review:** Assess the migration logic for potential performance bottlenecks, especially on large datasets.
58+
- [ ] **Review Documentation:** Check that the migration class is well-commented, explaining the purpose and any complex logic.
59+
60+
### 2. Testing Review:
61+
62+
- [ ] **Confirm Unit Tests:** Ensure that unit tests for the migration have been written and cover various scenarios.
63+
- [ ] **Review Test Coverage:** Validate that the tests adequately cover the schema changes and data migration paths, including edge cases.
64+
65+
### 3. Holistic check:
66+
67+
- [ ] Run migration **Beta -> Beta** and verify no issues.
68+
- [ ] Run migration **Beta -> Release** and verify no issues.
69+
- [ ] Run migration **Release -> Release** and verify no issues.
70+
71+
## What to watch out for:
72+
73+
- [ ] **Data Loss:** Ensure that no unintended data loss occurs during the migration.
74+
- [ ] **Network Calls:** Avoid making network calls during the migration process. If necessary, ensure they are handled gracefully and do not fail the migration.
75+
- [ ] **Write migrations that are self-contained and do not depend on application logic outside the migration class.**
76+
- [ ] **Long-running Migrations:** Be cautious of migrations that may take a long time to complete, especially on large datasets. Consider breaking them into smaller steps if necessary.
77+
- [ ] **Blocking the Main Thread:** Migrations run on the main thread and will block the UI. Keep migrations as fast as possible.
78+

0 commit comments

Comments
 (0)