Skip to content

Instantly share code, notes, and snippets.

Jeremy Jarrell jeremyjarrell

View GitHub Profile
@jeremyjarrell
jeremyjarrell / Idempotent migration in MySQL example
Created Jul 25, 2013
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.
View Idempotent migration in MySQL example
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
@jeremyjarrell
jeremyjarrell / Prefix migrations with timestamp Groovy task
Created Jul 25, 2013
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
View Prefix migrations with timestamp Groovy task
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 / Prefix migrations with timestamp Ant task
Last active May 15, 2017
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
View Prefix migrations with timestamp Ant task
<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 / compare_production_to_qa.rb
Created Mar 16, 2012
Compares the production to qa branches for differences
View compare_production_to_qa.rb
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
You can’t perform that action at this time.