diff --git a/lib/orient_db/migration.rb b/lib/orient_db/migration.rb new file mode 100644 index 0000000000000000000000000000000000000000..37c5cecd0107abdb5038aefc4fce6425963b4459 --- /dev/null +++ b/lib/orient_db/migration.rb @@ -0,0 +1,18 @@ +module OrientDb + class Migration + + def initialize(client) + @client = client + end + + def create_class(klass) + unless @client.class_exists? klass + @client.create_class(klass) do |c| + if block_given? + yield c + end + 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 new file mode 100644 index 0000000000000000000000000000000000000000..b721b8d6974e26c5c009a20a106efcda7004f50e --- /dev/null +++ b/lib/orient_db/migrations.rb @@ -0,0 +1,13 @@ +class OrientDb::Migrations + def initialize(client) + @migrations = [] + @migrations << CreateCountry.new(client) + @migrations << CreateHighlight.new(client) + @migrations << CreateUniversity.new(client) + @migrations << CreateUser.new(client) + end + + def run + @migrations.each { |m| m.up } + 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 new file mode 100644 index 0000000000000000000000000000000000000000..430b2e491d18da7fbc5f92aaf2a5be34aedbf5bf --- /dev/null +++ b/lib/orient_db/migrations/create_country.rb @@ -0,0 +1,7 @@ +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_highlight.rb b/lib/orient_db/migrations/create_highlight.rb new file mode 100644 index 0000000000000000000000000000000000000000..8fcc0b450132c0470a82fd799ef403b958aa8312 --- /dev/null +++ b/lib/orient_db/migrations/create_highlight.rb @@ -0,0 +1,7 @@ +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_university.rb b/lib/orient_db/migrations/create_university.rb new file mode 100644 index 0000000000000000000000000000000000000000..ec6df66553002417519d52ad26c95bae3cf1f370 --- /dev/null +++ b/lib/orient_db/migrations/create_university.rb @@ -0,0 +1,7 @@ +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 new file mode 100644 index 0000000000000000000000000000000000000000..50136f70d0cec824fc17b64697ba2598c27eb9cc --- /dev/null +++ b/lib/orient_db/migrations/create_user.rb @@ -0,0 +1,7 @@ +class OrientDb::Migrations::CreateUser < OrientDb::Migration + + def up + create_class 'User' + end + +end \ No newline at end of file diff --git a/lib/tasks/orientdb.rake b/lib/tasks/orientdb.rake index ba2b89f700624bb252b84ba3a2a46eda18a2ee70..504aa1f120363f4c7d471ca017e70808a053ad6f 100644 --- a/lib/tasks/orientdb.rake +++ b/lib/tasks/orientdb.rake @@ -4,19 +4,8 @@ namespace :orientdb do task migrate: :environment do desc "Migrate orient db schema" - client = OrientDb::Client.instance - - # User vertice - client.command 'create class User extends V' - - # Highlight vertice - client.command 'create class Highlight extends V' - - # Country vertice - client.command 'create class Country extends V' - - # University vertice - client.command 'create class University extends V' + migrations = OrientDb::Migrations.new(OrientDb::Client.instance) + migrations.run end -end +end \ No newline at end of file