Skip to content

Commit

Permalink
Restores migrate run entry season
Browse files Browse the repository at this point in the history
  • Loading branch information
mskwon1 committed Jan 16, 2024
1 parent 6300647 commit 952fd97
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import updateRunEntry from './run-entry/update';
import getFineStatus from './fine/status';
import getUserRunEntries from './run-entry/me';
import migrateWeeklyReportSeason from './weekly-report/migrateSeason';
import migrateRunEntrySeason from './run-entry/migrateSeason';

const functions = {
findAllUsers,
Expand All @@ -30,6 +31,7 @@ const functions = {
getFineStatus,
getUserRunEntries,
migrateWeeklyReportSeason,
migrateRunEntrySeason,
};

export default functions;
30 changes: 30 additions & 0 deletions src/functions/run-entry/migrateSeason/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import RunEntryService from 'src/services/runEntryService';

const client = new DynamoDBClient({ region: 'ap-northeast-2' });

const handler = async () => {
const runEntryService = new RunEntryService(client);

try {
const runEntries = await runEntryService.findAll();
const runEntriesWithSeason = runEntries.map((entry) => {
return {
...entry,
season: '2023',
};
});

console.log(runEntries);

const { createdItemsCount } = await runEntryService.createOrUpdateMany(
runEntriesWithSeason
);

console.log(createdItemsCount);
} catch (error) {
console.log(error);
}
};

export const main = handler;
23 changes: 23 additions & 0 deletions src/functions/run-entry/migrateSeason/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { handlerPath } from '@libs/handler-resolver';
import { LambdaFunctionEntry } from 'src/utils';

const migrateRunEntrySeason: LambdaFunctionEntry = {
handler: `${handlerPath(__dirname)}/handler.main`,
iamRoleStatements: [
{
Effect: 'Allow',
Action: ['dynamodb:BatchWriteItem', 'dynamodb:Query'],
Resource: [
{ 'Fn::GetAtt': ['dalsamoSingleTable', 'Arn'] },
{
'Fn::Join': [
'/',
[{ 'Fn::GetAtt': ['dalsamoSingleTable', 'Arn'] }, 'index/*'],
],
},
],
},
],
};

export default migrateRunEntrySeason;

0 comments on commit 952fd97

Please sign in to comment.