raise "Can not revert initial migration"
end
t.string "token"
end
t.integer "initial_eta"
t.integer "resource_id"
t.string "resource_type"
t.datetime "action_started_at"
end
add_index "actions", ["resource_id", "resource_type"], :name => "index_actions_on_resource_id_and_resource_type"
t.text "iri"
end
add_index "alternative_iris", ["ontology_id", "iri"], :name => "index_alternative_iris_on_ontology_id_and_iri", :unique => true
t.text "key"
t.integer "user_id"
t.string "state"
end
t.integer "as_axiom_selection_id"
t.string "as_axiom_selection_type"
end
t.integer "sentence_id"
t.integer "axiom_selection_id"
end
add_index "axioms_axiom_selections", ["axiom_selection_id"], :name => "index_axioms_on_axiom_selection_id"
add_index "axioms_axiom_selections", ["sentence_id", "axiom_selection_id"], :name => "index_axioms_axiom_selection_unique", :unique => true
add_index "axioms_axiom_selections", ["sentence_id"], :name => "index_axioms_axiom_selections_on_sentence_id"
t.string "prover"
t.text "proof"
end
end
add_index "c_edges", ["parent_id", "child_id"], :name => "index_c_edges_on_parent_id_and_child_id", :unique => true
t.string "ordinal"
end
end
add_index "categories_ontologies", ["category_id", "ontology_id"], :name => "index_c_vertices_ontologies_on_c_vertex_id_and_ontology_id", :unique => true
add_index "categories_ontologies", ["ontology_id", "category_id"], :name => "index_c_vertices_ontologies_on_ontology_id_and_c_vertex_id"
t.integer "begin_line"
t.integer "end_line"
t.integer "begin_column"
t.integer "end_column"
t.integer "referencee_id"
t.string "referencee_type"
end
end
add_index "comments", ["commentable_id", "commentable_type", "id"], :name => "index_comments_on_commentable_and_id"
t.text "committer"
t.text "author"
t.datetime "author_date"
t.datetime "commit_date"
end
add_index "commits", ["repository_id", "commit_oid"], :name => "index_commits_on_repository_id_and_commit_oid", :unique => true
add_index "commits", ["repository_id", "id"], :name => "index_commits_on_repository_id_and_id", :unique => true
t.integer "parent_id"
t.integer "child_id"
end
end
add_index "file_extension_mime_type_mappings", ["mime_type"], :name => "index_file_extension_mime_type_mappings_on_mime_type"
t.text "name"
t.text "description"
end
end
t.integer "sentence_id"
t.integer "proof_attempt_configuration_id"
end
add_index "goals_proof_attempt_configurations", ["proof_attempt_configuration_id"], :name => "index_goals_pacs_on_proof_attempt_configuration_id"
add_index "goals_proof_attempt_configurations", ["sentence_id"], :name => "index_goals_proof_attempt_configurations_on_sentence_id"
t.string "name"
t.text "version"
end
end
t.text "iri"
t.string "kind"
end
add_index "language_adjoints", ["projection_id"], :name => "index_language_adjoints_on_projection_id"
add_index "language_adjoints", ["translation_id"], :name => "index_language_adjoints_on_translation_id"
t.text "iri"
t.string "kind"
t.string "standardization_status"
t.string "defined_by"
end
t.text "description"
t.string "standardization_status"
t.string "defined_by"
end
t.text "name"
t.text "description"
t.text "url"
end
t.integer "license_model_id"
t.integer "ontology_id"
end
t.text "iri"
t.string "kind"
end
t.text "iri"
t.string "kind"
t.string "standardization_status"
t.string "defined_by"
t.boolean "default"
t.boolean "projection"
t.string "faithfulness"
t.string "slug"
end
t.text "description"
t.string "standardization_status"
t.string "defined_by"
t.integer "user_id"
t.string "slug"
end
end
t.integer "source_id"
t.integer "target_id"
t.integer "aux_mapping_id"
t.integer "version_number"
t.boolean "current"
end
t.integer "ontology_id"
t.integer "logic_mapping_id"
t.string "kind"
t.integer "parent_id"
t.text "name"
t.integer "mapping_version_id"
t.text "locid"
end
t.integer "metadatable_id"
t.string "metadatable_type"
t.integer "user_id"
t.text "key"
t.text "value"
end
add_index "metadata", ["metadatable_id", "metadatable_type"], :name => "index_metadata_on_metadatable_id_and_metadatable_type"
t.integer "parent_id"
t.integer "language_id"
t.integer "logic_id"
t.integer "ontology_version_id"
t.text "name"
t.text "description"
t.integer "ontology_type_id"
t.string "acronym"
t.text "documentation"
t.integer "tool_id"
t.integer "license_model_id"
t.integer "formality_level_id"
t.text "locid"
end
add_index "ontologies", ["repository_id", "basepath"], :name => "index_ontologies_on_repository_id_and_basepath"
add_index "ontologies", ["repository_id", "id"], :name => "index_ontologies_on_repository_id_and_id", :unique => true
t.integer "ontology_id"
t.integer "project_id"
end
end
add_index "ontologies_tasks", ["ontology_id", "task_id"], :name => "index_ontologies_tasks_on_ontology_id_and_task_id", :unique => true
end
end
t.integer "user_id"
t.integer "previous_version_id"
t.text "last_error"
t.string "checksum"
t.datetime "state_updated_at"
t.string "basepath"
t.integer "parent_id"
t.integer "commit_id"
end
add_index "ontology_versions", ["ontology_id", "number"], :name => "index_ontology_versions_on_ontology_id_and_number"
add_index "ontology_versions", ["previous_version_id"], :name => "index_ontology_versions_on_previous_version_id"
end
t.text "last_error"
t.datetime "state_updated_at"
end
add_index "oops_requests", ["ontology_version_id"], :name => "index_oops_requests_on_ontology_version_id"
t.text "description"
end
end
add_index "oops_responses_symbols", ["oops_response_id", "symbol_id"], :name => "index_oops_responses_symbols_on_oops_response_id_and_symbol_id", :unique => true
t.integer "creator_id"
end
add_index "permissions", ["item_id", "item_type", "subject_id", "subject_type"], :name => "index_permissions_on_item_and_subject", :unique => true
add_index "permissions", ["subject_id", "subject_type"], :name => "index_permissions_on_subject_id_and_subject_type"
end
t.integer "timeout"
t.integer "prover_id"
t.integer "logic_mapping_id"
end
t.string "proof_status_id"
t.integer "time_taken"
t.integer "prover_id"
t.datetime "state_updated_at"
t.text "last_error"
t.integer "proof_attempt_configuration_id"
t.text "locid"
end
t.string "identifier"
t.string "name"
t.text "description"
t.boolean "solved"
t.text "locid"
end
t.text "content"
t.text "locid"
end
end
t.text "description"
t.text "source_address"
t.text "last_error"
t.datetime "imported_at"
t.datetime "state_updated_at"
t.string "remote_type"
t.string "destroy_job_id"
t.datetime "destroy_job_at"
end
t.string "kind"
t.text "uri"
end
t.integer "ontology_id"
t.text "text"
end
t.string "range"
t.text "display_text"
t.string "type"
t.string "proof_status_id"
t.text "locid"
t.string "state"
t.datetime "state_updated_at"
t.text "last_error"
end
add_index "sentences", ["ontology_id", "id"], :name => "index_sentences_on_ontology_id_and_id", :unique => true
add_index "sentences", ["ontology_id", "name"], :name => "index_sentences_on_ontology_id_and_name", :unique => true
end
add_index "sentences_symbols", ["sentence_id", "symbol_id"], :name => "index_sentences_symbols_on_sentence_id_and_symbol_id", :unique => true
add_index "sentences_symbols", ["symbol_id", "sentence_id"], :name => "index_sentences_symbols_on_symbol_id_and_sentence_id"
t.text "name"
t.string "extension"
t.string "mimetype"
end
end
add_index "structured_proof_parts", ["mapping_version_id"], :name => "index_structured_proof_parts_on_mapping_version_id"
add_index "structured_proof_parts", ["sentence_id"], :name => "index_structured_proof_parts_on_sentence_id"
add_index "structured_proof_parts", ["structured_proof_id"], :name => "index_structured_proof_parts_on_structured_proof_id"
t.string "rule"
end
t.boolean "exact"
end
add_index "supports", ["language_id", "logic_id"], :name => "index_supports_on_language_id_and_logic_id", :unique => true
t.integer "ontology_id"
end
add_index "symbol_groups", ["ontology_id", "id"], :name => "index_symbol_groups_on_ontology_id_and_id", :unique => true
t.integer "confidence"
t.string "kind"
end
t.string "kind"
t.text "iri"
t.string "range"
t.text "display_name"
t.text "label"
t.text "comment"
t.integer "symbol_group_id"
t.text "locid"
end
add_index "symbols", ["ontology_id", "id"], :name => "index_symbols_on_ontology_id_and_id", :unique => true
add_index "symbols", ["ontology_id", "text"], :name => "index_symbols_on_ontology_id_and_text", :unique => true
end
t.integer "time_limit"
end
t.text "description"
end
t.integer "creator_id"
end
add_index "team_users", ["team_id", "user_id"], :name => "index_team_users_on_team_id_and_user_id", :unique => true
end
t.text "description"
t.text "url"
end
t.integer "audience_id"
t.integer "ontology_id"
t.integer "sentence_id"
t.integer "symbol_mapping_id"
end
add_index "translated_sentences", ["audience_id"], :name => "index_translated_sentences_on_audience_id"
add_index "translated_sentences", ["ontology_id"], :name => "index_translated_sentences_on_ontology_id"
end
add_index "url_maps", ["repository_id", "source"], :name => "index_url_maps_on_repository_id_and_source", :unique => true
t.integer "sentence_id"
t.integer "proof_attempt_id"
end
add_index "used_axioms_proof_attempts", ["proof_attempt_id"], :name => "index_used_axioms_proof_attempts_on_proof_attempt_id"
add_index "used_axioms_proof_attempts", ["sentence_id"], :name => "index_used_axioms_proof_attempts_on_sentence_id"
end
t.string "email"
t.string "encrypted_password"
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.string "unlock_token"
t.datetime "locked_at"
t.text "name"
t.datetime "deleted_at"
end
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
add_foreign_key "basic_proofs", "logic_mappings", name: "basic_proofs_logic_mapping_id_fk", dependent: :delete
add_foreign_key "basic_proofs", "sentences", name: "basic_proofs_sentence_id_fk", dependent: :delete
add_foreign_key "categories_ontologies", "categories", name: "c_vertices_ontologies_c_vertex_id_fk", dependent: :delete
add_foreign_key "categories_ontologies", "ontologies", name: "c_vertices_ontologies_ontology_id_fk", dependent: :delete
add_foreign_key "language_adjoints", "language_mappings", name: "language_adjoints_projection_id_fk", column: "projection_id", dependent: :delete
add_foreign_key "language_adjoints", "language_mappings", name: "language_adjoints_translation_id_fk", column: "translation_id", dependent: :delete
add_foreign_key "language_mappings", "languages", name: "language_mappings_source_id_fk", column: "source_id", dependent: :delete
add_foreign_key "language_mappings", "languages", name: "language_mappings_target_id_fk", column: "target_id", dependent: :delete
add_foreign_key "logic_adjoints", "logic_mappings", name: "logic_adjoints_projection_id_fk", column: "projection_id", dependent: :delete
add_foreign_key "logic_adjoints", "logic_mappings", name: "logic_adjoints_translation_id_fk", column: "translation_id", dependent: :delete
add_foreign_key "logic_mappings", "logics", name: "logic_mappings_source_id_fk", column: "source_id", dependent: :delete
add_foreign_key "logic_mappings", "logics", name: "logic_mappings_target_id_fk", column: "target_id", dependent: :delete
add_foreign_key "mapping_versions", "mappings", name: "mapping_versions_mapping_id_fk", dependent: :delete
add_foreign_key "mapping_versions", "ontology_versions", name: "mapping_versions_source_id_fk", column: "source_id", dependent: :delete
add_foreign_key "mapping_versions", "ontology_versions", name: "mapping_versions_target_id_fk", column: "target_id", dependent: :delete
add_foreign_key "ontology_versions", "ontologies", name: "ontology_versions_ontology_id_fk", dependent: :delete
add_foreign_key "ontology_versions", "ontology_versions", name: "ontology_versions_parent_id_fk", column: "parent_id"
add_foreign_key "ontology_versions", "ontology_versions", name: "ontology_versions_previous_version_id_fk", column: "previous_version_id"
add_foreign_key "oops_requests", "ontology_versions", name: "oops_requests_ontology_version_id_fk", dependent: :delete
add_foreign_key "oops_responses", "oops_requests", name: "oops_responses_oops_request_id_fk", dependent: :delete
add_foreign_key "oops_responses_symbols", "oops_responses", name: "oops_responses_symbols_oops_response_id_fk", dependent: :delete
add_foreign_key "permissions", "users", name: "permissions_creator_id_fk", column: "creator_id", dependent: :nullify
add_foreign_key "sentences_symbols", "ontologies", name: "sentences_symbols_ontology_id_fk", dependent: :delete
add_foreign_key "sentences_symbols", "sentences", name: "sentences_symbols_sentence_id_fk", dependent: :delete
add_foreign_key "sentences_symbols", "symbols", name: "sentences_symbols_symbol_id_fk", dependent: :delete
add_foreign_key "structured_proof_parts", "mapping_versions", name: "structured_proof_parts_mapping_version_id_fk", dependent: :delete
add_foreign_key "structured_proof_parts", "sentences", name: "structured_proof_parts_sentence_id_fk", dependent: :delete
add_foreign_key "structured_proof_parts", "structured_proofs", name: "structured_proof_parts_structured_proof_id_fk", dependent: :delete
add_foreign_key "symbol_groups", "ontologies", name: "symbol_groups_ontology_id_fk", dependent: :delete
add_foreign_key "symbol_mappings", "symbols", name: "symbol_mappings_source_id_fk", column: "source_id", dependent: :delete
add_foreign_key "symbol_mappings", "symbols", name: "symbol_mappings_target_id_fk", column: "target_id", dependent: :delete
add_foreign_key "team_users", "users", name: "team_users_creator_id_fk", column: "creator_id", dependent: :nullify
add_foreign_key "used_sentences", "basic_proofs", name: "used_sentences_basic_proof_id_fk", dependent: :delete
add_foreign_key "used_sentences", "sentences", name: "used_sentences_sentence_id_fk", dependent: :delete
end
execute <<-SQL
CREATE OR REPLACE FUNCTION fetch_distributed_graph_data(
distributed_id integer)
RETURNS SETOF integer AS $$
BEGIN
RETURN QUERY WITH "graph_core" AS (
SELECT "mappings"."id",
"mappings"."target_id",
"mappings"."source_id"
FROM "mappings"
WHERE "mappings"."ontology_id" = distributed_id),
"graph_data" AS (
SELECT ("graph_core"."source_id") AS node_id,
("graph_core"."id") AS edge_id
FROM graph_core
UNION
SELECT ("graph_core"."target_id") AS node_id,
("graph_core"."id") AS edge_id
FROM graph_core)
SELECT DISTINCT "graph_data"."node_id"
FROM "graph_data";
END;
$$ language plpgsql;
SQL
end
def add_function_fetch_graph_data
$function_declaration = "fetch_graph_data(center_id integer, source_tbl regclass, target_tbl regclass, depth integer)"
execute <<-SQL
CREATE TYPE graph_data_type AS (
node_id integer,
edge_id integer,
depth integer
);
CREATE OR REPLACE FUNCTION #{$function_declaration}
RETURNS SETOF graph_data_type AS $$
BEGIN
RETURN QUERY EXECUTE format('
WITH RECURSIVE graph_data(node_id, edge_id, depth) AS (
(WITH mergeable AS (
SELECT (%s."source_id") AS source_id,
(%s."target_id") AS target_id,
(%s."id") AS edge_id,
1 AS depth
FROM %s
WHERE (%s."source_id" = %s OR
%s."target_id" = %s)
)
SELECT (source_id) AS node_id, edge_id, depth FROM mergeable
UNION
SELECT (target_id) AS node_id, edge_id, depth FROM mergeable
)
UNION ALL
(WITH mergeable AS (
SELECT (%s."source_id") AS source_id,
(%s."target_id") AS target_id,
(%s."id") AS edge_id,
(graph_data.depth+1) AS depth
FROM %s
INNER JOIN graph_data
ON (%s."source_id" = "graph_data"."node_id" OR
%s."target_id" = "graph_data"."node_id")
WHERE graph_data.depth < %s)
SELECT (source_id) AS node_id, edge_id, depth FROM mergeable
UNION
SELECT (target_id) AS node_id, edge_id, depth FROM mergeable
)
)
SELECT DISTINCT * from graph_data;
', source_tbl, source_tbl, source_tbl,
source_tbl, source_tbl, center_id,
source_tbl, center_id,
source_tbl, source_tbl, source_tbl,
source_tbl, source_tbl, source_tbl,
depth);
END;
$$ language plpgsql;
SQL
end
def add_check_logic_id
execute <<-SQL
ALTER TABLE ontologies
ADD CONSTRAINT logic_id_check CHECK (state != 'done' OR logic_id IS NOT NULL OR type = 'DistributedOntology')
SQL
end
def populate_database_with_ontology_file_extensions
file_extensions_distributed = %w[casl dol hascasl het]
file_extensions_single = %w[owl omn obo hs exp maude elf hol isa thy prf omdoc hpf clf clif xml fcstd rdf xmi qvt tptp gen_trm baf]
file_extensions_distributed.map! { |e| ".#{e}" }
file_extensions_single.map! { |e| ".#{e}" }
file_extensions_distributed.each do |ext|
ActiveRecord::Base.connection.execute(
"INSERT INTO ontology_file_extensions (extension, distributed) VALUES ('#{ext}', 'true')")
end
file_extensions_single.each do |ext|
ActiveRecord::Base.connection.execute(
"INSERT INTO ontology_file_extensions (extension, distributed) VALUES ('#{ext}', 'false')")
end
end
def populate_database_with_file_extension_mime_type_mappings
mappings = [
%w(.clif text/clif),
%w(.owl application/owl),
%w(.owl text/obo),
%w(.ttl text/turtle),
%w(.owx application/owl+xml),
%w(.casl text/casl),
%w(.dol text/dol),
%w(.het text/het),
]
mappings.each do |(file_extension, mime_type)|
FileExtensionMimeTypeMapping.
where(file_extension: file_extension, mime_type: mime_type).
first_or_create!
end
end
end