# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require 'active_record' module RTM module AR module TMDM class Topic < ActiveRecord::Base;end class ItemIdentifier < ActiveRecord::Base belongs_to :topic_map_construct end class SubjectIdentifier < ActiveRecord::Base belongs_to :topic end class SubjectLocator < ActiveRecord::Base belongs_to :topic end class QuaaxTM2RTMViews < ActiveRecord::Migration def self.up create_view "topic_maps", "select id, baselocator from qtm_topicmap" do |t| t.column :id t.column :base_locator end create_view "topics", "select id, topicmap_id, null, null from qtm_topic" do |t| t.column :id t.column :topic_map_id t.column :reified_id t.column :reified_type end create_view "associations", "select id, topicmap_id, type_id from qtm_association" do |t| t.column :id t.column :topic_map_id t.column :ttype_id end create_view "association_roles", "select id, association_id, type_id, reference from qtm_assocrole" do |t| t.column :id t.column :association_id t.column :ttype_id t.column :topic_id end create_view "topic_names", "select id, topic_id, type_id, value from qtm_topicname" do |t| t.column :id t.column :topic_id t.column :ttype_id t.column :value end create_view "occurrence", "select id, topic_id, type_id, value, datatype from qtm_occurrence" do |t| t.column :id t.column :topic_id t.column :ttype_id t.column :value t.column :datatype end create_view "variants", "select id, topicname_id, value, datatype from qtm_variant" do |t| t.column :id t.column :topic_name_id t.column :value t.column :datatype end rename_table "qtm_topicmapconstructref", "item_identifiers" rename_column "item_identifiers", "locator", "reference" add_column :item_identifiers, :topic_map_id, :integer ItemIdentifier.reset_column_information ItemIdentifier.find(:all).each do |si| si.update_attribute :topic_map_id, si.topic_map_construct.topic_map_id end create_table :item_identifiers do |t| t.column :topic_map_id, :integer, :null => false t.column :reference, :string, :null => false t.column :topic_map_construct_id, :integer t.column :topic_map_construct_type, :string end SubjectIdentifier.reset_column_information SubjectIdentifier.find(:all).each do |si| si.update_attribute :topic_map_id, si.topic.topic_map_id end rename_table "qtm_subjectidentifier", "subject_identifiers" rename_column :subject_identifiers, "locator", "reference" add_column :subject_identifiers, :topic_map_id, :integer SubjectIdentifier.reset_column_information SubjectIdentifier.find(:all).each do |si| si.update_attribute :topic_map_id, si.topic.topic_map_id end rename_table "qtm_subjectlocator", "subject_locators" rename_column :subject_locators, "locator", "reference" add_column :subject_locators, :topic_map_id, :integer Topic.reset_column_information SubjectLocator.reset_column_information SubjectLocator.find(:all).each do |si| si.update_attribute :topic_map_id, si.topic.topic_map_id end create_table :scoped_objects_topics do |t| t.column :scoped_object_id, :integer t.column :scoped_object_type, :string t.column :topic_id, :integer end # TODO: instance of # scope # reifier end def self.down raise "not supported" end end end end end #if __FILE__ == $0 # puts "Generating SQLite3 Databse tmdm.sqlite3." # ActiveRecord::Base.establish_connection( # :adapter => "sqlite3", # :database => "tmdm.sqlite3" # ) # RTM::AR::TMDM::QuaaxTM2RTM.migrate(:up) #end