Sha256: 522edbbd563adb3d8c9f5cde1dff8138e562f10efc7757e3dc95616a9c9ab10c

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

namespace :fields do

  require 'csv'

  desc "Dump fields information in CSV"
  task :csv=>:environment do
    fn = Rails.root.join('tmp','fields.csv')
    if CSV.constants.map(&:to_sym).include?(:VERSION)
      options = [{
              :headers=>true,
              :col_sep=>';'
            }]
    else
      options = [';']
    end
    CSV.open(fn, 'w', *options) do |csv|
        csv << %w{table column pk assoc foreign sql_type type attributes extra comments}
        ModalFields.report(
          :primary_keys=>true, :foreing_keys=>true,
          :undeclared_fields=>true) do |kind, table, name, data|
            row_data = [table, name, kind==:primary_key]
            if kind==:foreign_key
              row_data << data[:foreign_name] << data[:foreign_table].to_s
            else
              row_data << '' << ''
            end
            attrs = data.except(:sql_type, :type, :extra, :comments).to_json
            extra = data[:extra]
            row_data << data[:sql_type] << data[:type] << attrs << data[:extra] << data[:comments]
            csv << row_data
        end
    end
    puts "Data written to #{fn}"
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
modalfields-1.4.5 lib/tasks/csv.rake
modalfields-1.4.4 lib/tasks/csv.rake
modalfields-1.4.3 lib/tasks/csv.rake
modalfields-1.4.2 lib/tasks/csv.rake
modalfields-1.4.1 lib/tasks/csv.rake
modalfields-1.4.0 lib/tasks/csv.rake