Skip to content

Instantly share code, notes, and snippets.

@bscofield
Created June 15, 2010 10:45
Show Gist options
  • Save bscofield/438966 to your computer and use it in GitHub Desktop.
Save bscofield/438966 to your computer and use it in GitHub Desktop.
class MigrationManifest
@@manifest = []
def self.table(name, options = {}, &block)
@@manifest << [:table, name, options, block]
end
def self.column(table, name, data_type, options = {})
@@manifest << [:column, table, name, data_type, options]
end
def self.index(table, name, options = {})
@@manifest << [:index, table, name, options]
end
def self.irreversible
@irreversible = true
end
def self.up
@@manifest.each do |step|
p step
end
end
def self.down
raise 'Irreversible migration' if @irreversible
@@manifest.reverse.each do |step|
p step
end
end
end
class CreatePeople < MigrationManifest
irreversible
table :people do |t|
t.string :name
end
column :people, :email, :string
index :people, :email
end
CreatePeople.up
CreatePeople.down
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment