orientdb-schema-migrator 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1248c231b6e9daabc14adad92504c3c554bf5c99
4
- data.tar.gz: 567fdd36e4f5420c8be2c50474870eabffac84d0
3
+ metadata.gz: cf9d9e3fb0150f23f6bfd7a70b5da16feba0c8fb
4
+ data.tar.gz: b9da196ea991fba8ba19a7160f619bc35d9d6ce3
5
5
  SHA512:
6
- metadata.gz: c3fee532d00b7257a074de17c5da9f5802be37f0b1ba3e03e835db913bb5ed6d52a27229ed4e645ad0e7f81c1a21775792ed996f96f381292a0e13ee97d5c86f
7
- data.tar.gz: 1599105f1143cab750e070362a4ff5c59101a05a9371fa851015d4473dcd804cba5600fffb1ae1e67bd99faa777d292d84e02427df6f961228962b00e7dd5495
6
+ metadata.gz: 3beca086f3fe46ae19be29c1ff8718599177444622e07be46f6de42c3fbdd2eb30aace0fe7c417be5f0719b1a62920d499d57363006c24a9fc0dd3e8a605add0
7
+ data.tar.gz: c28718cd7823755f1902159573b3a266a474ab6c77e9229e62cfe99529fd0fb60d1af4909c7378651bb0a17315e2cfa32dd507efcba36a1caa4020868c18189d
data/Rakefile CHANGED
@@ -19,12 +19,12 @@ db_namespace = namespace :db do
19
19
  }
20
20
 
21
21
  task :connect do
22
- OrientdbSchemaMigrator::ODBClient.connect(:database => db, :user => db_user, :password => db_pass)
22
+ OrientdbSchemaMigrator.client.connect(:database => db, :user => db_user, :password => db_pass)
23
23
  end
24
24
 
25
25
  desc "Verify your orientdb test database setup"
26
26
  task :verify_test_db do
27
- if OrientdbSchemaMigrator::ODBClient.database_exists?(config)
27
+ if OrientdbSchemaMigrator.client.database_exists?(config)
28
28
  puts "Test database exists"
29
29
  else
30
30
  raise "Failure: database does not exist"
@@ -1,5 +1,5 @@
1
1
  require "orientdb4r"
2
-
2
+ require "yaml"
3
3
  require "orientdb_schema_migrator/version"
4
4
  require "orientdb_schema_migrator/migration"
5
5
  require "orientdb_schema_migrator/migration_generator"
@@ -9,5 +9,33 @@ require "orientdb_schema_migrator/proxy"
9
9
  require "orientdb_schema_migrator/railtie" if defined?(Rails)
10
10
 
11
11
  module OrientdbSchemaMigrator
12
- ODBClient = Orientdb4r.client
12
+ def self.get_config
13
+ config_file =
14
+ if defined?(Rails)
15
+ Rails.root.to_s + '/config/orientdb.yml'
16
+ elsif ENV['ODB_TEST']
17
+ File.expand_path('../../spec/support/config.yml', __FILE__)
18
+ elsif ENV['odb_config_path']
19
+ ENV['odb_config_path']
20
+ else
21
+ raise "No odb config path defined"
22
+ end
23
+ env =
24
+ if defined?(Rails)
25
+ Rails.env
26
+ elsif ENV['ODB_TEST']
27
+ 'test'
28
+ else
29
+ raise "No environment specified to load database connection config"
30
+ end
31
+ YAML.load_file(config_file)[env]
32
+ end
33
+
34
+ def self.client
35
+ if defined?($client)
36
+ $client
37
+ else
38
+ $client = Orientdb4r.client(:host => get_config["host"])
39
+ end
40
+ end
13
41
  end
@@ -5,7 +5,7 @@ module OrientdbSchemaMigrator
5
5
  def self.create_class class_name, class_options={}
6
6
  # check if class exists first
7
7
  assert_class_not_exists!(class_name)
