legion-data 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +147 -0
  3. data/.gitignore +13 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +29 -0
  6. data/Gemfile +7 -0
  7. data/README.md +35 -0
  8. data/Rakefile +55 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/bitbucket-pipelines.yml +26 -0
  12. data/legion-data.gemspec +38 -0
  13. data/lib/legion/data.rb +43 -0
  14. data/lib/legion/data/connection.rb +30 -0
  15. data/lib/legion/data/connections/base.rb +45 -0
  16. data/lib/legion/data/connections/jdbc.rb +21 -0
  17. data/lib/legion/data/connections/mysql.rb +26 -0
  18. data/lib/legion/data/connections/mysql2.rb +26 -0
  19. data/lib/legion/data/connections/mysql_base.rb +19 -0
  20. data/lib/legion/data/migration.rb +28 -0
  21. data/lib/legion/data/migrations/001_add_schema_columns.rb +17 -0
  22. data/lib/legion/data/migrations/002_add_chains_table.rb +21 -0
  23. data/lib/legion/data/migrations/003_add_datacenters_table.rb +21 -0
  24. data/lib/legion/data/migrations/004_add_envs_table.rb +21 -0
  25. data/lib/legion/data/migrations/005_add_functions_table.rb +25 -0
  26. data/lib/legion/data/migrations/006_add_namespaces_table.rb +24 -0
  27. data/lib/legion/data/migrations/007_add_nodes_table.rb +22 -0
  28. data/lib/legion/data/migrations/008_add_relationships_table.rb +28 -0
  29. data/lib/legion/data/migrations/009_add_task_logs_table.rb +17 -0
  30. data/lib/legion/data/migrations/010_add_tasks_table.rb +20 -0
  31. data/lib/legion/data/migrations/011_add_users_and_groups.rb +28 -0
  32. data/lib/legion/data/migrations/012_foreign_keys_users_and_groups.rb +42 -0
  33. data/lib/legion/data/migrations/013_function_foreign_keys.rb +10 -0
  34. data/lib/legion/data/migrations/014_nodes_foreign_keys.rb +12 -0
  35. data/lib/legion/data/migrations/015_relationships_foreign_keys.rb +14 -0
  36. data/lib/legion/data/migrations/016_tasks_foreign_keys.rb +22 -0
  37. data/lib/legion/data/migrations/017_add_relationship_to_tasks.rb +14 -0
  38. data/lib/legion/data/model.rb +35 -0
  39. data/lib/legion/data/models/chain.rb +12 -0
  40. data/lib/legion/data/models/datacenter.rb +12 -0
  41. data/lib/legion/data/models/environment.rb +12 -0
  42. data/lib/legion/data/models/function.rb +14 -0
  43. data/lib/legion/data/models/namespace.rb +12 -0
  44. data/lib/legion/data/models/node.rb +13 -0
  45. data/lib/legion/data/models/relationship.rb +16 -0
  46. data/lib/legion/data/models/task.rb +17 -0
  47. data/lib/legion/data/models/task_log.rb +13 -0
  48. data/lib/legion/data/version.rb +5 -0
  49. metadata +230 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3181ed356e3e8824c11395ebe6e9243951f75ba4167d61ef1fa50bd67e492a0c
