orientdb-schema-migrator 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/lib/orientdb-schema-migrator.rb +30 -2
- data/lib/orientdb_schema_migrator/migration.rb +14 -14
- data/lib/orientdb_schema_migrator/migrator.rb +5 -5
- data/lib/orientdb_schema_migrator/version.rb +1 -1
- data/lib/tasks/orientdb_schema_migrator.rake +1 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf9d9e3fb0150f23f6bfd7a70b5da16feba0c8fb
|
4
|
+
data.tar.gz: b9da196ea991fba8ba19a7160f619bc35d9d6ce3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
-
|
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
|
-
|
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 =
|
19
|
+
super_class = OrientdbSchemaMigrator.client.get_class(class_name)["superClass"]
|
20
20
|
if super_class == "V"
|
21
|
-
|
21
|
+
OrientdbSchemaMigrator.client.command "delete vertex #{class_name}"
|
22
22
|
elsif super_class == "E"
|
23
|
-
|
23
|
+
OrientdbSchemaMigrator.client.command "delete edge #{class_name}"
|
24
24
|
end
|
25
25
|
# drop class
|
26
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
64
|
+
OrientdbSchemaMigrator.client.command "drop index #{index_name}"
|
65
65
|
end
|
66
66
|
|
67
67
|
def self.class_exists? class_name
|
68
|
-
|
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 =
|
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 =
|
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
|
-
|
19
|
+
OrientdbSchemaMigrator.client.connect :database => db, :user => user, :password => password
|
20
20
|
end
|
21
21
|
|
22
22
|
def disconnect
|
23
|
-
|
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 =
|
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
|
-
|
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
|
-
|
114
|
+
OrientdbSchemaMigrator.client.command "DELETE FROM schema_versions WHERE schema_version = '#{migration[:version]}'"
|
115
115
|
end
|
116
116
|
|
117
117
|
def up?
|
@@ -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
|
-
|
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.
|
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-
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: orientdb4r
|