8
- ODBClient.create_class class_name, class_options
8
+ OrientdbSchemaMigrator.client.create_class class_name, class_options
9
9
  if block_given?
10
10
  proxy = Proxy.new(self, class_name)
11
11
  yield proxy
@@ -16,14 +16,14 @@ module OrientdbSchemaMigrator
16
16
  # check if class exists first
17
17
  if class_exists?(class_name)
18
18
  # delete vertices/edges first
19
- super_class = ODBClient.get_class(class_name)["superClass"]
19
+ super_class = OrientdbSchemaMigrator.client.get_class(class_name)["superClass"]
20
20
  if super_class == "V"
21
- ODBClient.command "delete vertex #{class_name}"
21
+ OrientdbSchemaMigrator.client.command "delete vertex #{class_name}"
22
22
  elsif super_class == "E"
23
- ODBClient.command "delete edge #{class_name}"
23
+ OrientdbSchemaMigrator.client.command "delete edge #{class_name}"
24
24
  end
25
25
  # drop class
26
- ODBClient.command "drop class #{class_name}"
26
+ OrientdbSchemaMigrator.client.command "drop class #{class_name}"
27
27
  return true
28
28
  else
29
29
  return false
@@ -32,52 +32,52 @@ module OrientdbSchemaMigrator
32
32
 
33
33
  def self.rename_class old_name, new_name
34
34
  assert_class_exists!(old_name)
35
- ODBClient.command "alter class #{old_name} name #{new_name}"
35
+ OrientdbSchemaMigrator.client.command "alter class #{old_name} name #{new_name}"
36
36
  end
37
37
 
38
38
  def self.add_property class_name, property_name, type, property_options={}
39
39
  assert_class_exists!(class_name)
40
40
  assert_property_not_exists!(class_name, property_name)
41
- ODBClient.create_property class_name,property_name,type, property_options
41
+ OrientdbSchemaMigrator.client.create_property class_name,property_name,type, property_options
42
42
  end
43
43
 
44
44
  def self.drop_property class_name, property_name
45
45
  assert_class_exists!(class_name)
46
46
  assert_property_exists!(class_name, property_name)
47
- ODBClient.command "drop property #{class_name}.#{property_name}"
47
+ OrientdbSchemaMigrator.client.command "drop property #{class_name}.#{property_name}"
48
48
  end
49
49
 
50
50
  def self.alter_property class_name, property_name, attribute_name, new_value
51
51
  assert_class_exists!(class_name)
52
52
  assert_property_exists!(class_name, property_name)
53
- ODBClient.command "alter property #{class_name}.#{property_name} #{attribute_name} #{new_value}"
53
+ OrientdbSchemaMigrator.client.command "alter property #{class_name}.#{property_name} #{attribute_name} #{new_value}"
54
54
  end
55
55
 
56
56
  def self.add_index class_name, property_name, index_name, type
57
57
  assert_class_exists!(class_name)
58
58
  assert_property_exists!(class_name, property_name)
59
59
  assert_index_not_exists!(class_name, index_name)
60
- ODBClient.command "create index #{index_name} on #{class_name} (#{property_name}) #{type}"
60
+ OrientdbSchemaMigrator.client.command "create index #{index_name} on #{class_name} (#{property_name}) #{type}"
61
61
  end
62
62
 
63
63
  def self.drop_index index_name
64
- ODBClient.command "drop index #{index_name}"
64
+ OrientdbSchemaMigrator.client.command "drop index #{index_name}"
65
65
  end
66
66
 
67
67
  def self.class_exists? class_name
68
- ODBClient.class_exists? class_name
68
+ OrientdbSchemaMigrator.client.class_exists? class_name
69
69
  end
70
70
 
71
71
  def self.index_exists?(class_name, index_name)
72
72
  return false unless class_exists?(class_name)
