Skip to content

Commit

Permalink
Added new database migration file validation workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Gareth40342 committed Oct 13, 2024
1 parent 2a9a783 commit 26ef9ff
Show file tree
Hide file tree
Showing 4 changed files with 272 additions and 0 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/check-database-migration-files.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Flyway Migration Files

on:
pull_request:
branches:
- '**'

jobs:
validate:
runs-on: ubuntu-latest

steps:
- name: Checkout current branch
uses: actions/checkout@v3

- name: Fetch base branch
run: |
git fetch origin +refs/heads/${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}
- name: Check for new migration files
run: |
echo "Checking for new migration files..."
# Set the directory for migrations
MIGRATION_DIR=src/main/resources/db/migration
# Get existing migration files from the base branch
BASE_MIGRATION_FILES=$(git ls-tree -r --name-only origin/${{ github.base_ref }} -- $MIGRATION_DIR)
# Initialize variable to hold the latest base file
LATEST_BASE_FILE=""
LATEST_BASE_TIMESTAMP=""
# Determine the latest timestamp from the base branch
for BASE_FILE in $BASE_MIGRATION_FILES; do
BASE_TIMESTAMP=$(echo $BASE_FILE | grep -oP 'V\K[0-9_]{10,14}')
# Check if this base timestamp is later than the current latest
if [[ "$LATEST_BASE_TIMESTAMP" < "$BASE_TIMESTAMP" ]]; then
LATEST_BASE_TIMESTAMP="$BASE_TIMESTAMP"
LATEST_BASE_FILE="$BASE_FILE"
fi
done
echo " "
echo "Base migration file with the latest timestamp:"
echo " $LATEST_BASE_FILE"
# Get the new migration files added in the current branch
NEW_MIGRATION_FILES=$(git diff --name-only origin/${{ github.base_ref }} -- $MIGRATION_DIR)
# Output new migration files found in the current branch
echo " "
if [[ -z "$NEW_MIGRATION_FILES" ]]; then
echo "No new migration files found."
exit 0
else
echo "New migration files in the current branch:"
# Output the new migration files with indentation
for FILE in $NEW_MIGRATION_FILES; do
echo " $FILE"
done
fi
FORMAT_ERROR_FILES=()
BASE_BRANCH_NAME=${{ github.base_ref }}
CURRENT_BRANCH_NAME=${{ github.head_ref }}
# First check for format validity
for FILE in $NEW_MIGRATION_FILES; do
FILENAME=$(basename "$FILE") # Extract just the filename from the full path
if ! [[ "$FILENAME" =~ ^V[0-9]{4}_[0-9]{2}_[0-9]{2}_[0-9]{4}__.*$ ]]; then
FORMAT_ERROR_FILES+=("$FILE") # Collect the full file path for invalid format
fi
done
# Output errors for format
if [[ ${#FORMAT_ERROR_FILES[@]} -gt 0 ]]; then
echo " "
echo "Error: The following migration file names do not have a valid timestamp format:"
for FORMAT_ERROR_FILE in "${FORMAT_ERROR_FILES[@]}"; do
echo " $FORMAT_ERROR_FILE"
done
exit 1 # Exit with an error code
fi
ERROR_FILES=()
# Check for new migration files and their timestamps
for FILE in $NEW_MIGRATION_FILES; do
TIMESTAMP=$(echo $FILE | grep -oP 'V\K[0-9_]{10,14}')
# Ensure the timestamp is valid
if [[ -z "$TIMESTAMP" ]]; then
echo "Error: File $FILE does not have a valid timestamp."
exit 1
fi
# Validate against the latest base file timestamp
if [[ "$TIMESTAMP" < "$LATEST_BASE_TIMESTAMP" ]]; then
ERROR_FILES+=("$FILE") # Collect the file name for later output
fi
done
# Output errors for timestamps
if [[ ${#ERROR_FILES[@]} -gt 0 ]]; then
echo " "
echo "Error: The following migration file names in the current branch [$CURRENT_BRANCH_NAME]:"
for ERROR_FILE in "${ERROR_FILES[@]}"; do
echo " $ERROR_FILE"
done
echo "Contain timestamps earlier than the latest migration file from the base branch [$BASE_BRANCH_NAME]:"
echo " $LATEST_BASE_FILE"
exit 1 # Exit with an error code
fi
echo "All new migration files are valid."
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Add scenario
*/
INSERT INTO dbs.scenario (name, notifications_to_delete, notifications_to_create)
VALUES ('Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant',
'{"Notice.AAA6.ClaimantIntent.CCJ.Requested.Claimant",
"Notice.AAA6.ClaimantIntent.RequestedCCJ.ClaimantAcceptedDefendantPlan.Claimant",
"Notice.AAA6.ClaimantIntent.RequestCCJ.ClaimantAcceptOrRejectPlan.SettlementRequested.NoDefResponse.Claimant",
"Notice.AAA6.ClaimantIntent.RequestCCJ.ClaimantAcceptOrRejectPlan.SettlementRequested.DefPaymentMissed.Claimant"}',
'{"Notice.AAA6.JudgmentsOnline.IssuedCCJ.Claimant": ["djClaimantNotificationMessage", "djClaimantNotificationMessageCy"]}');

/**
* Add notification template
*/
INSERT INTO dbs.dashboard_notifications_templates ( template_name, title_En, title_Cy, description_En, description_Cy
, notification_role)
VALUES ('Notice.AAA6.JudgmentsOnline.IssuedCCJ.Claimant',
'A judgment against the defendant has been made',
'Mae dyfarniad wedi’i wneud yn erbyn y diffynnydd',
'<p class="govuk-body">The defendant should now pay you according to the terms of the judgment. <br> Once they do, you should <a href="{CONFIRM_YOU_HAVE_BEEN_PAID_URL}" class="govuk-link">confirm that they’ve paid you the full amount that you’re owed</a>.<br>If they do not pay you by the date on the judgment, you can <u>ask for enforcement action to be taken against them</u>. <br>If you need to change the terms of payment within the judgment, such as the instalments you had previously agreed, you can ${djClaimantNotificationMessage}.</p>',
'<p class="govuk-body">Dylai’r diffynnydd eich talu yn unol â thelerau’r dyfarniad. <br> Unwaith y byddant yn gwneud hynny, dylech <a href="{CONFIRM_YOU_HAVE_BEEN_PAID_URL}" class="govuk-link">gadarnhau eu bod wedi talu’r swm llawn sy’n ddyledus i chi</a>.<br>Os na fyddant yn eich talu erbyn y dyddiad ar y dyfarniad, gallwch <u>ofyn am gymryd camau gorfodi yn eu herbyn</u>. <br>Os oes arnoch angen newid y telerau talu o fewn y dyfarniad, fel y rhandaliadau roeddech wedi cytuno arnynt yn flaenorol, gallwch ${djClaimantNotificationMessageCy}.</p>',
'CLAIMANT');

/**
* Add task list items claimant
*/
INSERT INTO dbs.task_item_template (task_name_en, category_en, task_name_cy, category_cy, template_name,
scenario_name, task_status_sequence, role, task_order)
VALUES ('<a>View the hearing</a>', 'Hearing',
'<a>Gweld y gwrandawiad</a>', 'Gwrandawiad',
'Hearing.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 8),
('<a>Upload hearing documents</a>', 'Hearing',
'<a>Llwytho dogfennau''r gwrandawiad</a>', 'Gwrandawiad',
'Hearing.Document.Upload', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 9),
('<a>View documents</a>', 'Hearing',
'<a>Gweld y dogfennau</a>', 'Gwrandawiad',
'Hearing.Document.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 10),
('<a>Add the trial arrangements</a>', 'Hearing',
'<a>Ychwanegu trefniadau''r treial</a>', 'Gwrandawiad',
'Hearing.Arrangements.Add', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 11),
('<a>View the bundle</a>', 'Hearing',
'<a>Gweld y bwndel</a>', 'Gwrandawiad',
'Hearing.Bundle.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 12),
('<a href={VIEW_ORDERS_AND_NOTICES} rel="noopener noreferrer" class="govuk-link">View orders and notices</a>', 'Orders and notices from the court',
'<a href={VIEW_ORDERS_AND_NOTICES} rel="noopener noreferrer" class="govuk-link">Gweld gorchmynion a rhybuddion</a>', 'Gorchmynion a rhybuddion gan y llys',
'Order.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{3, 3}', 'CLAIMANT', 13),
('<a href={VIEW_JUDGEMENT} class="govuk-link">View the judgment</a>', 'Judgments from the court',
'<a href={VIEW_JUDGEMENT} class="govuk-link">Gweld y Dyfarniad</a>', 'Dyfarniadau gan y llys',
'Judgment.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{3, 3}', 'CLAIMANT', 14),
('<a href={COMFIRM_YOU_PAID_JUDGMENT_DEBT} class="govuk-link">Confirm you''ve paid a judgment (CCJ) debt</a>', 'Judgments from the court',
'<a href={COMFIRM_YOU_PAID_JUDGMENT_DEBT} class="govuk-link">Cadarnhewch eich bod wedi talu dyled dyfarniad (CCJ)</a>', 'Dyfarniadau gan y llys',
'Judgment.Cosc', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{3, 3}', 'CLAIMANT', 15);
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Add scenario
*/
INSERT INTO dbs.scenario (name, notifications_to_delete, notifications_to_create)
VALUES ('Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant',
'{"Notice.AAA6.ClaimantIntent.CCJ.Requested.Claimant",
"Notice.AAA6.ClaimantIntent.RequestedCCJ.ClaimantAcceptedDefendantPlan.Claimant",
"Notice.AAA6.ClaimantIntent.RequestCCJ.ClaimantAcceptOrRejectPlan.SettlementRequested.NoDefResponse.Claimant",
"Notice.AAA6.ClaimantIntent.RequestCCJ.ClaimantAcceptOrRejectPlan.SettlementRequested.DefPaymentMissed.Claimant"}',
'{"Notice.AAA6.JudgmentsOnline.IssuedCCJ.Claimant": ["djClaimantNotificationMessage", "djClaimantNotificationMessageCy"]}');

/**
* Add notification template
*/
INSERT INTO dbs.dashboard_notifications_templates ( template_name, title_En, title_Cy, description_En, description_Cy
, notification_role)
VALUES ('Notice.AAA6.JudgmentsOnline.IssuedCCJ.Claimant',
'A judgment against the defendant has been made',
'Mae dyfarniad wedi’i wneud yn erbyn y diffynnydd',
'<p class="govuk-body">The defendant should now pay you according to the terms of the judgment. <br> Once they do, you should <a href="{CONFIRM_YOU_HAVE_BEEN_PAID_URL}" class="govuk-link">confirm that they’ve paid you the full amount that you’re owed</a>.<br>If they do not pay you by the date on the judgment, you can <u>ask for enforcement action to be taken against them</u>. <br>If you need to change the terms of payment within the judgment, such as the instalments you had previously agreed, you can ${djClaimantNotificationMessage}.</p>',
'<p class="govuk-body">Dylai’r diffynnydd eich talu yn unol â thelerau’r dyfarniad. <br> Unwaith y byddant yn gwneud hynny, dylech <a href="{CONFIRM_YOU_HAVE_BEEN_PAID_URL}" class="govuk-link">gadarnhau eu bod wedi talu’r swm llawn sy’n ddyledus i chi</a>.<br>Os na fyddant yn eich talu erbyn y dyddiad ar y dyfarniad, gallwch <u>ofyn am gymryd camau gorfodi yn eu herbyn</u>. <br>Os oes arnoch angen newid y telerau talu o fewn y dyfarniad, fel y rhandaliadau roeddech wedi cytuno arnynt yn flaenorol, gallwch ${djClaimantNotificationMessageCy}.</p>',
'CLAIMANT');

/**
* Add task list items claimant
*/
INSERT INTO dbs.task_item_template (task_name_en, category_en, task_name_cy, category_cy, template_name,
scenario_name, task_status_sequence, role, task_order)
VALUES ('<a>View the hearing</a>', 'Hearing',
'<a>Gweld y gwrandawiad</a>', 'Gwrandawiad',
'Hearing.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 8),
('<a>Upload hearing documents</a>', 'Hearing',
'<a>Llwytho dogfennau''r gwrandawiad</a>', 'Gwrandawiad',
'Hearing.Document.Upload', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 9),
('<a>View documents</a>', 'Hearing',
'<a>Gweld y dogfennau</a>', 'Gwrandawiad',
'Hearing.Document.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 10),
('<a>Add the trial arrangements</a>', 'Hearing',
'<a>Ychwanegu trefniadau''r treial</a>', 'Gwrandawiad',
'Hearing.Arrangements.Add', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 11),
('<a>View the bundle</a>', 'Hearing',
'<a>Gweld y bwndel</a>', 'Gwrandawiad',
'Hearing.Bundle.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 12),
('<a href={VIEW_ORDERS_AND_NOTICES} rel="noopener noreferrer" class="govuk-link">View orders and notices</a>', 'Orders and notices from the court',
'<a href={VIEW_ORDERS_AND_NOTICES} rel="noopener noreferrer" class="govuk-link">Gweld gorchmynion a rhybuddion</a>', 'Gorchmynion a rhybuddion gan y llys',
'Order.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{3, 3}', 'CLAIMANT', 13),
('<a href={VIEW_JUDGEMENT} class="govuk-link">View the judgment</a>', 'Judgments from the court',
'<a href={VIEW_JUDGEMENT} class="govuk-link">Gweld y Dyfarniad</a>', 'Dyfarniadau gan y llys',
'Judgment.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{3, 3}', 'CLAIMANT', 14),
('<a href={COMFIRM_YOU_PAID_JUDGMENT_DEBT} class="govuk-link">Confirm you''ve paid a judgment (CCJ) debt</a>', 'Judgments from the court',
'<a href={COMFIRM_YOU_PAID_JUDGMENT_DEBT} class="govuk-link">Cadarnhewch eich bod wedi talu dyled dyfarniad (CCJ)</a>', 'Dyfarniadau gan y llys',
'Judgment.Cosc', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{3, 3}', 'CLAIMANT', 15);
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Add scenario
*/
INSERT INTO dbs.scenario (name, notifications_to_delete, notifications_to_create)
VALUES ('Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant',
'{"Notice.AAA6.ClaimantIntent.CCJ.Requested.Claimant",
"Notice.AAA6.ClaimantIntent.RequestedCCJ.ClaimantAcceptedDefendantPlan.Claimant",
"Notice.AAA6.ClaimantIntent.RequestCCJ.ClaimantAcceptOrRejectPlan.SettlementRequested.NoDefResponse.Claimant",
"Notice.AAA6.ClaimantIntent.RequestCCJ.ClaimantAcceptOrRejectPlan.SettlementRequested.DefPaymentMissed.Claimant"}',
'{"Notice.AAA6.JudgmentsOnline.IssuedCCJ.Claimant": ["djClaimantNotificationMessage", "djClaimantNotificationMessageCy"]}');

/**
* Add notification template
*/
INSERT INTO dbs.dashboard_notifications_templates ( template_name, title_En, title_Cy, description_En, description_Cy
, notification_role)
VALUES ('Notice.AAA6.JudgmentsOnline.IssuedCCJ.Claimant',
'A judgment against the defendant has been made',
'Mae dyfarniad wedi’i wneud yn erbyn y diffynnydd',
'<p class="govuk-body">The defendant should now pay you according to the terms of the judgment. <br> Once they do, you should <a href="{CONFIRM_YOU_HAVE_BEEN_PAID_URL}" class="govuk-link">confirm that they’ve paid you the full amount that you’re owed</a>.<br>If they do not pay you by the date on the judgment, you can <u>ask for enforcement action to be taken against them</u>. <br>If you need to change the terms of payment within the judgment, such as the instalments you had previously agreed, you can ${djClaimantNotificationMessage}.</p>',
'<p class="govuk-body">Dylai’r diffynnydd eich talu yn unol â thelerau’r dyfarniad. <br> Unwaith y byddant yn gwneud hynny, dylech <a href="{CONFIRM_YOU_HAVE_BEEN_PAID_URL}" class="govuk-link">gadarnhau eu bod wedi talu’r swm llawn sy’n ddyledus i chi</a>.<br>Os na fyddant yn eich talu erbyn y dyddiad ar y dyfarniad, gallwch <u>ofyn am gymryd camau gorfodi yn eu herbyn</u>. <br>Os oes arnoch angen newid y telerau talu o fewn y dyfarniad, fel y rhandaliadau roeddech wedi cytuno arnynt yn flaenorol, gallwch ${djClaimantNotificationMessageCy}.</p>',
'CLAIMANT');

/**
* Add task list items claimant
*/
INSERT INTO dbs.task_item_template (task_name_en, category_en, task_name_cy, category_cy, template_name,
scenario_name, task_status_sequence, role, task_order)
VALUES ('<a>View the hearing</a>', 'Hearing',
'<a>Gweld y gwrandawiad</a>', 'Gwrandawiad',
'Hearing.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 8),
('<a>Upload hearing documents</a>', 'Hearing',
'<a>Llwytho dogfennau''r gwrandawiad</a>', 'Gwrandawiad',
'Hearing.Document.Upload', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 9),
('<a>View documents</a>', 'Hearing',
'<a>Gweld y dogfennau</a>', 'Gwrandawiad',
'Hearing.Document.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 10),
('<a>Add the trial arrangements</a>', 'Hearing',
'<a>Ychwanegu trefniadau''r treial</a>', 'Gwrandawiad',
'Hearing.Arrangements.Add', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 11),
('<a>View the bundle</a>', 'Hearing',
'<a>Gweld y bwndel</a>', 'Gwrandawiad',
'Hearing.Bundle.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{2, 2}', 'CLAIMANT', 12),
('<a href={VIEW_ORDERS_AND_NOTICES} rel="noopener noreferrer" class="govuk-link">View orders and notices</a>', 'Orders and notices from the court',
'<a href={VIEW_ORDERS_AND_NOTICES} rel="noopener noreferrer" class="govuk-link">Gweld gorchmynion a rhybuddion</a>', 'Gorchmynion a rhybuddion gan y llys',
'Order.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{3, 3}', 'CLAIMANT', 13),
('<a href={VIEW_JUDGEMENT} class="govuk-link">View the judgment</a>', 'Judgments from the court',
'<a href={VIEW_JUDGEMENT} class="govuk-link">Gweld y Dyfarniad</a>', 'Dyfarniadau gan y llys',
'Judgment.View', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{3, 3}', 'CLAIMANT', 14),
('<a href={COMFIRM_YOU_PAID_JUDGMENT_DEBT} class="govuk-link">Confirm you''ve paid a judgment (CCJ) debt</a>', 'Judgments from the court',
'<a href={COMFIRM_YOU_PAID_JUDGMENT_DEBT} class="govuk-link">Cadarnhewch eich bod wedi talu dyled dyfarniad (CCJ)</a>', 'Dyfarniadau gan y llys',
'Judgment.Cosc', 'Scenario.AAA6.JudgmentsOnline.IssuedCCJ.Claimant', '{3, 3}', 'CLAIMANT', 15);

0 comments on commit 26ef9ff

Please sign in to comment.