4
+ data.tar.gz: e5ef94e148b2fd6c54c8790f10293ee61f3c1186bbe2f784bbef029b25df70c6
5
+ SHA512:
6
+ metadata.gz: ecf75674d469d1d79b17bebd520b9ed4259ff7187884abc020d30aaa069d4920fafdf55100223ff5aabfe941aeb9378bc290fb292277cabf34ced9acecafe99e
7
+ data.tar.gz: 81d01b0512a7054babf355225139bc767c6d0aea8284bed05b94b54563f5e45289ca3b6f1953910e6a38aaa2b945b20979212ff5cb82e2a9e8699eab58c65dde
@@ -0,0 +1,147 @@
1
+ version: 2 # use CircleCI 2.0
2
+ jobs:
3
+ "rubocop":
4
+ docker:
5
+ - image: circleci/ruby:2.4-node
6
+ steps:
7
+ - checkout
8
+ - run: gem install rubocop
9
+ - run:
10
+ name: Run Rubocop
11
+ command: rubocop
12
+ - store_test_results:
13
+ path: test_results
14
+ "ruby-2.3":
15
+ docker:
16
+ - image: circleci/ruby:2.3
17
+ - image: mysql:5.7
18
+ environment:
19
+ MYSQL_DATABASE: 'legion'
20
+ MYSQL_ROOT_PASSWORD: 'legion'
21
+ MYSQL_USER: 'legion'
22
+ MYSQL_PASSWORD: 'legion'
23
+ steps:
24
+ - checkout
25
+ - run:
26
+ name: Bundle Install
27
+ command: bundle install
28
+ - run:
29
+ name: Run RSpec
30
+ command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
31
+ when: always
32
+ - store_test_results:
33
+ path: test-results
34
+
35
+ "ruby-2.4":
36
+ docker:
37
+ - image: circleci/ruby:2.4-node
38
+ - image: mysql:5.7
39
+ environment:
40
+ MYSQL_DATABASE: 'legion'
41
+ MYSQL_ROOT_PASSWORD: 'legion'
42
+ MYSQL_USER: 'legion'
43
+ MYSQL_PASSWORD: 'legion'
44
+ steps:
45
+ - checkout
46
+ - run:
47
+ name: Bundle Install
48
+ command: bundle install
49
+ - run:
50
+ name: Run RSpec
51
+ command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
52
+ when: always
53
+ - store_test_results:
54
+ path: test-results
55
+ "ruby-2.5":
56
+ docker:
57
+ - image: circleci/ruby:2.5-node
58
+ - image: mysql:5.7
59
+ environment:
60
+ MYSQL_DATABASE: 'legion'
61
+ MYSQL_ROOT_PASSWORD: 'legion'
62
+ MYSQL_USER: 'legion'
63
+ MYSQL_PASSWORD: 'legion'
64
+ steps:
65
+ - checkout
66
+ - run:
67
+ name: Bundle Install
68
+ command: bundle install
69
+ - run:
70
+ name: Run RSpec
71
+ command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
72
+ when: always
73
+ - store_test_results:
74
+ path: test-results
75
+ "ruby-2.6":
76
+ docker:
77
+ - image: circleci/ruby:2.6-node
78
+ - image: mysql:5.7
79
+ environment:
80
+ MYSQL_DATABASE: 'legion'
81
+ MYSQL_ROOT_PASSWORD: 'legion'
82
+ MYSQL_USER: 'legion'
83
+ MYSQL_PASSWORD: 'legion'
84
+ steps:
85
+ - checkout
86
+ - run:
87
+ name: Bundle Install
88
+ command: bundle install
89
+ - run:
90
+ name: Run RSpec
91
+ command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
92
+ when: always
93
+ - store_test_results:
94
+ path: test-results
95
+ "jruby-9.2":
96
+ docker:
97
+ - image: circleci/jruby:9.2
98
+ - image: mysql:5.7
99
+ environment:
100
+ MYSQL_DATABASE: 'legion'
101
+ MYSQL_ROOT_PASSWORD: 'legion'
102
+ MYSQL_USER: 'legion'
103
+ MYSQL_PASSWORD: 'legion'
104
+ steps:
105
+ - checkout
106
+ - run:
107
+ name: Bundle Install
108
+ command: bundle install
109
+ - run:
110
+ name: Run RSpec
111
+ command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
112
+ when: always
113
+ - store_test_results:
114
+ path: test-results
115
+
116
+ workflows:
117
+ version: 2
118
+ cop_rake_deploy:
119
+ jobs:
120
+ - rubocop
121
+ - ruby-2.3:
122
+ requires:
123
+ - ruby-2.4
124
+ filters:
125
+ branches:
126
+ only: /\bdevelop\b|\bmaster\b/
127
+ - ruby-2.4:
128
+ requires:
129
+ - rubocop
130
+ - ruby-2.5:
131
+ requires:
132
+ - ruby-2.4
133
+ filters:
134
+ branches:
135
+ only: /\bdevelop\b|\bmaster\b/
136
+ - ruby-2.6:
137
+ requires:
138
+ - ruby-2.4
139
+ filters:
140
+ branches:
141
+ only: /\bdevelop\b|\bmaster\b/
142
+ # - jruby-9.2:
143
+ # requires:
144
+ # - ruby-2.3
145
+ # - ruby-2.4
146
+ # - ruby-2.5
147
+ # - ruby-2.6
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /*.log
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,29 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+ Exclude:
4
+ - 'lib/legion/data/migrations/*.rb'
5
+ Metrics/MethodLength:
6
+ Max: 30
7
+ Metrics/ClassLength:
8
+ Max: 1500
9
+ Metrics/BlockLength:
10
+ Max: 50
11
+ Exclude:
12
+ - 'lib/legion/data/migrations/*'
13
+ Layout/SpaceAroundEqualsInParameterDefault:
14
+ EnforcedStyle: space
15
+ Style/SymbolArray:
16
+ Enabled: true
17
+ Layout/AlignHash:
18
+ EnforcedHashRocketStyle: table
19
+ EnforcedColonStyle: table
20
+ Style/HashSyntax:
21
+ EnforcedStyle: ruby19_no_mixed_keys
22
+ Style/Documentation:
23
+ Enabled: false
24
+ AllCops:
25
+ TargetRubyVersion: 2.4
26
+ Style/FrozenStringLiteralComment:
27
+ Enabled: false
28
+ Naming/FileName:
29
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in legion-data.gemspec
4
+ gemspec
5
+
6
+ gem 'legion-logging', path: '~/legion-io/legion-logging'
7
+ gem 'legion-settings', path: '~/legion-io/legion-settings'
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Legion::Data
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/legion/data`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'legion-data'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install legion-data
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/legion-data.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
8
+
9
+ task :dev do
10
+ end
11
+
12
+ RuboCop::RakeTask.new(:rubocop) do |t|
13
+ t.options = ['--display-cop-names']
14
+ end
15
+
16
+ RuboCop::RakeTask.new(:rubocop_fix) do |t|
17
+ # t.options = ['--display-cop-names -a']
18
+ t.options = ['--display-cop-names']
19
+ end
20
+
21
+ namespace :db do
22
+ require 'sequel'
23
+ require 'legion/logging'
24
+ Sequel.extension :migration
25
+
26
+ # desc 'Prints current schema version'
27
+ # task :version do
28
+ # version = DB[:schema_info].first[:version] # if DB.tables.include?(:schema_info) || true
29
+ #
30
+ # puts "Schema Version: #{version}"
31
+ # end
32
+ #
33
+ # desc 'Perform migration up to latest migration available'
34
+ # task :migrate do
35
+ # Sequel::Migrator.run(DB, 'lib/legion/data/migrations')
36
+ # Rake::Task['db:version'].execute
37
+ # end
38
+ #
39
+ # desc 'Perform rollback to specified target or full rollback as default'
40
+ # task :rollback, :target do |_t, args|
41
+ # args.with_defaults(target: 0)
42
+ #
43
+ # Sequel::Migrator.run(DB, 'lib/legion/data/migrations', target: args[:target].to_i)
44
+ # Rake::Task['db:version'].execute
45
+ # end
46
+ #
47
+ # desc 'Perform migration reset (full rollback and migration)'
48
+ # task :reset do
49
+ # Sequel::Migrator.run(DB, 'migrations', target: 0)
50
+ # Sequel::Migrator.run(DB, 'migrations')
51
+ # Rake::Task['db:version'].execute
52
+ # end
53
+ end
54
+
55
+ # RuboCop::RakeTask.new
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'legion/data'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ image: ruby:2.4.0
2
+
3
+ pipelines:
4
+ branches:
5
+ master:
6
+ - step:
7
+ caches:
8
+ - bundler
9
+ script:
10
+ - gem install bundle rubocop
11
+ - bundle install
12
+ - rubocop
13
+ - rake
14
+ services:
15
+ - mysql
16
+ definitions:
17
+ services:
18
+ mysql:
19
+ image: mysql:5.7
20
+ environment:
21
+ MYSQL_DATABASE: 'legion'
22
+ MYSQL_ROOT_PASSWORD: 'legion'
23
+ MYSQL_USER: 'legion'
24
+ MYSQL_PASSWORD: 'legion'
25
+ caches:
26
+ bundler: vendor/bundle
@@ -0,0 +1,38 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'legion/data/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = (RUBY_ENGINE == 'jruby' ? 'legion-data-java' : 'legion-data')
7
+ spec.version = Legion::Data::VERSION
8
+ spec.authors = ['Esity']
9
+ spec.email = ['matthewdiverson@gmail.com']
10
+
11
+ spec.summary = 'Used by Legion to connect to the database'
12
+ spec.description = 'The Legion connect gem'
13
+ spec.homepage = 'https://bitbucket.org/legion-io/legion-data'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'codecov', '~> 0'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0'
27
+ spec.add_development_dependency 'rubocop', '~> 0'
28
+
29
+ spec.add_dependency 'legion-logging', '~>0.1'
30
+ spec.add_dependency 'legion-settings', '~>0.1'
31
+
32
+ if RUBY_ENGINE == 'jruby'
33
+ spec.add_dependency 'jdbc-mysql'
34
+ else
35
+ spec.add_dependency 'mysql2'
36
+ end
37
+ spec.add_dependency 'sequel'
38
+ end
@@ -0,0 +1,43 @@
1
+ require 'legion/data/version'
2
+ require 'sequel'
3
+ require 'legion/data/connection'
4
+ require 'legion/data/migration'
5
+ require 'legion/data/model'
6
+
7
+ module Legion
8
+ module Data
9
+ def build(options = {})
10
+ @connected = false
11
+ options.merge!(default_options) { |_key, v1, _v2| v1 }
12
+ @connection = connect(options[:connection]) if options[:connection][:auto_connect]
13
+ return unless options[:connection][:auto_connect]
14
+
15
+ migrate(@connection, options[:migration])
16
+ model(options[:model]) if options[:model][:auto_load]
17
+ end
18
+
19
+ def connect(_options = {})
20
+ Legion::Data::Connection.new
21
+ end
22
+
23
+ def migrate(connection, options = {})
24
+ return false if options.key?(:auto_migrate) && options[:auto_migrate]
25
+
26
+ Legion::Data::Migration.new(connection.database.connection)
27
+ end
28
+
29
+ def model(_options = {})
30
+ Legion::Data::Models.new
31
+ end
32
+
33
+ def default_options
34
+ { migration: { auto_migrate: true },
35
+ model: { auto_load: true },
36
+ connection: { auto_connect: true } }
37
+ end
38
+
39
+ def merge_options(options, default = default_options)
40
+ options.merge!(default) { |_key, v1, _v2| v1 }
41
+ end
42
+ end
43
+ end