Created
June 15, 2010 10:45
-
-
Save bscofield/438966 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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