dbgrapher 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 216e0bf448c9a04b8878009c8d74bcac49ef2a59ed242f14f6f224bd94200157
4
+ data.tar.gz: '08cdfb6be53b59e0a3bbf643dd1dacf171ec2e85a89ef720f9aa3a007dd113ae'
5
+ SHA512:
6
+ metadata.gz: 29914d7a7c53ced3cb7a15ed449f916f1aa3527d39cd5318a46b04eb603bba62dcd4287e1c44bef036d9b9b46bb93490d15efada9fc2c364b3fa1fcc7b441f75
7
+ data.tar.gz: 920a12eb8ee1ae88e79facbd75a9be1e71cb275f594a213884478fd744f623d158d000488643dd8c6da29212101beb4210b5b9e4cc8a300a6714daf1d7196c34
data/.github/env.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "googleDrive": {
3
+ "developerKey": "",
4
+ "clientId": "",
5
+ "appId": ""
6
+ },
7
+ "oneDrive": {
8
+ "clientId": ""
9
+ }
10
+ }
@@ -0,0 +1,20 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+ branches: [master]
8
+
9
+ jobs:
10
+ cd:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
14
+ - uses: actions/checkout@v2
15
+ - uses: actions/setup-ruby@v1
16
+ with:
17
+ ruby-version: '2.7'
18
+ - run: bundle
19
+ - run: bundle exec rspec
20
+
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dbgrapher.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0", :groups => [:test]
8
+ gem "byebug", "~> 11.1", :groups => [:development, :test]
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dbgrapher (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (11.1.3)
10
+ diff-lcs (1.4.4)
11
+ rake (12.3.3)
12
+ rspec (3.10.0)
13
+ rspec-core (~> 3.10.0)
14
+ rspec-expectations (~> 3.10.0)
15
+ rspec-mocks (~> 3.10.0)
16
+ rspec-core (3.10.1)
17
+ rspec-support (~> 3.10.0)
18
+ rspec-expectations (3.10.1)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.10.0)
21
+ rspec-mocks (3.10.2)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-support (3.10.2)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ byebug (~> 11.1)
31
+ dbgrapher!
32
+ rake (~> 12.0)
33
+ rspec (~> 3.0)
34
+
35
+ BUNDLED WITH
36
+ 2.1.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Ara Yeressian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ [![CI](https://github.com/ayeressian/dbgrapher_gem/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/ayeressian/dbgrapher_gem/actions/workflows/ci.yml)
2
+
3
+ # Dbgrapher
4
+
5
+ This is a library that provides rake task to be used with rails application to generate dbgrapher.com db schema file.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dbgrapher'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dbgrapher
22
+
23
+ In the lib/tasks directory create dbgrapher.rake file with the following content
24
+
25
+ ```ruby
26
+ require "dbgrapher/rake_task"
27
+
28
+ Dbgrapher::RakeTask.new()
29
+ ```
30
+
31
+ Then run
32
+
33
+ rake dbgrapher:gen
34
+
35
+ In the `db/schema directory` it will generate `dbgrapher.json` file.
36
+ Now in your browser (preferably chrome) navigate to [dbgrapher.com](https://dbgrapher.com). In the "Please select a cloud provider." dialog select "None". In the following dialog select "Open". Open the `db/schema/dbgrapher.json` file. Move the tables to appropriate positions. Then from "File" top menu select save. In case you're not using chrome you should select "Download" from "File" top menu and copy the downloaded file to the `db/schema/dbgrapher.json`.
37
+ Every time a new table is being added to the database the top procedure should be performed. Note its only necessary to position the newly added tables, the previously positioned table positions are persisted.
38
+ Don't forget to commit your dbgrapher.json file. It contains information about the table positions.
39
+
40
+ ## Development
41
+
42
+ 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.
43
+
44
+ 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).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ayeressian/dbgrapher_gem.
49
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dbgrapher"
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
data/dbgrapher.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ require_relative 'lib/dbgrapher/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "dbgrapher"
5
+ spec.version = Dbgrapher::VERSION
6
+ spec.authors = ["Ara Yeressian"]
7
+ spec.email = ["yeressian@tuta.io"]
8
+
9
+ spec.summary = "This library provides rake task to be used with rails application to generate dbgrapher.com db schema file"
10
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
11
+ # spec.homepage = "TODO: Put your gem's website or public repo URL here."
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
15
+
16
+ # spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/ayeressian/dbgrapher_gem"
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.licenses = ['MIT']
30
+ end
@@ -0,0 +1,53 @@
1
+ module Dbgrapher
2
+ class Generate
3
+ def initialize(schema_path:)
4
+ @schema_path = schema_path
5
+ end
6
+
7
+ def run()
8
+ @result = File.exists?(@schema_path) ?
9
+ JSON.parse(File.read(@schema_path), { :symbolize_names => true }) :
10
+ { tables: [] }
11
+ @deleted_tables = @result[:tables].map { |table| table[:name] }
12
+ ActiveRecord::Base.connection.tables.each(&self.method(:parse_table))
13
+ @result[:tables] = @result[:tables].filter { |table| !@deleted_tables.find { |deleted_table| table[:name] === deleted_table } }
14
+ File.write(@schema_path, JSON.pretty_generate(@result))
15
+ end
16
+
17
+ private
18
+
19
+ def parse_column(column, table_name)
20
+ fks = ActiveRecord::Base.connection.foreign_keys(table_name)
21
+ pks = ActiveRecord::Base.connection.primary_keys(table_name)
22
+ formatted_column = {
23
+ name: column.name,
24
+ type: column.type,
25
+ }
26
+
27
+ fk = fks.find { |fk| fk.options[:column] === column.name }
28
+
29
+ if !fk.nil?
30
+ formatted_column[:fk] = {
31
+ table: fk.to_table,
32
+ column: fk.options[:primary_key],
33
+ }
34
+ end
35
+
36
+ formatted_column[:pk] = true if pks.find { |pk| pk === column.name }
37
+
38
+ formatted_column
39
+ end
40
+
41
+ def parse_table(table_name)
42
+ table = @result[:tables].find { |table| table[:name] === table_name }
43
+ new_table = table.nil?
44
+ @deleted_tables.delete_if { |deleted_table| deleted_table === table_name }
45
+ table ||= {
46
+ name: table_name,
47
+ }
48
+
49
+ table[:columns] = ActiveRecord::Base.connection.columns(table_name).map { |column| parse_column(column, table_name) }
50
+ @result[:tables].push(table) if new_table
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,17 @@
1
+ require "dbgrapher/version"
2
+ require "dbgrapher/generate"
3
+ require "rake"
4
+
5
+ module Dbgrapher
6
+ class RakeTask
7
+ include Rake::DSL
8
+ def initialize(task_namespace: :dbgrapher, schema_path: './db/dbgrapher.json')
9
+ namespace(task_namespace) do
10
+ desc "Generates dbgrapher.json"
11
+ task gen: :environment do
12
+ Dbgrapher::Generate.new(schema_path: schema_path).run
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Dbgrapher
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dbgrapher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ara Yeressian
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-04-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - yeressian@tuta.io
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/env.json"
21
+ - ".github/workflows/ci.yml"
22
+ - ".gitignore"
23
+ - ".rspec"
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE
27
+ - README.md
28
+ - Rakefile
29
+ - bin/console
30
+ - bin/setup
31
+ - dbgrapher.gemspec
32
+ - lib/dbgrapher/generate.rb
33
+ - lib/dbgrapher/rake_task.rb
34
+ - lib/dbgrapher/version.rb
35
+ homepage:
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ source_code_uri: https://github.com/ayeressian/dbgrapher_gem
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.3.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.1.2
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: This library provides rake task to be used with rails application to generate
59
+ dbgrapher.com db schema file
60
+ test_files: []