chartio-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +7 -0
- data/bin/chartio-rails +22 -0
- data/chartio-rails.gemspec +29 -0
- data/gemfiles/rails3.gemfile +5 -0
- data/gemfiles/rails31.gemfile +5 -0
- data/gemfiles/rails32.gemfile +5 -0
- data/gemfiles/rails40.gemfile +5 -0
- data/gemfiles/rails41.gemfile +5 -0
- data/lib/chartio-rails.rb +7 -0
- data/lib/chartio/csv_formatter.rb +29 -0
- data/lib/chartio/foreign_key_relationship.rb +29 -0
- data/lib/chartio/formatter.rb +13 -0
- data/lib/chartio/railtie.rb +14 -0
- data/lib/chartio/schema.rb +106 -0
- data/lib/chartio/test_formatter.rb +36 -0
- data/lib/chartio/version.rb +3 -0
- data/spec/chartio_rails_spec.rb +80 -0
- data/spec/csv_formatter_spec.rb +47 -0
- data/spec/example_app.rb +58 -0
- data/spec/schema.rb +55 -0
- data/spec/spec_helper.rb +21 -0
- data/tasks/chartio.rake +12 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7fd307c2f486484a41616b25455b756957bcb255
|
4
|
+
data.tar.gz: 559e769d21f44e5a7cf292c801e9b7cec61b267f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 50613ccc6158bc9f6ae54706cd086e4fa4d1608f008887b131e7ae61a7881c36fa3d6eea5490bdb790cc4bb63bacb93172a3be0f30deb8006a1eb1bfcdbf8ce8
|
7
|
+
data.tar.gz: ad6484ebb4b0ab97f1fe3539a63bee3d8c0dd35351ac1da7f3a745a21174cbf339ea08aabf87d557699489dc827d9564290989726bf8ff0a54628a6fb256ce50
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Rimas Silkaitis
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Chartio Rails
|
2
|
+
|
3
|
+
As a Rails user you're probably familiar with the fact that Rails doesn't not create foreign keys in the database. Since ActiveRecord migrations don't cover this, it makes it very hard to work with Chartio because the metadata around how tables should be joined together only lives at the application layer. Using this gem, you will be able to output the metadata around the relationships in your Rails project and, working with your Chartio Customer Success Engineer, can get the relationships you need for your database.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
group :development do
|
11
|
+
gem 'chartio-rails'
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install chartio-rails
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
$ rake chartio:schema
|
26
|
+
|
27
|
+
What's outputted is a csv with the needed schema information and a log file. You should package both and email them over to Chartio.
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/chartio-rails
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'optparse'
|
5
|
+
require 'yaml'
|
6
|
+
begin
|
7
|
+
require 'chartio-rails'
|
8
|
+
rescue LoadError
|
9
|
+
lib = File.expand_path('../../lib', __FILE__)
|
10
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
11
|
+
require File.expand_path("../../lib/chartio-rails", __FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
options = {}
|
15
|
+
options_parser = OptionParser.new do |opts|
|
16
|
+
opts.banner = <<-TXT
|
17
|
+
A helper function to build foreign key constraints in Chartio
|
18
|
+
|
19
|
+
Usage: relateiq_dump [options]
|
20
|
+
TXT
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chartio/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chartio-rails"
|
8
|
+
spec.version = Chartio::VERSION
|
9
|
+
spec.authors = ["Rimas Silkaitis"]
|
10
|
+
spec.email = ["rimas@chartio.com"]
|
11
|
+
spec.description = %q{Helper functions for getting your Rails database hooked up to Chartio}
|
12
|
+
spec.summary = %q{Helper functions for getting your Rails database hooked up to Chartio}
|
13
|
+
spec.homepage = "https://chartio.com/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "activerecord", ">= 3.0.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "sqlite3", '~> 1.3.8'
|
27
|
+
spec.add_development_dependency "wwtd", "~> 0.5.1"
|
28
|
+
spec.add_development_dependency "pry"
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Chartio
|
4
|
+
class CSVFormatter < Formatter
|
5
|
+
|
6
|
+
attr_accessor :foreign_keys
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@foreign_keys = []
|
10
|
+
@stringio = StringIO.open
|
11
|
+
@csv = CSV.new(@stringio)
|
12
|
+
end
|
13
|
+
|
14
|
+
def foreign_key(incoming_foreign_key)
|
15
|
+
@foreign_keys << incoming_foreign_key
|
16
|
+
end
|
17
|
+
|
18
|
+
def output_report
|
19
|
+
@csv << Chartio::ForeignKeyRelationship::FIELDS.map(&:to_s)
|
20
|
+
|
21
|
+
@foreign_keys.each do |key|
|
22
|
+
@csv << key.to_a
|
23
|
+
end
|
24
|
+
|
25
|
+
@csv.string
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Chartio
|
2
|
+
class ForeignKeyRelationship
|
3
|
+
|
4
|
+
FIELDS = [
|
5
|
+
:parent_table, :parent_primary_key, :child_table,
|
6
|
+
:child_foreign_key, :polymorphic_field
|
7
|
+
]
|
8
|
+
|
9
|
+
attr_accessor(*FIELDS)
|
10
|
+
|
11
|
+
def initialize(*args)
|
12
|
+
args.each_with_index do |ele, index|
|
13
|
+
instance_variable_set("@#{FIELDS[index]}", ele)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_a
|
18
|
+
FIELDS.map { |x| self.send(x) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_h
|
22
|
+
FIELDS.inject({}) do |hash, element|
|
23
|
+
hash[element] = self.send(element)
|
24
|
+
hash
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Chartio
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
railtie_name :chartio
|
4
|
+
|
5
|
+
rake_tasks do
|
6
|
+
load "tasks/chartio.rake"
|
7
|
+
end
|
8
|
+
|
9
|
+
config.to_prepare do
|
10
|
+
Rails.application.eager_load!
|
11
|
+
puts "[WARNING] chartio-rails eager loads all of your models in development mode"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module Chartio
|
5
|
+
class Schema
|
6
|
+
|
7
|
+
attr_accessor :formatter, :logger
|
8
|
+
|
9
|
+
def initialize(formatter, logger = STDOUT)
|
10
|
+
@formatter = formatter
|
11
|
+
@logger = logger
|
12
|
+
end
|
13
|
+
|
14
|
+
def output_report
|
15
|
+
find_relationships do |record|
|
16
|
+
begin
|
17
|
+
@formatter << record
|
18
|
+
rescue => e
|
19
|
+
logger.puts "Encountered an error"
|
20
|
+
logger.puts e.message
|
21
|
+
logger.puts e.backtrace
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
@formatter.output_report
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def foreign_key_method
|
31
|
+
ActiveRecord::VERSION::STRING < '3.1.' ? :primary_key_name : :foreign_key
|
32
|
+
end
|
33
|
+
|
34
|
+
def polymorphic_type(association_reflection)
|
35
|
+
if ActiveRecord::VERSION::STRING < '3.1.'
|
36
|
+
association_reflection.klass.reflections[association_reflection.options[:as]].options[:foreign_type]
|
37
|
+
else
|
38
|
+
association_reflection.type
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def join_table(association_reflection)
|
43
|
+
if ActiveRecord::VERSION::STRING < '4.1' && ActiveRecord::VERSION::STRING >= '4.0'
|
44
|
+
association_reflection.join_table
|
45
|
+
else
|
46
|
+
association_reflection.options[:join_table]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def find_relationships
|
51
|
+
models = ActiveRecord::Base.descendants
|
52
|
+
models.each do |model|
|
53
|
+
model.reflections.each do |assoc, assoc_reflect|
|
54
|
+
relationship = case assoc_reflect.macro
|
55
|
+
when :has_many
|
56
|
+
has_many(model, assoc_reflect)
|
57
|
+
when :belongs_to
|
58
|
+
belongs_to(model, assoc_reflect)
|
59
|
+
when :has_and_belongs_to_many
|
60
|
+
has_and_belongs_to_many(model, assoc_reflect)
|
61
|
+
else
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
yield(relationship) if relationship
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def has_and_belongs_to_many(model, association_reflection)
|
70
|
+
if ActiveRecord::VERSION::STRING < '4.1.'
|
71
|
+
ForeignKeyRelationship.new(
|
72
|
+
model.table_name,
|
73
|
+
model.primary_key,
|
74
|
+
join_table(association_reflection),
|
75
|
+
association_reflection.send(foreign_key_method)
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def has_many(model, association_reflection)
|
81
|
+
# Were checking for polymorphic associations
|
82
|
+
if association_reflection.options[:as]
|
83
|
+
ForeignKeyRelationship.new(
|
84
|
+
model.table_name,
|
85
|
+
model.primary_key,
|
86
|
+
association_reflection.table_name,
|
87
|
+
association_reflection.send(foreign_key_method),
|
88
|
+
polymorphic_type(association_reflection)
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def belongs_to(model, association_reflection)
|
94
|
+
if !association_reflection.options[:polymorphic] &&
|
95
|
+
!(model.name.include?("HABTM_") && association_reflection.name == :left_side)
|
96
|
+
ForeignKeyRelationship.new(
|
97
|
+
association_reflection.table_name,
|
98
|
+
association_reflection.klass.primary_key,
|
99
|
+
model.table_name,
|
100
|
+
association_reflection.send(foreign_key_method)
|
101
|
+
)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Chartio
|
2
|
+
class TestFormatter
|
3
|
+
|
4
|
+
attr_accessor :foreign_keys
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@foreign_keys = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def <<(fk)
|
11
|
+
@foreign_keys << fk
|
12
|
+
end
|
13
|
+
|
14
|
+
def output_report
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_key(search_options = {})
|
19
|
+
find(:find, search_options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_keys(search_options = {})
|
23
|
+
find(:find_all, search_options)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def find(find_type, search_options)
|
29
|
+
foreign_keys.send(find_type) { |x|
|
30
|
+
search_options.inject(true) do |boolean, option|
|
31
|
+
boolean && x.send(option[0]) == option[1]
|
32
|
+
end
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Chartio Rails" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@test_formatter = Chartio::TestFormatter.new
|
7
|
+
@schema = Chartio::Schema.new(@test_formatter)
|
8
|
+
@schema.output_report
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should handle a belongs_to relationship" do
|
12
|
+
expected_key = {
|
13
|
+
:parent_table => 'accounts',
|
14
|
+
:parent_primary_key => 'id',
|
15
|
+
:child_table => 'users',
|
16
|
+
:child_foreign_key => 'account_id',
|
17
|
+
:polymorphic_field => nil
|
18
|
+
}
|
19
|
+
fk = @test_formatter.find_key(expected_key)
|
20
|
+
expect(fk).to be_truthy
|
21
|
+
expect(fk.to_h).to match(expected_key)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should handle a has_and_belongs_to_many" do
|
25
|
+
fks = @test_formatter.find_keys(:child_table => 'assemblies_parts')
|
26
|
+
expect(fks.length).to eq(2)
|
27
|
+
expect(fks.map(&:to_h)).to match_array([
|
28
|
+
{
|
29
|
+
:parent_table => 'parts',
|
30
|
+
:parent_primary_key => 'id',
|
31
|
+
:child_table => 'assemblies_parts',
|
32
|
+
:child_foreign_key => 'part_id',
|
33
|
+
:polymorphic_field => nil
|
34
|
+
},
|
35
|
+
{
|
36
|
+
:parent_table => 'assemblies',
|
37
|
+
:parent_primary_key => 'id',
|
38
|
+
:child_table => 'assemblies_parts',
|
39
|
+
:child_foreign_key => 'assembly_id',
|
40
|
+
:polymorphic_field => nil
|
41
|
+
}
|
42
|
+
])
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should output a polymorphic assocation" do
|
46
|
+
fks = @test_formatter.find_keys(:polymorphic_field => 'imageable_type')
|
47
|
+
expect(fks.length).to eq(2)
|
48
|
+
expect(fks.map(&:to_h)).to match_array([
|
49
|
+
{
|
50
|
+
parent_table: 'employees',
|
51
|
+
parent_primary_key: 'id',
|
52
|
+
child_table: 'pictures',
|
53
|
+
child_foreign_key: 'imageable_id',
|
54
|
+
polymorphic_field: 'imageable_type'
|
55
|
+
},
|
56
|
+
{
|
57
|
+
parent_table: 'products',
|
58
|
+
parent_primary_key: 'id',
|
59
|
+
child_table: 'pictures',
|
60
|
+
child_foreign_key: 'imageable_id',
|
61
|
+
polymorphic_field: 'imageable_type'
|
62
|
+
}
|
63
|
+
])
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should handle belongs_to overrides" do
|
67
|
+
fks = @test_formatter.find_keys(:child_table => 'orders', :child_foreign_key => 'user_id')
|
68
|
+
expect(fks.length).to eq(1)
|
69
|
+
expect(fks.map(&:to_h)).to match_array([
|
70
|
+
{
|
71
|
+
parent_table: 'users',
|
72
|
+
parent_primary_key: 'id',
|
73
|
+
child_table: 'orders',
|
74
|
+
child_foreign_key: 'user_id',
|
75
|
+
polymorphic_field: nil
|
76
|
+
}
|
77
|
+
])
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "CSV Formatter" do
|
4
|
+
|
5
|
+
it "should output a header if no schema is provided" do
|
6
|
+
allow(ActiveRecord::Base).to receive(:descendants) { [] }
|
7
|
+
csv = CSV.parse(output_csv)
|
8
|
+
expect(csv.length).to eq(1)
|
9
|
+
first_row_should_be_header(csv)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with a full schema" do
|
13
|
+
|
14
|
+
before(:all) do
|
15
|
+
@csv = CSV.parse(output_csv)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should complete successfully" do
|
19
|
+
expect(@csv.length).to eq(11)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should output a has_and_belongs_to_many association" do
|
23
|
+
results = @csv.find_all do |x|
|
24
|
+
x == ["parts", "id", "assemblies_parts", "part_id", nil] ||
|
25
|
+
x == ["assemblies", "id", "assemblies_parts", "assembly_id", nil]
|
26
|
+
end
|
27
|
+
expect(results.length).to eq(2)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should output a self join" do
|
31
|
+
results = @csv.find_all { |x| x == ["employees", "id", "employees", "manager_id", nil] }
|
32
|
+
expect(results.length).to eq(1)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def first_row_should_be_header(csv)
|
40
|
+
expect(csv[0]).to match_array(Chartio::ForeignKeyRelationship::FIELDS.map(&:to_s))
|
41
|
+
end
|
42
|
+
|
43
|
+
def output_csv
|
44
|
+
csv_formatter = Chartio::CSVFormatter.new
|
45
|
+
schema = Chartio::Schema.new(csv_formatter)
|
46
|
+
schema.output_report
|
47
|
+
end
|
data/spec/example_app.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
class Account < ActiveRecord::Base
|
2
|
+
has_many :users
|
3
|
+
has_one :account_history
|
4
|
+
end
|
5
|
+
|
6
|
+
class AccountHistory < ActiveRecord::Base
|
7
|
+
belongs_to :account
|
8
|
+
end
|
9
|
+
|
10
|
+
class Supplier < ActiveRecord::Base
|
11
|
+
has_one :account_history, through: :account
|
12
|
+
end
|
13
|
+
|
14
|
+
class User < ActiveRecord::Base
|
15
|
+
belongs_to :account
|
16
|
+
end
|
17
|
+
|
18
|
+
class Employee < ActiveRecord::Base
|
19
|
+
has_many :subordinates, class_name: "Employee", foreign_key: "manager_id"
|
20
|
+
belongs_to :manager, class_name: "Employee"
|
21
|
+
|
22
|
+
has_many :pictures, :as => :imageable
|
23
|
+
end
|
24
|
+
|
25
|
+
class Product < ActiveRecord::Base
|
26
|
+
has_many :pictures, :as => :imageable
|
27
|
+
end
|
28
|
+
|
29
|
+
class Picture < ActiveRecord::Base
|
30
|
+
belongs_to :imageable, :polymorphic => :true
|
31
|
+
end
|
32
|
+
|
33
|
+
class Assembly < ActiveRecord::Base
|
34
|
+
has_and_belongs_to_many :parts
|
35
|
+
end
|
36
|
+
|
37
|
+
class Part < ActiveRecord::Base
|
38
|
+
has_and_belongs_to_many :assemblies
|
39
|
+
end
|
40
|
+
|
41
|
+
class Physician < ActiveRecord::Base
|
42
|
+
has_many :appointments
|
43
|
+
has_many :patients, :through => :appointments
|
44
|
+
end
|
45
|
+
|
46
|
+
class Appointment < ActiveRecord::Base
|
47
|
+
belongs_to :physician
|
48
|
+
belongs_to :patient
|
49
|
+
end
|
50
|
+
|
51
|
+
class Patient < ActiveRecord::Base
|
52
|
+
has_many :appointments
|
53
|
+
has_many :physicians, :through => :appointments
|
54
|
+
end
|
55
|
+
|
56
|
+
class Order < ActiveRecord::Base
|
57
|
+
belongs_to :customer, class_name: "User", foreign_key: "user_id"
|
58
|
+
end
|
data/spec/schema.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
ActiveRecord::Migration.verbose = false
|
2
|
+
|
3
|
+
ActiveRecord::Schema.define do
|
4
|
+
create_table :accounts do |t|
|
5
|
+
t.string :name
|
6
|
+
end
|
7
|
+
|
8
|
+
create_table :account_histories do |t|
|
9
|
+
t.integer :account_id
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table :suppliers do |t|
|
13
|
+
t.string :name
|
14
|
+
end
|
15
|
+
|
16
|
+
create_table :users do |t|
|
17
|
+
t.string :name
|
18
|
+
t.integer :account_id
|
19
|
+
end
|
20
|
+
|
21
|
+
create_table :employees do |t|
|
22
|
+
t.integer :manager_id
|
23
|
+
end
|
24
|
+
|
25
|
+
create_table :products do |t|
|
26
|
+
end
|
27
|
+
|
28
|
+
create_table :pictures do |t|
|
29
|
+
t.integer :imageable_id
|
30
|
+
t.string :imageable_type
|
31
|
+
end
|
32
|
+
|
33
|
+
create_table :assemblies do |t|
|
34
|
+
end
|
35
|
+
|
36
|
+
create_table :assemblies_parts, :id => false do |t|
|
37
|
+
t.integer :assembly_id
|
38
|
+
t.integer :part_id
|
39
|
+
end
|
40
|
+
|
41
|
+
create_table :parts do |t|
|
42
|
+
end
|
43
|
+
|
44
|
+
create_table :physicians do |t|
|
45
|
+
end
|
46
|
+
|
47
|
+
create_table :appointments do |t|
|
48
|
+
t.integer :physician_id
|
49
|
+
t.integer :patient_id
|
50
|
+
end
|
51
|
+
|
52
|
+
create_table :orders do |t|
|
53
|
+
t.integer :user_id
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
Bundler.require(:default)
|
4
|
+
require 'pry'
|
5
|
+
require 'chartio/test_formatter'
|
6
|
+
|
7
|
+
lib = File.expand_path('../spec', __FILE__)
|
8
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
config.before(:suite) do
|
13
|
+
ActiveRecord::Base.establish_connection({
|
14
|
+
:adapter => 'sqlite3',
|
15
|
+
:database => ':memory:'
|
16
|
+
})
|
17
|
+
load File.dirname(__FILE__) + '/schema.rb'
|
18
|
+
require "example_app"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/tasks/chartio.rake
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
namespace :chartio do
|
2
|
+
desc "Generate a chartio schema"
|
3
|
+
task :schema => :environment do
|
4
|
+
runner = Chartio::Schema.new
|
5
|
+
timestamp = Time.now.strftime("%Y%m%d%H%M")
|
6
|
+
runner.crawl(
|
7
|
+
"chartio_schema_#{timestamp}.csv",
|
8
|
+
"chartio_schema_#{timestamp}.log"
|
9
|
+
)
|
10
|
+
puts "All done!"
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chartio-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rimas Silkaitis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.3.8
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.8
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: wwtd
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.5.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.5.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Helper functions for getting your Rails database hooked up to Chartio
|
112
|
+
email:
|
113
|
+
- rimas@chartio.com
|
114
|
+
executables:
|
115
|
+
- chartio-rails
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/chartio-rails
|
126
|
+
- chartio-rails.gemspec
|
127
|
+
- gemfiles/rails3.gemfile
|
128
|
+
- gemfiles/rails31.gemfile
|
129
|
+
- gemfiles/rails32.gemfile
|
130
|
+
- gemfiles/rails40.gemfile
|
131
|
+
- gemfiles/rails41.gemfile
|
132
|
+
- lib/chartio-rails.rb
|
133
|
+
- lib/chartio/csv_formatter.rb
|
134
|
+
- lib/chartio/foreign_key_relationship.rb
|
135
|
+
- lib/chartio/formatter.rb
|
136
|
+
- lib/chartio/railtie.rb
|
137
|
+
- lib/chartio/schema.rb
|
138
|
+
- lib/chartio/test_formatter.rb
|
139
|
+
- lib/chartio/version.rb
|
140
|
+
- spec/chartio_rails_spec.rb
|
141
|
+
- spec/csv_formatter_spec.rb
|
142
|
+
- spec/example_app.rb
|
143
|
+
- spec/schema.rb
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
- tasks/chartio.rake
|
146
|
+
homepage: https://chartio.com/
|
147
|
+
licenses:
|
148
|
+
- MIT
|
149
|
+
metadata: {}
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options: []
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
requirements: []
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 2.2.0
|
167
|
+
signing_key:
|
168
|
+
specification_version: 4
|
169
|
+
summary: Helper functions for getting your Rails database hooked up to Chartio
|
170
|
+
test_files:
|
171
|
+
- spec/chartio_rails_spec.rb
|
172
|
+
- spec/csv_formatter_spec.rb
|
173
|
+
- spec/example_app.rb
|
174
|
+
- spec/schema.rb
|
175
|
+
- spec/spec_helper.rb
|