Commit 484f4deeeca9ad8e1da9180d221dff4c39da95dc

Authored by Arthur Esposte
1 parent 37bcb7c7
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Remake create_siorg_institutions migration

db/migrate/20150910121056_create_siorg_institutions.rb
... ... @@ -1,70 +0,0 @@
1   -#encoding: utf-8
2   -require "i18n"
3   -
4   -class CreateSiorgInstitutions < ActiveRecord::Migration
5   - def up
6   - governmental_power = GovernmentalPower.where("name ILIKE ?", "Executivo").first
7   - governmental_sphere = GovernmentalSphere.where("name ILIKE ?", "Federal").first
8   - env = Environment.default
9   -
10   - if env && governmental_power && governmental_sphere
11   - CSV.foreach("plugins/spb_migrations/files/orgaos_siorg.csv", :headers => true) do |row|
12   - template = Community["institution"]
13   -
14   - community = Community.where("identifier ILIKE ?", row["Nome"].to_slug).first
15   - unless community
16   - institution = Institution.where("acronym ILIKE ?", row["Sigla"]).first
17   - community = institution.community if institution
18   - end
19   -
20   - community = Community.new unless community
21   -
22   - community.environment = env if community.environment.blank?
23   - community.name = row["Nome"].rstrip
24   - community.country = row["Pais"]
25   - community.state = row["Estado"]
26   - community.city = row["Cidade"]
27   - community.template = template if template
28   -
29   - community.save!
30   -
31   - juridical_nature = JuridicalNature.where("name ILIKE ? OR name ILIKE ?", "#{I18n.transliterate(row['Natureza Jurídica'].rstrip)}", "#{row['Natureza Jurídica'].rstrip}").first
32   -
33   - juridical_nature = JuridicalNature.create!(name: row['Natureza Jurídica'].rstrip) unless juridical_nature
34   -
35   -
36   - institution = Hash.new
37   -
38   - institution[:name] = row["Nome"]
39   - institution[:siorg_code] = row["Código do SIORG"]
40   - institution[:acronym] = row["Sigla"]
41   - institution[:governmental_sphere] = governmental_sphere
42   - institution[:governmental_power] = governmental_power
43   - institution[:juridical_nature] = juridical_nature
44   - institution[:sisp] = (row["SISP"] == "Sim")
45   - institution[:cnpj] = row["CNPJ"]
46   - institution[:community] = community
47   -
48   - if community.institution
49   - community.institution.update_attributes(institution)
50   - else
51   - institution[:community] = community
52   - community.institution = PublicInstitution.create!(institution)
53   - end
54   -
55   - if community.save
56   - print "."
57   - else
58   - print "F"
59   - end
60   -
61   - end
62   - end
63   - puts ""
64   - end
65   -
66   - def down
67   - say "This can't be reverted"
68   - end
69   -
70   -end
db/migrate/20151002180659_create_siorg_institutions.rb 0 → 100644
... ... @@ -0,0 +1,73 @@
  1 +#encoding: utf-8
  2 +require "i18n"
  3 +
  4 +class CreateSiorgInstitutions < ActiveRecord::Migration
  5 + def up
  6 + governmental_power = GovernmentalPower.where("name ILIKE ?", "Executivo").first
  7 + governmental_sphere = GovernmentalSphere.where("name ILIKE ?", "Federal").first
  8 + env = Environment.default
  9 +
  10 + if env && governmental_power && governmental_sphere
  11 + CSV.foreach("plugins/spb_migrations/files/orgaos_siorg.csv", :headers => true) do |row|
  12 + template = Community["institution"]
  13 +
  14 + community = Community.where("identifier ILIKE ?", row["Nome"].to_slug).first
  15 + unless community
  16 + institution = Institution.where("acronym ILIKE ?", row["Sigla"]).first
  17 + community = institution.community if institution
  18 + end
  19 +
  20 + community = Community.new unless community
  21 +
  22 + community.environment = env if community.environment.blank?
  23 + community.name = row["Nome"].rstrip
  24 + community.country = row["Pais"]
  25 + community.state = row["Estado"]
  26 + community.city = row["Cidade"]
  27 + community.template = template if template
  28 +
  29 + unless community.save
  30 + print "F"
  31 + next
  32 + end
  33 +
  34 + juridical_nature = JuridicalNature.where("name ILIKE ? OR name ILIKE ?", "#{I18n.transliterate(row['Natureza Jurídica'].rstrip)}", "#{row['Natureza Jurídica'].rstrip}").first
  35 +
  36 + juridical_nature = JuridicalNature.create!(name: row['Natureza Jurídica'].rstrip) unless juridical_nature
  37 +
  38 +
  39 + institution = Hash.new
  40 +
  41 + institution[:name] = row["Nome"]
  42 + institution[:siorg_code] = row["Código do SIORG"]
  43 + institution[:acronym] = row["Sigla"]
  44 + institution[:governmental_sphere] = governmental_sphere
  45 + institution[:governmental_power] = governmental_power
  46 + institution[:juridical_nature] = juridical_nature
  47 + institution[:sisp] = (row["SISP"] == "Sim")
  48 + institution[:cnpj] = row["CNPJ"]
  49 + institution[:community] = community
  50 +
  51 + if community.institution
  52 + community.institution.update_attributes(institution)
  53 + else
  54 + institution[:community] = community
  55 + community.institution = PublicInstitution.create!(institution)
  56 + end
  57 +
  58 + if community.save
  59 + print "."
  60 + else
  61 + print "F"
  62 + end
  63 +
  64 + end
  65 + end
  66 + puts ""
  67 + end
  68 +
  69 + def down
  70 + say "This can't be reverted"
  71 + end
  72 +
  73 +end
... ...