Skip to content

Commit

Permalink
feat: Update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dinushchathurya committed Dec 31, 2024
1 parent 44e29da commit 44833c9
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddTesthreeToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('testthree')->nullable()->after('email');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('testthree');
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddTestfourToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// gh-ost: ALTER TABLE users ADD COLUMN testfour VARCHAR(255) NULL AFTER email;
Schema::table('users', function (Blueprint $table) {
$table->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');
});
}
}
18 changes: 17 additions & 1 deletion gh-ost-with-tracking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 44833c9

Please sign in to comment.