rails_erd_viewer 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 57e5bc9a196ae2b3a355691d443a910b14303c0f72974d723c12ad9612213dd6
4
+ data.tar.gz: 814b1568381750e9b4cf5a4f379a7a861c8feab0126decf9ed20953ef846cb37
5
+ SHA512:
6
+ metadata.gz: '06391e090974a2768d70fd3363cc722876f6546ac4947687b2001b4d17c00491a143d1526eda6e73b34620800555703058cecd10db9e975a2d044c772acf00a5'
7
+ data.tar.gz: adb1aeecee36b7cec8d6f593977990b2defad29a60f6246db0d7709b69a5b29279c8fcaf55fb0983bf279647400431c5adb04760c5becfb5b768ce997b3ac21f
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # Changelog
2
+ ## 0.1.1 (18-Nov-24)
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ case rails_version = ENV.fetch('RAILS_VERSION', nil)
8
+ when nil
9
+ gem 'rails'
10
+ when 'edge'
11
+ gem 'rails', github: 'rails/rails'
12
+ else
13
+ gem 'rails', "~> #{rails_version}.0"
14
+ end
15
+
16
+ gem 'codecov'
17
+ gem 'rails-controller-testing'
18
+ gem 'rake'
19
+ gem 'rspec'
20
+ gem 'rspec-rails'
21
+ gem 'rubocop'
22
+ gem 'rubocop-performance'
23
+ gem 'rubocop-rails'
24
+ gem 'rubocop-rake'
25
+ gem 'rubocop-rspec'
26
+ gem 'rubocop-rspec_rails'
27
+ gem 'simplecov'
28
+ gem 'sprockets-rails'
29
+ gem 'sqlite3'
30
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Lokalise team, Ilya Bodrov
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 NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Rails ERD Viewer
2
+
3
+ Rails ERD Viewer automatically generates Entity-Relationship Diagrams from your ActiveRecord and displays them
4
+ using [erd-editor](https://github.com/dineug/erd-editor).
5
+
6
+ ---
7
+
8
+ ### Install
9
+
10
+ Add this to the development group in your `Gemfile`:
11
+
12
+ ```ruby
13
+ group :development do
14
+ gem 'rails_erd_viewer', '~> 0.1.0'
15
+ end
16
+ ```
17
+
18
+ ---
19
+
20
+ ### Usage
21
+
22
+ Run `rails erd:generate`.
23
+
24
+ Then visit `/erd-viewer`
25
+
26
+
27
+ ---
28
+
29
+ ### Automatic ERD Generation
30
+
31
+ The ERD generation will happen automatically in the following situations:
32
+
33
+ - **After running migrations**: Every time you execute `rails db:migrate`, `rails db:reset`, or `rails db:redo`, the ERD diagram will be automatically generated, reflecting changes in the database.
34
+ - **After a rollback**: Whenever you run `rails db:rollback`, the ERD diagram will be regenerated to reflect the current state of the database.
35
+
36
+ This ensures that the ERD diagram is always up-to-date, reflecting changes in the database structure without the need for additional commands.
37
+
38
+ ---
39
+
40
+ ### Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wptussolini/rails_erd_viewer.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake'
4
+ begin
5
+ require 'bundler/setup'
6
+ Bundler::GemHelper.install_tasks
7
+ rescue LoadError
8
+ puts 'although not required, bundler is recommended for running the tests'
9
+ end
10
+ task default: :spec
11
+
12
+ require 'rspec/core/rake_task'
13
+ RSpec::Core::RakeTask.new(:spec)
14
+
15
+ require 'rubocop/rake_task'
16
+ RuboCop::RakeTask.new do |task|
17
+ task.requires << 'rubocop-performance'
18
+ task.requires << 'rubocop-rspec'
19
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsErdViewer
4
+ # RailsErdViewer::Engine
5
+ class Engine < Rails::Engine
6
+ isolate_namespace RailsErdViewer
7
+
8
+ initializer 'rails_erd_viewer.assets.precompile' do |app|
9
+ app.config.assets.precompile += %w[
10
+ rails_erd_viewer/application.js
11
+ ]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_erd_viewer'
4
+ require 'rails'
5
+
6
+ module RailsErdViewer
7
+ # RailsErdViewer::Railtie
8
+ class Railtie < Rails::Railtie
9
+ railtie_name :rails_erd_viewer
10
+
11
+ rake_tasks do
12
+ path = File.expand_path(__dir__)
13
+ Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsErdViewer
4
+ # ERDGenerator
5
+ class SchemaGenerator
6
+ def self.generate
7
+ file_path = Rails.root.join('tmp/application_schema.sql')
8
+ File.open(file_path, 'w') do |file|
9
+ ActiveRecord::Base.connection.tables.each do |table_name|
10
+ columns = ActiveRecord::Base.connection.columns(table_name)
11
+
12
+ add_table_to_file(file, table_name, columns)
13
+
14
+ add_foreign_keys_to_file(file, table_name)
15
+ end
16
+ end
17
+ end
18
+
19
+ def self.add_table_to_file(file, table_name, columns)
20
+ file.write "CREATE TABLE #{table_name} (\n"
21
+ add_columns_to_file(file, columns)
22
+ file.write " PRIMARY KEY (id)\n" if columns.any? { |c| c.name == 'id' }
23
+ file.write ");\n\n"
24
+ end
25
+
26
+ def self.add_foreign_keys_to_file(file, table_name)
27
+ foreign_keys = ActiveRecord::Base.connection.foreign_keys(table_name)
28
+ foreign_keys.each do |fk|
29
+ file.write(
30
+ "ALTER TABLE #{fk.from_table} ADD FOREIGN KEY (#{fk.column}) " \
31
+ "REFERENCES #{fk.to_table} (#{fk.primary_key});\n"
32
+ )
33
+ end
34
+ end
35
+
36
+ def self.add_columns_to_file(file, columns)
37
+ columns_count = columns.size
38
+ columns.each_with_index do |column, index|
39
+ column_end = index == columns_count - 1 ? '' : ','
40
+ add_column_to_file(file, column, column_end)
41
+ end
42
+ end
43
+
44
+ def self.add_column_to_file(file, column, column_end)
45
+ type = get_column_type(column)
46
+
47
+ null_constraint = column.null ? '' : ' NOT NULL'
48
+ default_constraint = column.default.nil? ? '' : " DEFAULT #{column.default.inspect}"
49
+
50
+ file.write " #{column.name} #{type}#{null_constraint}#{default_constraint}#{column_end}\n"
51
+ end
52
+
53
+ def self.get_column_type(column)
54
+ column_type_map[column.type] || 'unknown'
55
+ end
56
+
57
+ def self.column_type_map
58
+ {
59
+ string: 'varchar(255)', text: 'text', integer: 'integer(11)', float: 'float', decimal: 'decimal(10,2)',
60
+ datetime: 'datetime', boolean: 'boolean', date: 'date', time: 'time'
61
+ }
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsErdViewer
4
+ VERSION = '0.1.1'
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'rails_erd_viewer/version'
4
+ require 'rails_erd_viewer/engine'
5
+ require_relative 'rails_erd_viewer/schema_generator'
6
+ module RailsErdViewer
7
+ require 'rails_erd_viewer/railtie' if defined?(Rails)
8
+ class MissingErdSchemaError < StandardError; end
9
+ end
data/lib/tasks/db.rake ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :db do
4
+ namespace :migrate do
5
+ %i[change up down reset redo].each do |t|
6
+ task t => :environment do # rubocop:disable
7
+ RailsErdViewer::SchemaGenerator.generate
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :erd do
4
+ desc 'Generate ERD Schema of the Database'
5
+ task generate: :environment do
6
+ RailsErdViewer::SchemaGenerator.generate
7
+ puts 'ERD Schema generated successfully. You can view it at: http://localhost:3000/erd-viewer'
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('lib/rails_erd_viewer/version', __dir__)
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'rails_erd_viewer'
6
+ spec.version = RailsErdViewer::VERSION
7
+ spec.authors = ['Phelipe Tussolini']
8
+ spec.email = ['wp.tussolini@gmail.com']
9
+ spec.summary = 'A gem to visualize Entity-Relationship Diagram from your rails application.'
10
+ spec.description = 'RailsERD Viewer helps developers visualize ERDs, making database relationships clearer.'
11
+ spec.homepage = 'https://github.com/wptussolini/rails-erd'
12
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
13
+ spec.license = 'MIT'
14
+ spec.platform = Gem::Platform::RUBY
15
+ spec.required_ruby_version = '>= 2.5.0'
16
+ spec.files = Dir['README.md', 'LICENSE',
17
+ 'CHANGELOG.md', 'lib/**/*.rb',
18
+ 'lib/**/*.rake',
19
+ 'rails_erd_viewer.gemspec', '.github/*.md',
20
+ 'Gemfile', 'Rakefile']
21
+ spec.extra_rdoc_files = ['README.md']
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
23
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_erd_viewer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Phelipe Tussolini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-11-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: RailsERD Viewer helps developers visualize ERDs, making database relationships
14
+ clearer.
15
+ email:
16
+ - wp.tussolini@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.md
21
+ files:
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - lib/rails_erd_viewer.rb
28
+ - lib/rails_erd_viewer/engine.rb
29
+ - lib/rails_erd_viewer/railtie.rb
30
+ - lib/rails_erd_viewer/schema_generator.rb
31
+ - lib/rails_erd_viewer/version.rb
32
+ - lib/tasks/db.rake
33
+ - lib/tasks/generate_erd.rake
34
+ - rails_erd_viewer.gemspec
35
+ homepage: https://github.com/wptussolini/rails-erd
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ allowed_push_host: https://rubygems.org
40
+ rubygems_mfa_required: 'true'
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.5.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.5.23
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: A gem to visualize Entity-Relationship Diagram from your rails application.
60
+ test_files: []