Replies: 3 comments 1 reply
-
I'm also looking for a better way to handle this. Is there a better solution around than having a one-time job that fetches all entities and then updates/put them immediately? // without handling errors, batching, unprocessed entities, etc.
const allMyEntities = // get all entities by looping queries, scan, etc.
await MyEntity.put(allMyEntities).go({ pages: "all" }) |
Beta Was this translation helpful? Give feedback.
-
I think having a separate repo that could resemble electrodb migration tools or some kind of cli designed to work with electrodb would good. This would need to take the different in schema versions (by checking the entity version) and then generate the commands needed to backfill version 1 with 2, etc. |
Beta Was this translation helpful? Give feedback.
-
It would be nice to have a built-in function which you can call on entity-level. Here's a generic but ineffecient workaround: type BackfillIndexOptions = {
tableName?: string;
region?: string;
};
export const backfillIndex = async <E extends Entity<any, any, any, any>>(
entity: E,
options: BackfillIndexOptions = {},
): Promise<void> => {
if (options.tableName) {
entity.setTableName(options.tableName);
}
if (options.region) {
entity.setClient(new DynamoDBClient({ region: options.region }));
}
const items = await entity.scan.go({ pages: 'all' });
for (const item of items.data) {
const result = await entity
.put(item)
.where(({ updatedAt }, { eq }) => eq(updatedAt, item.updatedAt))
.go();
console.log('Updated item', result);
}
} |
Beta Was this translation helpful? Give feedback.
-
Imagine this situation:
Only newly inserted rows will be present in the index, see the following screenshot:
I imagine I can write a script that hits DynamoDB directly and fills all the missing
gsi1pk
andgsi1sk
, but is there a way to do this from electrodb itself? I'd much rather that'd be case.It doesn't have to be something automatic at startup, 'cause I imagine there'd be a cost to this. But if I know I'm in the situation, it'd be great to do something like:
MyEntity.byMyCondition.backfill()
.Beta Was this translation helpful? Give feedback.
All reactions