Skip to content

Instantly share code, notes, and snippets.

@jeremyjarrell
jeremyjarrell / compare_production_to_qa.rb
Created March 16, 2012 19:19
Compares the production to qa branches for differences
def compare_branches(source, destination)
begin
IO.popen 'git fetch'
gitdiff = `git diff --name-status #{source}..#{destination}`
rescue
raise "git unavailable"
end
if (!gitdiff.empty?)
raise "Branches do not match!\n" + gitdiff
end
@jeremyjarrell
jeremyjarrell / Prefix migrations with timestamp Ant task
Last active May 15, 2017 15:53
An Ant task that prefixes new SQL migration files with a timestamp precise to milliseconds. The following usage will add a prefix to any SQL file in a hardcoded directory that does not begin with an number and double leading underscore: $ ant prefix-new-migrations
<project name="migrations">
<target name="prefix-new-migrations">
<foreach target="rename-file" param="the-file">
<path>
<!-- The hardcoded directory containing the migrations -->
<fileset dir="./src/db/migrations" casesensitive="no" includes="*.sql">
<!-- Exclude any migration files which have already been prefixed -->
<not>
<filename regex="\d+__.*" casesensitive="true"/>
@jeremyjarrell
jeremyjarrell / Prefix migrations with timestamp Groovy task
Created July 25, 2013 20:00
A Groovy task that prefixes new SQL migration files with a timestamp precise to milliseconds. The following usage will add a prefix to any SQL file in a hardcoded directory that does not begin with an number and double leading underscore: $ gradle prefixNewMigrations
task prefixNewMigrations {
fileTree(dir: 'dev/src/db/listhub').exclude({ isFilePrefixed(it.file) }).each { file ->
doLast {
def timestamp = new Date().format('yyyyMMddHHmmssSSS', TimeZone.getTimeZone('GMT'))
println "Renaming $file.name to ${timestamp}__$file.name"
file.renameTo("$file.parentFile.absolutePath$file.separator${timestamp}__$file.name")
@jeremyjarrell
jeremyjarrell / Idempotent migration in MySQL example
Created July 25, 2013 20:06
In MySQL, IF statements cannot exist outside of stored procedures. Therefore, to create an idempotent migration for MySQL it's necessary to wrap the migration in a stored procedure and execute that stored procedure against the database to perform the migration.
DELIMITER $$
DROP PROCEDURE IF EXISTS add_email_address_column_to_customers_table $$
-- Create the stored procedure to perform the migration
CREATE PROCEDURE add_email_address_column_to_customers_table()
BEGIN
-- Add the email_address column to the customers table, if it doesn't already exist