Skip to content

Commit

Permalink
adiciona seeds para povoamento do banco #42
Browse files Browse the repository at this point in the history
  • Loading branch information
mmp-s committed Oct 23, 2017
1 parent 15e238d commit 392e0e9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
51 changes: 51 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,57 @@
create_table "hospitals", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "co_unidade"
t.string "co_cnes"
t.string "nu_cnpj_mantenedora"
t.string "tp_pfpj"
t.string "nivel_dep"
t.string "no_razao_social"
t.string "no_fantasia"
t.string "no_logradouro"
t.string "nu_endereco"
t.string "no_complemento"
t.string "no_bairro"
t.string "co_cep"
t.string "co_regiao_saude"
t.string "co_micro_regiao"
t.string "co_distrito_sanitario"
t.string "co_distrito_administrativo"
t.string "nu_telefone"
t.string "nu_fax"
t.string "no_email"
t.string "nu_cpf"
t.string "nu_cnpj"
t.string "co_atividade"
t.string "co_clientela"
t.string "nu_alvara"
t.datetime "dt_expedicao"
t.string "tp_orgao_expedidor"
t.datetime "dt_val_lic_sani"
t.string "tp_lic_sani"
t.string "tp_unidade"
t.string "co_turno_atendimento"
t.string "co_estado_gestor"
t.string "co_municipio_gestor"
t.string "dt_atualizacao"
t.string "co_usuario"
t.string "co_cpfdiretorcln"
t.string "reg_diretorcln"
t.string "st_adesao_filantrop"
t.string "co_motivo_desab"
t.string "no_url"
t.float "nu_latitude"
t.float "nu_longitude"
t.string "dt_atu_geo"
t.string "no_usuario_geo"
t.string "co_natureza_jur"
t.string "tp_estab_sempre_aberto"
t.string "st_geracredito_gerente_sgif"
t.string "st_conexao_internet"
t.string "co_tipo_unidade"
t.string "no_fantasia_abrev"
t.string "tp_gestao"
t.date "dt_atualizacao_origem"
end

end
13 changes: 13 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
require 'smarter_csv'
require 'database_cleaner'

DatabaseCleaner.clean_with(:truncation)

filename = '/home/mateus/periodo4/es/planilhas/_tbEstabelecimento201707.csv'
options = {:key_mapping => {:unwanted_row => nil, :old_row_name => :new_name}}
n = SmarterCSV.process(filename, options) do |array|
puts array.first
# we're passing a block in, to process each resulting hash / =row (the block takes array of hashes)
# when chunking is not enabled, there is only one hash in each array
Hospital.create( array.first )
end

0 comments on commit 392e0e9

Please sign in to comment.