database_documenter 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -2
- data/lib/database_documenter.rb +2 -0
- data/lib/database_documenter/exporters/base_exporter.rb +29 -0
- data/lib/database_documenter/exporters/export_to_md.rb +76 -0
- data/lib/database_documenter/exporters/export_to_word.rb +3 -19
- data/lib/database_documenter/railtie.rb +1 -0
- data/lib/database_documenter/version.rb +1 -1
- data/lib/tasks/generate_db_md_document.rake +6 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56031ec9b99ec64b5212f3eada1f4b576d36f36ec3967fd270a3c80b2714d32a
|
4
|
+
data.tar.gz: b0054f9a664ef63947afa1f3ea1545721369463812334d9e497424bfbe0b9334
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 564ccee8d6051584a010bb03897e432809d972bae8f6ad1bf8cfe850e6002a46072b7bfa35cfcdd93cf529ef77ff8c6739b131b085a3f4a630684ee3efbd14fd
|
7
|
+
data.tar.gz: 0704b340ecc3c62bcb39609b3216bbbba7a523eb0b25b05253037d77166c327dcc8059fb921620ede41ba496e6e4740863f4c9b0ab265261bb8a6381a98388aa
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Welcome to Database Documenter gem! We created this gem to generate database doc
|
|
4
4
|
|
5
5
|
## Features
|
6
6
|
|
7
|
-
1. Generate database documentation as a Word document
|
7
|
+
1. Generate database documentation as a `Word document` or `Markdown file`.
|
8
8
|
2. Generate Description for columns based on it is type and name, Also handle Enums and STI and AASM.
|
9
9
|
3. Easy to change the generated description by adding a comment on your database.
|
10
10
|
4. Hide sample values of desired columns using configuration.
|
@@ -39,10 +39,18 @@ end
|
|
39
39
|
|
40
40
|
## Usage
|
41
41
|
|
42
|
-
|
42
|
+
### To Generate the Word document
|
43
|
+
|
44
|
+
In the application directory run this rake task and then you will find a word document named `database.docx` in your application directory:
|
43
45
|
|
44
46
|
$ bundle exec rake generate_db_document
|
45
47
|
|
48
|
+
### To Generate the Markdown file
|
49
|
+
|
50
|
+
Run the following rake task and then you will find a markdown file named `database.md` in your application directory:
|
51
|
+
|
52
|
+
$ bundle exec rake generate_db_md_document
|
53
|
+
|
46
54
|
## Override generated description
|
47
55
|
You can override it by adding comment to your schema using one of the following options:
|
48
56
|
|
@@ -63,3 +71,4 @@ use `change_column_comment` and `change_table_comment` methods in rails 5
|
|
63
71
|
|
64
72
|
- Generate the ERD with the file.
|
65
73
|
- Add test cases.
|
74
|
+
- Update `DatabaseDocumenter::TableDat`a to return the `sql_code` as a `String`.
|
data/lib/database_documenter.rb
CHANGED
@@ -7,7 +7,9 @@ require 'database_documenter/database_comment/postgres_database_comment'
|
|
7
7
|
require 'database_documenter/tables_sql'
|
8
8
|
require 'database_documenter/column_description'
|
9
9
|
require 'database_documenter/table_data'
|
10
|
+
require 'database_documenter/exporters/base_exporter'
|
10
11
|
require 'database_documenter/exporters/export_to_word'
|
12
|
+
require 'database_documenter/exporters/export_to_md'
|
11
13
|
require 'caracal'
|
12
14
|
require "database_documenter/railtie" if defined?(Rails)
|
13
15
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseDocumenter::Exporters
|
4
|
+
class BaseExporter
|
5
|
+
attr_accessor :table_data, :printed_tables, :generated_cols_count, :commented_cols_count
|
6
|
+
|
7
|
+
APP_NAME = ENV['APP_NAME'].capitalize
|
8
|
+
HEADER_SECOND_LINE = "The database design specifies how the data of the software is going to be stored."
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.table_data = DatabaseDocumenter::TableData.new
|
12
|
+
self.printed_tables = []
|
13
|
+
self.generated_cols_count = 0
|
14
|
+
self.commented_cols_count = 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_all_models
|
18
|
+
Rails.application.eager_load!
|
19
|
+
end
|
20
|
+
|
21
|
+
# Skip STI classes
|
22
|
+
# Skip duplicate tables in case of has_and_belongs_to_many
|
23
|
+
# Skip certain modules
|
24
|
+
def skip_class?(klass)
|
25
|
+
(klass.class_name != klass.base_class.class_name) || klass.abstract_class? ||
|
26
|
+
(printed_tables.include? klass.table_name) || (DatabaseDocumenter.configuration.skipped_modules.include? klass.parent.name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DatabaseDocumenter::Exporters
|
4
|
+
class ExportToMd < BaseExporter
|
5
|
+
def call
|
6
|
+
load_all_models
|
7
|
+
generate_md_document
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_md_document
|
11
|
+
md_file_header = StringIO.new
|
12
|
+
md_file_body = StringIO.new
|
13
|
+
md_file = File.open("database.md", "w")
|
14
|
+
|
15
|
+
generate_md_file_header(md_file_header)
|
16
|
+
|
17
|
+
ActiveRecord::Base.descendants.each do |klass|
|
18
|
+
next if skip_class?(klass)
|
19
|
+
|
20
|
+
generate_table_metadata(md_file_header, md_file_body, klass)
|
21
|
+
generate_table_columns(md_file_body, klass)
|
22
|
+
end
|
23
|
+
md_file.puts md_file_header.string
|
24
|
+
md_file.puts md_file_body.string
|
25
|
+
md_file.close
|
26
|
+
end
|
27
|
+
|
28
|
+
def generate_md_file_header(md_file_header)
|
29
|
+
md_file_header << "# #{APP_NAME} Database Design\n"
|
30
|
+
md_file_header << "#{HEADER_SECOND_LINE}\n"
|
31
|
+
md_file_header << "# Tables \n"
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate_table_metadata(md_file_header, md_file_body, klass)
|
35
|
+
metadata = table_data.get_meta_data(klass)
|
36
|
+
|
37
|
+
md_file_header << "- [#{klass.table_name}](##{klass.table_name})\n"
|
38
|
+
|
39
|
+
md_file_body << "\n"
|
40
|
+
md_file_body << "## #{klass.table_name}\n"
|
41
|
+
md_file_body << "### Table details\n"
|
42
|
+
md_file_body << "|Key|Value|\n"
|
43
|
+
md_file_body << "|---|---|\n"
|
44
|
+
md_file_body << "|Table Name|#{metadata[:name]}|\n"
|
45
|
+
md_file_body << "|Description|#{metadata[:description]}|\n"
|
46
|
+
md_file_body << "|Primary Key|#{metadata[:primary_key]}|\n"
|
47
|
+
|
48
|
+
md_file_body << "\n"
|
49
|
+
|
50
|
+
# TODO: Update DatabaseDocumenter::TableData to return this value as a String
|
51
|
+
# And let every Exporter renders it according to the required format
|
52
|
+
sql_code = metadata[:sql_code].contents.map(&:runs).map(&:first).map(&:text_content).join("\n")
|
53
|
+
md_file_body << "### Table SQL Code\n"
|
54
|
+
md_file_body << "```SQL\n"
|
55
|
+
md_file_body << "#{sql_code}\n"
|
56
|
+
md_file_body << "```\n"
|
57
|
+
end
|
58
|
+
|
59
|
+
def generate_table_columns(md_file_body, klass)
|
60
|
+
columns_data = table_data.get_columns_data(klass)
|
61
|
+
|
62
|
+
md_file_body << "### Table attributes\n"
|
63
|
+
md_file_body << "|Attribute|Description|Type|Example of values|\n"
|
64
|
+
md_file_body << "|---|---|---|---|\n"
|
65
|
+
|
66
|
+
columns_data.each do |col|
|
67
|
+
description = StringIO.new
|
68
|
+
col[:description].each do |column_description|
|
69
|
+
description << "- #{column_description}\n"
|
70
|
+
end
|
71
|
+
md_file_body.puts "|#{col[:name]}|#{col[:description][0]}|#{col[:type]}|#{col[:value]}|\n"
|
72
|
+
end
|
73
|
+
md_file_body.puts "\n"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -1,34 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module DatabaseDocumenter::Exporters
|
4
|
-
class ExportToWord
|
5
|
-
attr_accessor :table_data, :printed_tables, :generated_cols_count, :commented_cols_count
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
self.table_data = DatabaseDocumenter::TableData.new
|
9
|
-
self.printed_tables = []
|
10
|
-
self.generated_cols_count = 0
|
11
|
-
self.commented_cols_count = 0
|
12
|
-
end
|
13
|
-
|
4
|
+
class ExportToWord < BaseExporter
|
14
5
|
def call
|
15
6
|
load_all_models
|
16
7
|
generate_word_document
|
17
8
|
end
|
18
9
|
|
19
|
-
def load_all_models
|
20
|
-
Rails.application.eager_load!
|
21
|
-
end
|
22
|
-
|
23
10
|
def generate_word_document
|
24
11
|
Caracal::Document.save 'database.docx' do |docx|
|
25
12
|
add_word_header(docx)
|
26
13
|
add_word_footer(docx)
|
27
14
|
|
28
15
|
ActiveRecord::Base.descendants.each do |klass|
|
29
|
-
# Skip STI classes
|
30
|
-
# Skip duplicate tables in case of has_and_belongs_to_many
|
31
|
-
# Skip certain modules
|
32
16
|
next if skip_class?(klass)
|
33
17
|
|
34
18
|
printed_tables << klass.table_name
|
@@ -51,8 +35,8 @@ module DatabaseDocumenter::Exporters
|
|
51
35
|
end
|
52
36
|
|
53
37
|
def add_word_header(docx)
|
54
|
-
docx.h1 "Database Design"
|
55
|
-
docx.p
|
38
|
+
docx.h1 "#{APP_NAME} Database Design"
|
39
|
+
docx.p HEADER_SECOND_LINE
|
56
40
|
end
|
57
41
|
|
58
42
|
def skip_class?(klass)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_documenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmed Yehia
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,12 +134,15 @@ files:
|
|
134
134
|
- lib/database_documenter/database_comment/base_database_comment.rb
|
135
135
|
- lib/database_documenter/database_comment/mysql_database_comment.rb
|
136
136
|
- lib/database_documenter/database_comment/postgres_database_comment.rb
|
137
|
+
- lib/database_documenter/exporters/base_exporter.rb
|
138
|
+
- lib/database_documenter/exporters/export_to_md.rb
|
137
139
|
- lib/database_documenter/exporters/export_to_word.rb
|
138
140
|
- lib/database_documenter/railtie.rb
|
139
141
|
- lib/database_documenter/table_data.rb
|
140
142
|
- lib/database_documenter/tables_sql.rb
|
141
143
|
- lib/database_documenter/version.rb
|
142
144
|
- lib/tasks/generate_db_document.rake
|
145
|
+
- lib/tasks/generate_db_md_document.rake
|
143
146
|
- lib/tasks/generate_dd_initializer.rake
|
144
147
|
- lib/tasks/templates/database_documenter.rb
|
145
148
|
homepage: https://github.com/espace/db_documenter
|