From f8b9c2038cbd706d2de35cacca11c7fc917da1ab Mon Sep 17 00:00:00 2001 From: rublea Date: Tue, 10 Dec 2024 16:03:18 +0100 Subject: [PATCH] fix: migration script for v2 --- .../spacecat-shared-data-access/migrate_v2.sh | 246 +++++++++++++++++- 1 file changed, 243 insertions(+), 3 deletions(-) diff --git a/packages/spacecat-shared-data-access/migrate_v2.sh b/packages/spacecat-shared-data-access/migrate_v2.sh index 9288c888..d51e051c 100644 --- a/packages/spacecat-shared-data-access/migrate_v2.sh +++ b/packages/spacecat-shared-data-access/migrate_v2.sh @@ -10,11 +10,19 @@ SITE_TABLE="spacecat-services-sites-dev" ORGANIZATION_TABLE="spacecat-services-organizations-dev" CONFIGURATION_TABLE="spacecat-services-configurations-dev" DATA_TABLE="spacecat-services-data-dev" +EXPERIMENT_TABLE="spacecat-services-experiments-dev" +SITE_CANDIDATE_TABLE="spacecat-services-site-candidates-dev" +TOP_PAGES_TABLE="spacecat-services-site-top-pages-dev" +KEY_EVENTS_TABLE="spacecat-services-key-events-dev" # Fetch all sites SITES=$($AWS_CMD scan --table-name $SITE_TABLE) ORGANIZATIONS=$($AWS_CMD scan --table-name $ORGANIZATION_TABLE) CONFIGURATIONS=$($AWS_CMD scan --table-name $CONFIGURATION_TABLE) +EXPERIMENTS=$($AWS_CMD scan --table-name $EXPERIMENT_TABLE) +SITE_CANDIDATES=$($AWS_CMD scan --table-name $SITE_CANDIDATE_TABLE) +TOP_PAGES=$($AWS_CMD scan --table-name $TOP_PAGES_TABLE) +KEY_EVENTS=$($AWS_CMD scan --table-name $KEY_EVENTS_TABLE) # Migrate each site echo "$SITES" | jq -c '.Items[]' | while read -r site; do @@ -68,6 +76,7 @@ EOF $AWS_LOCAL_CMD put-item --table-name $DATA_TABLE --item "$MIGRATED_SITE" done +echo "Migrated sites successfully." # Migrate each organization echo "$ORGANIZATIONS" | jq -c '.Items[]' | while read -r org; do @@ -87,7 +96,7 @@ echo "$ORGANIZATIONS" | jq -c '.Items[]' | while read -r org; do "organizationId": {"S": "$ORG_ID"}, "imsOrgId": {"S": "$IMS_ORG_ID"}, "name": {"S": "$NAME"}, - "gsi1pk": {"S": "$GSI1PK"}, + "gsi1pk": {"S": "$ORGANIZATION_GSI1PK"}, "gsi1sk": {"S": "$ORGANIZATION_GSI1SK"}, "pk": {"S": "$ORGANIZATION_PK"}, "sk": {"S": "$ORGANIZATION_SK"}, @@ -104,9 +113,240 @@ echo "$ORGANIZATIONS" | jq -c '.Items[]' | while read -r org; do EOF ) - # Insert migrated organization data into the organization table + # Insert migrated organization into the data table $AWS_LOCAL_CMD put-item --table-name $DATA_TABLE --item "$MIGRATED_ORG" done -#TODO Migrate each configuration, top page, etc +echo "Migrated organizations successfully." + +# Migrate configurations +echo "$CONFIGURATIONS" | jq -c '.Items[]' | while read -r configuration; do + VERSION=$(echo $configuration | jq -r '.version.N') + CONFIGURATION_ID=$(uuidgen) + CONFIGURATION_PK="\$spacecat#configurationId_$CONFIGURATION_ID" + CONFIGURATION_SK="\$configuration_1" + CONFIGURATION_GSI1PK="all_configurations" + CONFIGURATION_GSI1SK="\$configuration_1#version_${VERSION}" + CREATED_AT=$(echo $configuration | jq -r '.createdAt.S') + UPDATED_AT=$(echo $configuration | jq -r '.updatedAt.S') + QUEUES=$(echo $configuration | jq -r '.queues // {"M": {}}') + JOBS=$(echo $configuration | jq -r '.jobs // {"L": {}}') + HANDLERS=$(echo $configuration | jq -r '.handlers // {"M": {}}') + SLACK_ROLES=$(echo $configuration | jq -r '.slackRoles // {"M": {}}') + MIGRATED_CONFIGURATION=$(cat <