Skip to content

Commit 9a1fa5d

Browse files
authored
fix: script (#96)
## Description Fixes metadata issue for copy cache ## Checklist before requesting a review - [ ] I have conducted a self-review of my code. - [ ] I have conducted a QA. - [ ] If it is a core feature, I have included comprehensive tests.
1 parent e88db0b commit 9a1fa5d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

.github/production_operations.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,15 @@ This guide is for production operations on the Gitcoin Data Layer.
124124
3. Run `Deploy Blue Green (Start upgrade - Step 1)` workflow and deploy the target deployment
125125
4. Follow the instructions to set up the target deployment:
126126

127-
- Set migrations with target environment nano ./scripts/migrations/.env
127+
- Set migrations with target environment `nano ./scripts/migrations/.env`
128128
```tsx
129129
DATABASE_URL=postgres://{{DB_USER}}:{{DB_PASSWORD}}@{{DB_URL}}:5432/GitcoinDatalayer{{Green|Blue(Should be target environment)}}
130130
DATABASE_SCHEMA=public
131131
NODE_ENV=production
132132
```
133133
- pnpm db:reset
134+
- pnpm db:cache:reset
135+
- pnpm db:cache:migrate
134136
- pnpm db:copy-cache -f {{ green | blue (should be the source environment) }}
135137
- pnpm db:migrate
136138

scripts/migrations/src/copyCache.script.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ export const copyTableData = async (
178178
// Process the fetched batch in smaller chunks for insertion
179179
for (let i = 0; i < batchRows.length; i += insertBatchSize) {
180180
const insertBatch = batchRows.slice(i, i + insertBatchSize);
181-
182181
// Create a parameterized query for this insertion batch
183182
const valueStrings = [];
184183
const valueParams = [];
@@ -188,7 +187,14 @@ export const copyTableData = async (
188187
const rowParams = [];
189188
for (const col of columns) {
190189
rowParams.push(`$${paramIndex++}`);
191-
valueParams.push(row[col]);
190+
//workaround for metadata column
191+
if (col === "metadata") {
192+
valueParams.push(
193+
Array.isArray(row[col]) ? stringify(row[col]) : row[col],
194+
);
195+
} else {
196+
valueParams.push(row[col]);
197+
}
192198
}
193199
valueStrings.push(`(${rowParams.join(", ")})`);
194200
}
@@ -267,7 +273,7 @@ export const main = async (): Promise<void> => {
267273
const targetDb = sourceColor === "blue" ? GREEN_DB : BLUE_DB;
268274

269275
logger.info(`Copying cache data from ${sourceColor} to ${targetColor}...`);
270-
await copyCacheData(sourceDb, targetDb, connectionDetails);
276+
await copyCacheData("datalayer-postgres-db", "GitcoinDatalayerGreen", connectionDetails);
271277

272278
logger.info(`✅ Cache data copied from ${sourceColor} to ${targetColor} successfully`);
273279

0 commit comments

Comments
 (0)