From 44833c93ad267b90bf9e31318b48dd06290c7923 Mon Sep 17 00:00:00 2001 From: Dinush Chathurya Date: Tue, 31 Dec 2024 15:24:16 +0000 Subject: [PATCH] feat: Update workflow --- ..._31_151857_add_testhree_to_users_table.php | 32 +++++++++++++++++ ..._31_152029_add_testfour_to_users_table.php | 34 +++++++++++++++++++ gh-ost-with-tracking.sh | 18 +++++++++- 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2024_12_31_151857_add_testhree_to_users_table.php create mode 100644 database/migrations/2024_12_31_152029_add_testfour_to_users_table.php diff --git a/database/migrations/2024_12_31_151857_add_testhree_to_users_table.php b/database/migrations/2024_12_31_151857_add_testhree_to_users_table.php new file mode 100644 index 0000000..82045df --- /dev/null +++ b/database/migrations/2024_12_31_151857_add_testhree_to_users_table.php @@ -0,0 +1,32 @@ +string('testthree')->nullable()->after('email'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('testthree'); + }); + } +} diff --git a/database/migrations/2024_12_31_152029_add_testfour_to_users_table.php b/database/migrations/2024_12_31_152029_add_testfour_to_users_table.php new file mode 100644 index 0000000..2ddf402 --- /dev/null +++ b/database/migrations/2024_12_31_152029_add_testfour_to_users_table.php @@ -0,0 +1,34 @@ +string('testfour')->nullable()->after('email'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // gh-ost: ALTER TABLE users DROP COLUMN testfour; + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('testfour'); + }); + } +} diff --git a/gh-ost-with-tracking.sh b/gh-ost-with-tracking.sh index 95fe330..9398516 100644 --- a/gh-ost-with-tracking.sh +++ b/gh-ost-with-tracking.sh @@ -31,9 +31,17 @@ record_migration() { local migration_name="$1" local BATCH + # Check if the migration is already recorded + if [[ $(is_migration_applied "$migration_name") -ne 0 ]]; then + echo "Skipping already recorded migration: $migration_name" + return 0 + fi + + # Determine the next batch number BATCH=$(mysql -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USERNAME" -p"$DB_PASSWORD" "$DB_DATABASE" \ -e "SELECT IFNULL(MAX(batch), 0) + 1 AS next_batch FROM migrations;" | tail -n 1) + # Insert the migration record mysql -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USERNAME" -p"$DB_PASSWORD" "$DB_DATABASE" \ -e "INSERT INTO migrations (migration, batch) VALUES ('$migration_name', $BATCH);" || { echo "Error: Failed to record migration in migrations table: $migration_name" >&2 @@ -46,7 +54,15 @@ record_migration() { extract_sql() { local file="$1" local pattern="$2" - grep -oP "$pattern" "$file" | sed 's/.*gh-ost: //' + local sql=$(grep -oP "$pattern" "$file" | sed 's/.*gh-ost: //') + + if [[ -z "$sql" ]]; then + echo "Debug: No SQL extracted for pattern: $pattern in file: $file" + else + echo "Debug: Extracted SQL: $sql" + fi + + echo "$sql" } # Function to validate gh-ost migration