Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backfill synonyms for all circulars once eventId has been backfilled #2662

Open
Courey opened this issue Nov 1, 2024 · 2 comments
Open

backfill synonyms for all circulars once eventId has been backfilled #2662

Courey opened this issue Nov 1, 2024 · 2 comments
Assignees

Comments

@Courey
Copy link
Contributor

Courey commented Nov 1, 2024

No description provided.

@Courey Courey self-assigned this Nov 1, 2024
@Courey
Copy link
Contributor Author

Courey commented Nov 1, 2024

import { tables } from '@architect/functions'
import { ReturnValue } from '@aws-sdk/client-dynamodb'
import type { DynamoDBDocument } from '@aws-sdk/lib-dynamodb'
import { paginateScan, UpdateCommand } from '@aws-sdk/lib-dynamodb'

import {
  type Circular,
  parseEventFromSubject,
} from '~/routes/circulars/circulars.lib'

export async function backfill() {
  console.log('Starting backfill...')
  const db = await tables()
  const client = db._doc as unknown as DynamoDBDocument
  const TableName = db.name('circulars')
  const pages = paginateScan(
    { client },
    {
      TableName,
    }
  )
  for await (const page of pages) {
    for (const record of page.Items || []) {
      const circular = record as unknown as Circular
      const validEvent =
        circular.eventId || parseEventFromSubject(circular.subject)
      if (!circular.eventId && validEvent) {
        const updateParams = {
          TableName,
          Key: {
            circularId: circular.circularId,
          },
          UpdateExpression: 'SET eventId = :eventId',
          ExpressionAttributeValues: {
            ':eventId': validEvent,
          },
          ReturnValues: ReturnValue.UPDATED_NEW,
        }
        await client.send(new UpdateCommand(updateParams))
      }
    }
  }
  console.log('... End backfill')
}
await backfill()

@Courey
Copy link
Contributor Author

Courey commented Nov 1, 2024

blocked till #2661 goes in as it uses a function defined in that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Blocked
Development

No branches or pull requests

1 participant