Skip to content

Instantly share code, notes, and snippets.

View blackjid's full-sized avatar
🎹

Juan Ignacio Donoso blackjid

🎹
View GitHub Profile
@blackjid
blackjid / Readme.md
Last active December 4, 2024 17:30
Rails abort if pending migrations with data

Abort if pending migrations with data

We use the awesome gem data-migrate with comes with a handy rake task to check if you have migrations pending. The task is really and extention to the task built in on rails but that also check for pending data migrations.

That rake task is available since version 6.3.0 of data-migrate. If you are stuck in an older version like I was here is a version of the rake task you can put in your project.

rake db:abort_if_pending_migrations:with_data
#!/bin/bash
# Escape for JSON
json_escape() {
echo "$1" | /usr/bin/python3 -c 'import json,sys; print(json.dumps(sys.stdin.read().strip()))'
}
# Get system data
model_id=$(/usr/sbin/system_profiler SPHardwareDataType | awk -F ': ' '/Model Identifier/ { print $2 }')
serial_number=$(/usr/sbin/system_profiler SPHardwareDataType | awk -F ': ' '/Serial Number/ { print $2 }')