73
- indexes = ODBClient.get_class(class_name)["indexes"]
73
+ indexes = OrientdbSchemaMigrator.client.get_class(class_name)["indexes"]
74
74
  return false unless indexes
75
75
  return indexes.any? { |idx| idx['name'] == index_name }
76
76
  end
77
77
 
78
78
  def self.property_exists? class_name, property_name
79
79
  if class_exists? class_name
80
- properties = ODBClient.get_class(class_name)["properties"]
80
+ properties = OrientdbSchemaMigrator.client.get_class(class_name)["properties"]
81
81
  if properties
82
82
  return properties.collect{|i| i["name"]}.include? property_name
83
83
  else
@@ -16,11 +16,11 @@ module OrientdbSchemaMigrator
16
16
  end
17
17
 
18
18
  def connect_to_db db, user, password
19
- ODBClient.connect :database => db, :user => user, :password => password
19
+ OrientdbSchemaMigrator.client.connect :database => db, :user => user, :password => password
20
20
  end
21
21
 
22
22
  def disconnect
23
- ODBClient.disconnect
23
+ OrientdbSchemaMigrator.client.disconnect
24
24
  end
25
25
 
26
26
  def migrate(target_version = nil)
@@ -55,7 +55,7 @@ module OrientdbSchemaMigrator
55
55
  end
56
56
 
57
57
  def current_version
58
- response = ODBClient.command "SELECT schema_version FROM schema_versions ORDER BY @rid DESC LIMIT 1"
58
+ response = OrientdbSchemaMigrator.client.command "SELECT schema_version FROM schema_versions ORDER BY @rid DESC LIMIT 1"
59
59
  results = response['result']
60
60
  results.any? ? results.first['schema_version'] : nil
61
61
  end
@@ -107,11 +107,11 @@ module OrientdbSchemaMigrator
107
107
  end
108
108
 
109
109
  def record_migration(migration)
110
- ODBClient.command "INSERT INTO schema_versions (schema_version) VALUES (#{migration[:version]})"
110
+ OrientdbSchemaMigrator.client.command "INSERT INTO schema_versions (schema_version) VALUES (#{migration[:version]})"
111
111
  end
112
112
 
113
113
  def drop_migration(migration)
114
- ODBClient.command "DELETE FROM schema_versions WHERE schema_version = '#{migration[:version]}'"
114
+ OrientdbSchemaMigrator.client.command "DELETE FROM schema_versions WHERE schema_version = '#{migration[:version]}'"
115
115
  end
116
116
 
117
117
  def up?
@@ -1,3 +1,3 @@
1
1
  module OrientdbSchemaMigrator
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,5 +1,3 @@
1
- require 'yaml'
2
-
3
1
  namespace :odb do
4
2
  task :config do
5
3
  if !ENV['ODB_TEST']
@@ -17,27 +15,7 @@ namespace :odb do
17
15
  end
18
16
 
19
17
  def with_connection &block
20
- config_file =
21
- if defined?(Rails)
22
- Rails.root.to_s + '/config/orientdb.yml'
23
- elsif ENV['ODB_TEST']
24
- File.expand_path('../../../spec/support/config.yml', __FILE__)
25
- elsif ENV['odb_config_path']
26
- ENV['odb_config_path']
27
- else
28
- raise "No odb config path defined"
29
- end
30
-
31
- env =
32
- if defined?(Rails)
33
- Rails.env
34
- elsif ENV['ODB_TEST']
35
- 'test'
36
- else
37
- raise "No environment specified to load database connection config"
38
- end
39
-
40
- config = YAML.load_file(config_file)[env]
18
+ config = OrientdbSchemaMigrator.get_config
41
19
  OrientdbSchemaMigrator::Migrator.connect_to_db(config['db'], config['user'], config['password'])
42
20
  begin
43
21
  yield
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orientdb-schema-migrator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - CoPromote
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-16 00:00:00.000000000 Z
11
+ date: 2015-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: orientdb4r