From 75c9374420b9e07973b02a76ec5f465c95a9ae62 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Wed, 21 Jun 2023 13:21:26 +0100 Subject: [PATCH] Add migration check script --- .github/github-bot.yml | 7 ------- Makefile | 7 +++++++ _assets/ci/Jenkinsfile.tests | 5 +++++ _assets/hooks/pre-merge-commit | 3 +++ _assets/hooks/pre-rebase | 3 +++ _assets/scripts/migration_check.sh | 29 +++++++++++++++++++++++++++++ 6 files changed, 47 insertions(+), 7 deletions(-) create mode 100755 _assets/hooks/pre-merge-commit create mode 100755 _assets/hooks/pre-rebase create mode 100755 _assets/scripts/migration_check.sh diff --git a/.github/github-bot.yml b/.github/github-bot.yml index 166db3689..009d181d3 100644 --- a/.github/github-bot.yml +++ b/.github/github-bot.yml @@ -3,13 +3,6 @@ _extends: probot-settings github-team: slug: 'go' -prchecklist: - title: Pull Request Checklist - checklist: - - 'Have you updated the documentation, if impacted (e.g. [docs.status.im](https://status.im/docs/))?' - - 'Have you tested changes with mobile?' - - 'Have you tested changes with desktop?' - stale: daysUntilStale: 90 daysUntilPullRequestStale: 14 diff --git a/Makefile b/Makefile index 7ad8898e8..2b4ccd161 100644 --- a/Makefile +++ b/Makefile @@ -388,6 +388,13 @@ migration: DEFAULT_MIGRATION_PATH := appdatabase/migrations/sql migration: touch $(DEFAULT_MIGRATION_PATH)/$(shell date +%s)_$(D).up.sql +migration-check: + bash _assets/scripts/migration_check.sh + +install-git-hooks: + @ln -s -f $(shell pwd)/_assets/hooks/pre-rebase .git/hooks + @ln -s -f $(shell pwd)/_assets/hooks/pre-merge-commit .git/hooks + migration-protocol: DEFAULT_PROTOCOL_PATH := protocol/migrations/sqlite migration-protocol: touch $(DEFAULT_PROTOCOL_PATH)/$(shell date +%s)_$(D).up.sql diff --git a/_assets/ci/Jenkinsfile.tests b/_assets/ci/Jenkinsfile.tests index e20a66dea..e590c098f 100644 --- a/_assets/ci/Jenkinsfile.tests +++ b/_assets/ci/Jenkinsfile.tests @@ -49,6 +49,11 @@ pipeline { } } } + stage('Migration') { + steps { script { + nix.shell('make migration-check') + } } + } stage('Lint') { steps { script { diff --git a/_assets/hooks/pre-merge-commit b/_assets/hooks/pre-merge-commit new file mode 100755 index 000000000..9e119b8b9 --- /dev/null +++ b/_assets/hooks/pre-merge-commit @@ -0,0 +1,3 @@ +#!/bin/bash + +make migration-check diff --git a/_assets/hooks/pre-rebase b/_assets/hooks/pre-rebase new file mode 100755 index 000000000..9e119b8b9 --- /dev/null +++ b/_assets/hooks/pre-rebase @@ -0,0 +1,3 @@ +#!/bin/bash + +make migration-check diff --git a/_assets/scripts/migration_check.sh b/_assets/scripts/migration_check.sh new file mode 100755 index 000000000..a7c9833e6 --- /dev/null +++ b/_assets/scripts/migration_check.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -e +set -o pipefail + +check_migration_order() { + local prev_migration="" + for file in "$@"; do + current_migration=$(echo "$file" | cut -d'-' -f1) + + if [[ ! -z "$prev_migration" && "$current_migration" < "$prev_migration" ]]; then + + echo "migration ${current_migration} is not in order with ${prev_migration}" + echo "Error: Migration files are out of order. Please ensure migrations are added in chronological order." + exit 1 + fi + + prev_migration="$current_migration" + done +} + +committed_files=$(git ls-tree -r --name-only HEAD protocol/migrations/sqlite/*.sql | sort) +staged_files=$(git diff --name-only origin/develop protocol/migrations/sqlite/*.sql | sort) + +all_files=$(echo -e "$committed_files\n$staged_files") + +check_migration_order $all_files + +exit 0