Sha256: bcea030c66ec0c0871dc480c40a51ffeb9201839bb91f673e8fa836a6e1dfa2b

Contents?: true

Size: 877 Bytes

Versions: 3

Compression:

Stored size: 877 Bytes

Contents

module DataMapper
  module AutoMigrations
    def auto_migrate!
      if self::subclasses.empty?
        table = database.table(self)
        table.activate_associations!
        
        table.create!(true)
      else
        schema = database.schema
        columns = self::subclasses.inject(schema[self].columns) do |span, subclass|
          span + schema[subclass].columns
        end

        table_name = schema[self].name.to_s
        table = schema[table_name]
        columns.each do |column|
          table.add_column(column.name, column.type, column.options)
        end
        
        table.activate_associations!
        
        return table.create!(true)
      end
    end
    
    private
    def create_table(table)
      raise NotImplementedError.new
    end
    
    def modify_table(table, columns)
      raise NotImplementedError.new
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
datamapper-0.3.0 lib/data_mapper/auto_migrations.rb
datamapper-0.3.1 lib/data_mapper/auto_migrations.rb
datamapper-0.3.2 lib/data_mapper/auto_migrations.rb