diff --git a/config/orientdb.yml b/config/orientdb.yml index 07945002eacbdb755ce3058bf6ff217959fc76e8..7c25a5c84c4c90bca4a1b078509cc12039527486 100644 --- a/config/orientdb.yml +++ b/config/orientdb.yml @@ -1,6 +1,6 @@ development: &development host: localhost - database: PortalMEC + database: Teste2 username: admin password: admin port: 2480 diff --git a/lib/orient_db/migration.rb b/lib/orient_db/migration.rb index e086f8941c82f6cec7f651269a9c093a95a51fc2..0d282d3183fd08b1481242d98b2bfd519a85d60f 100644 --- a/lib/orient_db/migration.rb +++ b/lib/orient_db/migration.rb @@ -19,14 +19,35 @@ module OrientDb # If +klass+ exists in current schema, nothing happens. # # A block can be passed with the created +klass+ object - def create_class(klass) + def create_class(klass, extends) unless @client.class_exists? klass - @client.create_class(klass) do |c| + @client.create_class(klass, :extends => extends) do |c| if block_given? yield c end end end end + + def drop_class(klass) + if @client.class_exists? klass + @client.drop_class(klass, :mode => :strict) + end + end + + def add_index(klass, property, type, engine=nil, metadata=nil) + engine = engine.nil? ? "" : " ENGINE #{engine}" + metadata = metadata.nil? ? "" : " METADATA #{metadata.to_s}" + begin + @client.command "CREATE INDEX #{klass}.#{property} ON #{klass} (#{property}) #{type}#{engine}#{metadata}" + rescue Orientdb4r::ServerError => e + # If the index already exists OrientDB will give an error containing this message + unless e.message.include? "Index with name #{klass.downcase}.#{property.downcase}" + puts "Error at index creation" + p e.message + p.backtrace + end + end + end end end \ No newline at end of file diff --git a/lib/orient_db/migrations.rb b/lib/orient_db/migrations.rb index 4efced72171aeaeb511e8d02fc93c2ce14e79b5a..debed17e525595a78fd72f9bf8c427b8ea0e63e0 100644 --- a/lib/orient_db/migrations.rb +++ b/lib/orient_db/migrations.rb @@ -5,11 +5,27 @@ class OrientDb::Migrations def initialize(client) @migrations = [] - @migrations << CreateCountry.new(client) - @migrations << CreateHighlight.new(client) - @migrations << CreateUniversity.new(client) + # Vertices @migrations << CreateUser.new(client) - @migrations << CreateMainpage.new(client) + @migrations << CreateAttribute.new(client) + @migrations << CreateComment.new(client) + @migrations << CreateObject.new(client) + # Vertices inheriting from Object + @migrations << CreateInstitution.new(client) + @migrations << CreateLearningObject.new(client) + # Vertices inheriting from LearningObject + @migrations << CreateCollection.new(client) + @migrations << CreateSubject.new(client) + @migrations << CreateMainPage.new(client) + + # Edges + @migrations << CreateIsAbout.new(client) + @migrations << CreatePublishedBy.new(client) + @migrations << CreateBelongsTo.new(client) + @migrations << CreateLike.new(client) + @migrations << CreateHasAttr.new(client) + @migrations << CreateComments.new(client) + @migrations << CreateCommentedBy.new(client) end ## @@ -17,4 +33,8 @@ class OrientDb::Migrations def run @migrations.each { |m| m.up } end + + def drop + @migrations.reverse_each { |m| m.down } + end end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_attribute.rb b/lib/orient_db/migrations/create_attribute.rb new file mode 100644 index 0000000000000000000000000000000000000000..db0de64764326513ede16021446a9368fe9fb9c0 --- /dev/null +++ b/lib/orient_db/migrations/create_attribute.rb @@ -0,0 +1,16 @@ +class OrientDb::Migrations::CreateAttribute < OrientDb::Migration + + def up + create_class 'Attribute', 'V' do |c| + c.property 'key', :string + c.property 'value', :string + end + add_index 'Attribute', 'key', "NOTUNIQUE_HASH_INDEX" + metadata = {:analyzer => "org.apache.lucene.analysis.br.BrazilianAnalyzer"} + add_index 'Attribute', 'value', "FULLTEXT", "LUCENE", metadata.to_json + end + + def down + drop_class 'Attribute' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_belongs_to.rb b/lib/orient_db/migrations/create_belongs_to.rb new file mode 100644 index 0000000000000000000000000000000000000000..6ceff5b036fdb3b222662a51fa8b1eed41f70302 --- /dev/null +++ b/lib/orient_db/migrations/create_belongs_to.rb @@ -0,0 +1,10 @@ +class OrientDb::Migrations::CreateBelongsTo < OrientDb::Migration + + def up + create_class 'BelongsTo', 'E' + end + + def down + drop_class 'BelongsTo' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_collection.rb b/lib/orient_db/migrations/create_collection.rb new file mode 100644 index 0000000000000000000000000000000000000000..20347685cc69cf00f0fa1ddecb18982f62b1e715 --- /dev/null +++ b/lib/orient_db/migrations/create_collection.rb @@ -0,0 +1,13 @@ +class OrientDb::Migrations::CreateCollection < OrientDb::Migration + + def up + create_class 'Collection', 'Object' do |c| + c.property 'privacy', :string + c.link 'learning_objects', :linkset, 'LearningObject' + end + end + + def down + drop_class 'Collection' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_comment.rb b/lib/orient_db/migrations/create_comment.rb new file mode 100644 index 0000000000000000000000000000000000000000..a53be2dd639dabe776397f5abaf528a3f635d588 --- /dev/null +++ b/lib/orient_db/migrations/create_comment.rb @@ -0,0 +1,14 @@ +class OrientDb::Migrations::CreateComment < OrientDb::Migration + + def up + create_class 'Comment', 'V' do |c| + c.property 'text', :string + c.property 'date_creation', :datetime + c.property 'last_modified', :datetime + end + end + + def down + drop_class 'Comment' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_commented_by.rb b/lib/orient_db/migrations/create_commented_by.rb new file mode 100644 index 0000000000000000000000000000000000000000..c35515623adc1f40c44a3253b77c97a1381d9493 --- /dev/null +++ b/lib/orient_db/migrations/create_commented_by.rb @@ -0,0 +1,10 @@ +class OrientDb::Migrations::CreateCommentedBy < OrientDb::Migration + + def up + create_class 'CommentedBy', 'E' + end + + def down + drop_class 'CommentedBy' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_comments.rb b/lib/orient_db/migrations/create_comments.rb new file mode 100644 index 0000000000000000000000000000000000000000..adc6b6d5825f9a7a19813029a4c0840bb0d1e65a --- /dev/null +++ b/lib/orient_db/migrations/create_comments.rb @@ -0,0 +1,10 @@ +class OrientDb::Migrations::CreateComments < OrientDb::Migration + + def up + create_class 'Comments', 'E' + end + + def down + drop_class 'Comments' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_country.rb b/lib/orient_db/migrations/create_country.rb deleted file mode 100644 index 430b2e491d18da7fbc5f92aaf2a5be34aedbf5bf..0000000000000000000000000000000000000000 --- a/lib/orient_db/migrations/create_country.rb +++ /dev/null @@ -1,7 +0,0 @@ -class OrientDb::Migrations::CreateCountry < OrientDb::Migration - - def up - create_class 'Country' - end - -end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_has_attr.rb b/lib/orient_db/migrations/create_has_attr.rb new file mode 100644 index 0000000000000000000000000000000000000000..7a7613c54efea93e468e7600de449d965191c55a --- /dev/null +++ b/lib/orient_db/migrations/create_has_attr.rb @@ -0,0 +1,10 @@ +class OrientDb::Migrations::CreateHasAttr < OrientDb::Migration + + def up + create_class 'HasAttr', 'E' + end + + def down + drop_class 'HasAttr' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_highlight.rb b/lib/orient_db/migrations/create_highlight.rb deleted file mode 100644 index 8fcc0b450132c0470a82fd799ef403b958aa8312..0000000000000000000000000000000000000000 --- a/lib/orient_db/migrations/create_highlight.rb +++ /dev/null @@ -1,7 +0,0 @@ -class OrientDb::Migrations::CreateHighlight < OrientDb::Migration - - def up - create_class 'Highlight' - end - -end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_institution.rb b/lib/orient_db/migrations/create_institution.rb new file mode 100644 index 0000000000000000000000000000000000000000..2c23aa4838b7f1a938c6d18a62ea1b1bc7170bc1 --- /dev/null +++ b/lib/orient_db/migrations/create_institution.rb @@ -0,0 +1,16 @@ +class OrientDb::Migrations::CreateInstitution < OrientDb::Migration + + def up + create_class 'Institution', 'Object' do |c| + c.property 'country', :string + c.property 'city', :string + c.property 'address', :string + c.property 'description', :string + c.property 'thumbnail', :string + end + end + + def down + drop_class 'Institution' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_is_about.rb b/lib/orient_db/migrations/create_is_about.rb new file mode 100644 index 0000000000000000000000000000000000000000..242fc25124753caa94c4137b9888c28d944274f9 --- /dev/null +++ b/lib/orient_db/migrations/create_is_about.rb @@ -0,0 +1,10 @@ +class OrientDb::Migrations::CreateIsAbout < OrientDb::Migration + + def up + create_class 'IsAbout', 'E' + end + + def down + drop_class 'IsAbout' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_learning_object.rb b/lib/orient_db/migrations/create_learning_object.rb new file mode 100644 index 0000000000000000000000000000000000000000..194fedb43ebad70e53e02647dc1a404c4dd7a0a3 --- /dev/null +++ b/lib/orient_db/migrations/create_learning_object.rb @@ -0,0 +1,17 @@ +class OrientDb::Migrations::CreateLearningObject < OrientDb::Migration + + def up + create_class 'LearningObject', 'Object' do |c| + c.property 'id_dspace', :integer, :mandatory => true, :notnull => true + c.property 'description', :string + c.property 'thumbnail', :string + c.property 'type', :string + c.property 'metadata', :string + end + add_index 'LearningObject', 'id_dspace', :type => "UNIQUE_HASH_INDEX" + end + + def down + drop_class 'LearningObject' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_like.rb b/lib/orient_db/migrations/create_like.rb new file mode 100644 index 0000000000000000000000000000000000000000..5bbb2bff96a442183180050c450ee4c1bbc87a89 --- /dev/null +++ b/lib/orient_db/migrations/create_like.rb @@ -0,0 +1,10 @@ +class OrientDb::Migrations::CreateLike < OrientDb::Migration + + def up + create_class 'Like', 'E' + end + + def down + drop_class 'Like' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_main_page.rb b/lib/orient_db/migrations/create_main_page.rb new file mode 100644 index 0000000000000000000000000000000000000000..bdcbc099e7dce5bd4ff0459dc150f70cfddd853d --- /dev/null +++ b/lib/orient_db/migrations/create_main_page.rb @@ -0,0 +1,12 @@ +class OrientDb::Migrations::CreateMainPage < OrientDb::Migration + + def up + create_class 'MainPage', 'V' do |c| + c.link 'highlights', :linkset, 'LearningObject' + end + end + + def down + drop_class 'MainPage' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_object.rb b/lib/orient_db/migrations/create_object.rb new file mode 100644 index 0000000000000000000000000000000000000000..d25a6d96f6c1bd97ae9f0cf32a861438d2cff8bc --- /dev/null +++ b/lib/orient_db/migrations/create_object.rb @@ -0,0 +1,14 @@ +class OrientDb::Migrations::CreateObject < OrientDb::Migration + + def up + create_class 'Object', 'V' do |c| + c.property 'name', :string + c.property 'date_creation', :datetime + c.property 'last_modified', :datetime + end + end + + def down + drop_class 'Object' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_published_by.rb b/lib/orient_db/migrations/create_published_by.rb new file mode 100644 index 0000000000000000000000000000000000000000..07df1d07f42d549b4567fb692a9100c81e28c55b --- /dev/null +++ b/lib/orient_db/migrations/create_published_by.rb @@ -0,0 +1,10 @@ +class OrientDb::Migrations::CreatePublishedBy < OrientDb::Migration + + def up + create_class 'PublishedBy', 'E' + end + + def down + drop_class 'PublishedBy' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_subject.rb b/lib/orient_db/migrations/create_subject.rb new file mode 100644 index 0000000000000000000000000000000000000000..cee8e81723ca32d8f52dbb6365136d0d90b7d486 --- /dev/null +++ b/lib/orient_db/migrations/create_subject.rb @@ -0,0 +1,12 @@ +class OrientDb::Migrations::CreateSubject < OrientDb::Migration + + def up + create_class 'Subject', 'Object' do |c| + c.link 'highlights', :linkset, 'LearningObject' + end + end + + def down + drop_class 'Subject' + end +end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_university.rb b/lib/orient_db/migrations/create_university.rb deleted file mode 100644 index ec6df66553002417519d52ad26c95bae3cf1f370..0000000000000000000000000000000000000000 --- a/lib/orient_db/migrations/create_university.rb +++ /dev/null @@ -1,7 +0,0 @@ -class OrientDb::Migrations::CreateUniversity < OrientDb::Migration - - def up - create_class 'University' - end - -end \ No newline at end of file diff --git a/lib/orient_db/migrations/create_user.rb b/lib/orient_db/migrations/create_user.rb index 50136f70d0cec824fc17b64697ba2598c27eb9cc..887c6be713a59ec266711512f01e704e5e5199b1 100644 --- a/lib/orient_db/migrations/create_user.rb +++ b/lib/orient_db/migrations/create_user.rb @@ -1,7 +1,13 @@ class OrientDb::Migrations::CreateUser < OrientDb::Migration def up - create_class 'User' + create_class 'User', 'V' do |c| + c.property 'p_id', :integer, :mandatory => true, :notnull => true + end + add_index 'User', 'p_id', "UNIQUE_HASH_INDEX" end + def down + drop_class 'User' + end end \ No newline at end of file diff --git a/lib/tasks/orientdb.rake b/lib/tasks/orientdb.rake index 401f4bf62f493f297a58d5a0171ff2466b2b45e2..1cce055bcffeaa46aef05696976e1164fb08fdf8 100644 --- a/lib/tasks/orientdb.rake +++ b/lib/tasks/orientdb.rake @@ -2,12 +2,19 @@ namespace :orientdb do desc "Orient DB integration tasks" task migrate: :environment do - desc "Migrate orient db schema" + desc "Migrate OrientDB schema" migrations = OrientDb::Migrations.new(OrientDb::Client.instance) migrations.run end + task drop: :environment do + desc "Drop OrientDB schema" + + migrations = OrientDb::Migrations.new(OrientDb::Client.instance) + migrations.drop + end + task create_learning_object_relations: :environment do desc "Create LearningObject relations based on its metadata"