Class: Schemer::Sequel::Migrator
- Inherits:
-
Object
- Object
- Schemer::Sequel::Migrator
- Defined in:
- lib/schemer/sequel.rb
Class Method Summary collapse
-
.migration(klass) ⇒ Object
Outputs the Rails migration for the schema defined in the given class.
Class Method Details
.migration(klass) ⇒ Object
Outputs the Rails migration for the schema defined in the given class.
Outputs an empty string if no schema is defined on the class.
74 75 76 77 78 79 80 81 82 |
# File 'lib/schemer/sequel.rb', line 74 def self.migration(klass) return nil unless klass.respond_to?(:schema_columns) "create_table :#{klass.table_name} do |t|\n" + (klass.schema_columns.keys - klass::protected_columns).collect do |column| " add_column :#{column}, " + (klass.schema_columns[column].is_a?(Symbol) ? ":#{klass.schema_columns[column]}" : klass.schema_columns[column].to_s) end.join("\n") + "\nend" end |