You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: scripts/migrations/README-DB-BLUE-GREEN.md
+28-15Lines changed: 28 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ This utility provides scripts for managing PostgreSQL databases in a blue-green
7
7
The scripts offer two main operations:
8
8
9
9
1.**Database Creation** - Create both blue and green databases if they don't exist
10
-
2.**Cache Data Copy** - Copy external services cache data from one database to the other
10
+
2.**Database Copy** - Create an exact copy of all tables and data from one database to the other
11
11
12
12
## Database Creation
13
13
@@ -25,35 +25,48 @@ pnpm db:create-databases
25
25
3. If either database doesn't exist, it creates it
26
26
4. This operation can be run multiple times without error, as it only creates databases when needed
27
27
28
-
## Cache Data Copy
28
+
## Database Copy
29
29
30
-
Use this operation to copy cache data between blue and green databases. This is essential for maintaining cache consistency during blue-green deployments.
30
+
Use this operation to create an exact copy of one database to the other. This is essential for maintaining consistency during blue-green deployments.
31
31
32
32
```bash
33
-
# Copy cache data from blue to green
33
+
# Copy all tables and data from blue to green
34
34
pnpm db:copy-cache --copyFrom=blue
35
35
36
-
# Copy cache data from green to blue
36
+
# Copy all tables and data from green to blue
37
37
pnpm db:copy-cache --copyFrom=green
38
38
39
39
# Using the shorthand parameter
40
40
pnpm db:copy-cache -f blue
41
41
```
42
42
43
-
### How Cache Data Copy Works
43
+
### How Database Copy Works
44
44
45
45
1. The script reads the PostgreSQL connection details from the `DATABASE_URL` environment variable
46
-
2. It handles the two specific cache tables: `price_cache` and `metadata_cache`
47
-
3. For each table:
48
-
- It truncates the target table
49
-
- Copies all data from the source to the target table
46
+
2. It determines the source and target databases based on the `copyFrom` parameter
47
+
3. It retrieves a list of all tables in the source database
48
+
4. For each table:
49
+
- It truncates the target table (removing all existing data)
50
+
- Copies all data from the source table to the target table
50
51
- Processes data in batches to avoid memory issues with large tables
52
+
5. After completion, the target database is an exact copy of the source database
51
53
52
-
### Cache Tables
54
+
##Blue-Green Deployment Process
53
55
54
-
The script only copies the following tables, which contain cached data from external services:
56
+
Here's a typical workflow for using this utility in a blue-green deployment:
55
57
56
-
-`price_cache`: Stores token price information
57
-
-`metadata_cache`: Stores token metadata
58
+
```bash
59
+
# Step 1: Ensure both databases exist
60
+
pnpm db:create-databases
61
+
62
+
# Step 2: Deploy new version to the inactive environment (e.g., green)
63
+
# (Your deployment steps here)
64
+
65
+
# Step 3: Copy data from the active environment to the inactive one
66
+
pnpm db:copy-cache --copyFrom=blue
67
+
68
+
# Step 4: Switch traffic to the newly updated environment
69
+
# (Your traffic switching steps here)
70
+
```
58
71
59
-
All other tables are managed through the regular migration process and are not part of the blue-green deployment cache copying strategy.
72
+
This process allows for zero-downtime deployments by maintaining two parallel database environments.
0 commit comments