25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/rails_schema_excel/exporter.rb', line 25
def self.create_a5_format(sheet, table_name, table_data, locale)
green_fill = sheet.styles.add_style(bg_color: GREEN, fg_color: '00', b: true, border: Axlsx::STYLE_THIN_BORDER)
= sheet.styles.add_style(bg_color: GREEN, fg_color: '00', b: true, border: Axlsx::STYLE_THIN_BORDER, alignment: { horizontal: :center })
border_style = sheet.styles.add_style(border: Axlsx::STYLE_THIN_BORDER)
bold_style = sheet.styles.add_style(b: true)
sheet.add_row [I18n.t(:table_info, locale)], style: bold_style
sheet.merge_cells("A1:F1")
[
[I18n.t(:system_name, locale), ''],
[I18n.t(:subsystem_name, locale), ''],
[I18n.t(:schema_name, locale), table_name],
[I18n.t(:logical_table_name, locale), ''],
[I18n.t(:physical_table_name, locale), table_name],
[I18n.t(:remarks, locale), '']
].each do |label, value|
sheet.add_row [label, value], style: [green_fill, border_style]
sheet.merge_cells("B#{sheet.rows.length}:C#{sheet.rows.length}")
end
sheet.add_row []
sheet.add_row [I18n.t(:column_info, locale)], style: bold_style
sheet.merge_cells("A#{sheet.rows.length}:F#{sheet.rows.length}")
sheet.add_row [
I18n.t(:no, locale),
I18n.t(:physical_name, locale),
I18n.t(:data_type, locale),
I18n.t(:not_null, locale),
I18n.t(:default, locale),
I18n.t(:remarks, locale)
], style:
table_data[:columns].each_with_index do |col, idx|
sheet.add_row [
idx + 1,
col[:name],
col[:type],
col[:not_null] ? 'Yes' : '',
col[:default],
''
], style: border_style
end
sheet.add_row []
sheet.add_row [I18n.t(:index_info, locale)], style: bold_style
sheet.merge_cells("A#{sheet.rows.length}:F#{sheet.rows.length}")
sheet.add_row [
I18n.t(:no, locale),
I18n.t(:index_name, locale),
I18n.t(:column_list, locale),
I18n.t(:key, locale),
I18n.t(:unique, locale),
I18n.t(:remarks, locale)
], style:
table_data[:indexes].each_with_index do |idx_data, idx|
sheet.add_row [
idx + 1,
"idx_#{idx_data[:columns]}",
idx_data[:columns],
'',
idx_data[:unique] ? 'Yes' : '',
''
], style: border_style
end
sheet.add_row []
sheet.add_row [I18n.t(:constraint_info, locale)], style: bold_style
sheet.merge_cells("A#{sheet.rows.length}:D#{sheet.rows.length}")
sheet.add_row [
I18n.t(:no, locale),
I18n.t(:constraint_name, locale),
I18n.t(:type, locale),
I18n.t(:constraint_definition, locale)
], style:
if table_data[:columns].any? { |col| col[:name] == 'id' }
sheet.add_row [1, 'PRIMARY', 'PRIMARY KEY', 'id'], style: border_style
end
sheet.add_row []
sheet.add_row [I18n.t(:foreign_key_info, locale)], style: bold_style
sheet.merge_cells("A#{sheet.rows.length}:E#{sheet.rows.length}")
sheet.add_row [
I18n.t(:no, locale),
I18n.t(:foreign_key_name, locale),
I18n.t(:column_list, locale),
I18n.t(:ref_table_name, locale),
I18n.t(:ref_column_list, locale)
], style:
table_data[:foreign_keys].each_with_index do |fk, idx|
sheet.add_row [
idx + 1,
"fk_#{fk[:ref_table]}",
"#{fk[:ref_table]}_id",
fk[:ref_table],
'id'
], style: border_style
end
sheet.add_row []
sheet.add_row [I18n.t(:foreign_key_pk_info, locale)], style: bold_style
sheet.merge_cells("A#{sheet.rows.length}:E#{sheet.rows.length}")
sheet.add_row [
I18n.t(:no, locale),
I18n.t(:foreign_key_name, locale),
I18n.t(:column_list, locale),
I18n.t(:ref_source_table_name, locale),
I18n.t(:ref_source_column_list, locale)
], style:
sheet.add_row []
sheet.add_row [I18n.t(:trigger_info, locale)], style: bold_style
sheet.merge_cells("A#{sheet.rows.length}:E#{sheet.rows.length}")
sheet.add_row [
I18n.t(:no, locale),
I18n.t(:trigger_name, locale),
I18n.t(:event, locale),
I18n.t(:timing, locale),
I18n.t(:condition, locale)
], style:
sheet.add_row []
sheet.add_row [I18n.t(:rdbms_specific_info, locale)], style: bold_style
sheet.merge_cells("A#{sheet.rows.length}:C#{sheet.rows.length}")
sheet.add_row [
I18n.t(:no, locale),
I18n.t(:property_name, locale),
I18n.t(:property_value, locale)
], style:
[
['TABLE_CATALOG', 'def'],
['TABLE_SCHEMA', ''],
['TABLE_NAME', table_name],
['TABLE_TYPE', 'BASE TABLE'],
['ENGINE', 'InnoDB'],
['VERSION', '10'],
['ROW_FORMAT', 'Compact'],
['TABLE_ROWS', ''],
['AVG_ROW_LENGTH', ''],
['DATA_LENGTH', ''],
['MAX_DATA_LENGTH', '']
].each_with_index do |(prop_name, prop_value), idx|
sheet.add_row [idx + 1, prop_name, prop_value], style: border_style
end
sheet.column_widths 5, 25, 20, 20, 20, 30
end
|