# encoding: utf-8
class CreateEol < ActiveRecord::Migration

  def self.up
    ActiveRecord::Migration.raise_error_if_in_production
    
    # Basically, I want to throw an error if we're not using MySQL, while at the same time providing the framework
    # for adding other DB support in the future...
    if ActiveRecord::Base.connection.class == ActiveRecord::ConnectionAdapters::Mysql2Adapter ||
        ActiveRecord::Base.connection.class == Octopus::Proxy  # could be using ActiveReload (Masochism) as we are now in testing
      # I was having trouble running the whole thing at once, so I'll break it up by command:
      # Note that this assumes that the file has been DOS-ified.
      IO.read(Rails.root.join('db', "eol.sql")).to_s.split(/;\s*[\r\n]+/).each do |cmd|
        next if cmd =~ /^\/\*!40101 SET/
        if cmd =~ /\w/m # Only run commands with text in them.  :)  A few were "\n\n".
          execute cmd.strip
        end
      end
    else
      raise ActiveRecord::IrreversibleMigration.new("Migration error: Unsupported database for initial schema--this was not written portably.")
    end
  end

  def self.down
    ActiveRecord::Migration.raise_error_if_in_production
    drop_table "agent_roles"
    drop_table "agents"
    drop_table "agents_data_objects"
    drop_table "agents_hierarchy_entries"
    drop_table "agents_synonyms"
    drop_table "audiences"
    drop_table "audiences_data_objects"
    drop_table "canonical_forms"
    drop_table "changeable_object_types"
    drop_table "collection_items"
    drop_table "collection_types"
    drop_table "collection_types_collections"
    drop_table "collection_types_hierarchies"
    drop_table "collections"
    drop_table "collections_communities"
    drop_table "collections_users"
    drop_table "comments"
    drop_table "communities"
    drop_table "contact_roles"
    drop_table "contact_subjects"
    drop_table "contacts"
    drop_table "content_page_archives"
    drop_table "content_pages"
    drop_table "content_partner_agreements"
    drop_table "content_partner_contacts"
    drop_table "content_partner_statuses"
    drop_table "content_partners"
    drop_table "content_table_items"
    drop_table "content_tables"
    drop_table "content_uploads"
    drop_table "curated_data_objects_hierarchy_entries"
    drop_table "curated_hierarchy_entry_relationships"
    drop_table "curator_activity_logs_untrust_reasons"
    drop_table "curator_levels"
    drop_table "data_object_data_object_tags"
    drop_table "data_object_tags"
    drop_table "data_object_translations"
    drop_table "data_objects"
    drop_table "data_objects_harvest_events"
    drop_table "data_objects_hierarchy_entries"
    drop_table "data_objects_info_items"
    drop_table "data_objects_refs"
    drop_table "data_objects_table_of_contents"
    drop_table "data_objects_taxon_concepts"
    drop_table "data_types"
    drop_table "error_logs"
    drop_table "feed_data_objects"
    drop_table "feed_item_types"
    drop_table "feed_items"
    drop_table "glossary_terms"
    drop_table "google_analytics_page_stats"
    drop_table "google_analytics_partner_summaries"
    drop_table "google_analytics_partner_taxa"
    drop_table "google_analytics_summaries"
    drop_table "harvest_events"
    drop_table "harvest_events_hierarchy_entries"
    drop_table "harvest_process_logs"
    drop_table "hierarchies"
    drop_table "hierarchies_content"
    drop_table "hierarchy_entries"
    drop_table "hierarchy_entries_flattened"
    drop_table "hierarchy_entries_refs"
    drop_table "hierarchy_entry_relationships"
    drop_table "hierarchy_entry_stats"
    drop_table "info_items"
    drop_table "item_pages"
    drop_table "languages"
    drop_table "licenses"
    drop_table "members"
    drop_table "mime_types"
    drop_table "name_languages"
    drop_table "names"
    drop_table "news_items"
    drop_table "open_id_authentication_associations"
    drop_table "open_id_authentication_nonces"
    drop_table "page_names"
    drop_table "page_stats_dataobjects"
    drop_table "page_stats_marine"
    drop_table "page_stats_taxa"
    drop_table "publication_titles"
    drop_table "random_hierarchy_images"
    drop_table "ranks"
    drop_table "ref_identifier_types"
    drop_table "ref_identifiers"
    drop_table "refs"
    drop_table "resource_statuses"
    drop_table "resources"
    drop_table "roles"
    drop_table "schema_migrations"
    drop_table "search_suggestions"
    drop_table "service_types"
    drop_table "sessions"
    drop_table "site_configuration_options"
    drop_table "sort_styles"
    drop_table "special_collections"
    drop_table "statuses"
    drop_table "survey_responses"
    drop_table "synonym_relations"
    drop_table "synonyms"
    drop_table "table_of_contents"
    drop_table "taxon_concept_content"
    drop_table "taxon_concept_exemplar_images"
    drop_table "taxon_concept_metrics"
    drop_table "taxon_concept_names"
    drop_table "taxon_concept_stats"
    drop_table "taxon_concepts"
    drop_table "taxon_concepts_flattened"
    drop_table "title_items"
    drop_table "top_concept_images"
    drop_table "top_images"
    drop_table "top_species_images"
    drop_table "top_unpublished_concept_images"
    drop_table "top_unpublished_images"
    drop_table "top_unpublished_species_images"
    drop_table "translated_agent_roles"
    drop_table "translated_audiences"
    drop_table "translated_collection_types"
    drop_table "translated_contact_roles"
    drop_table "translated_contact_subjects"
    drop_table "translated_content_page_archives"
    drop_table "translated_content_pages"
    drop_table "translated_content_partner_statuses"
    drop_table "translated_content_tables"
    drop_table "translated_data_types"
    drop_table "translated_info_items"
    drop_table "translated_languages"
    drop_table "translated_licenses"
    drop_table "translated_mime_types"
    drop_table "translated_news_items"
    drop_table "translated_ranks"
    drop_table "translated_resource_statuses"
    drop_table "translated_service_types"
    drop_table "translated_sort_styles"
    drop_table "translated_statuses"
    drop_table "translated_synonym_relations"
    drop_table "translated_table_of_contents"
    drop_table "translated_untrust_reasons"
    drop_table "translated_user_identities"
    drop_table "translated_vetted"
    drop_table "translated_view_styles"
    drop_table "translated_visibilities"
    drop_table "unique_visitors"
    drop_table "untrust_reasons"
    drop_table "user_identities"
    drop_table "user_infos"
    drop_table "user_primary_roles"
    drop_table "users"
    drop_table "users_data_objects"
    drop_table "users_data_objects_ratings"
    drop_table "users_user_identities"
    drop_table "vetted"
    drop_table "view_styles"
    drop_table "visibilities"
    drop_table "whats_this"
    drop_table "wikipedia_queue"
    drop_table "worklist_ignored_data_objects"
  end
end
