better_structure_sql 0.2.0 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 067320c86a8a8e2064c41dd5ac93acd1d89652213a61f9efed61a2b946c44660
4
- data.tar.gz: f31e6dc7cb21647d8836f8f81da99097ed1c536db1b0adb7af33cf511ee401d1
3
+ metadata.gz: ef64a880cabbca1d370188561e604a27ecc2e8bd1040b68b123f9cf281b462ee
4
+ data.tar.gz: c4d5d2e7e366a0f768a8bc2933453958b10f46e72d5f168ea45af91d5b05473b
5
5
  SHA512:
6
- metadata.gz: 581f226ac09dd57a6ab5f058615bcd1aba7e5eaca5abb01c62e3431b6c72ec7c9fe47422cf5e1bc8e5a336df4e64de386dbf7841cd4a2f6fafcd76feb50b575f
7
- data.tar.gz: cd77d7dd9898c14ea6cfad1fa528de9b1cfb83d15d4d98253a9229ac7fb6fe84ad1b884cd9bfda7d815fd3cb87260ba559e3c7f44f33ee14a60661dce2e732cb
6
+ metadata.gz: 1d70b3713af668a419e7c9c5fcd66f516b36a50ec31e94b174b893207a7f2017e6ec273942345f191aa8860ab3f517d678eec04d62a32f25d36752c8a89a1b20
7
+ data.tar.gz: 39fcdb892436045a1579eeea41398fcf8ceb4b28407a192885d4aece4881b170e75724534b6cab30d7f0b58826aa1f5d03a7378f592cbf8d54f248ac98b080df
data/CHANGELOG.md CHANGED
@@ -13,6 +13,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
 
14
14
  ### Fixed
15
15
 
16
+ ## [0.2.2] - 2025-11-23
17
+
18
+ ### Fixed
19
+ - Web UI now properly displays multi-file schema content for files under 1MB
20
+ - Optimized schema version show page to avoid loading ZIP archives unnecessarily
21
+ - Improved memory efficiency by explicitly selecting only needed columns
22
+ - Better error messages distinguishing "too large" from "not available" content
23
+
24
+ ## [0.2.1] - 2025-11-20
25
+
26
+ ### Changed
27
+ - Improved schema version web UI with content hash display (first 8 characters)
28
+ - Increased view limit for better visibility of stored schema versions
29
+
16
30
  ## [0.2.0] - 2025-11-20
17
31
 
18
32
  ### Added
data/README.md CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  </div>
18
18
 
19
- > **⚠️ Beta Notice**: Version 0.2.0 is feature-complete and production-ready for **PostgreSQL**. Multi-database support (MySQL, SQLite) is implemented but considered experimental. APIs are stable but may see minor refinements before v1.0. We welcome feedback and contributions!
19
+ > **⚠️ Beta Notice**: Version 0.2.2 is feature-complete and production-ready for **PostgreSQL**. Multi-database support (MySQL, SQLite) is implemented but considered experimental. APIs are stable but may see minor refinements before v1.0. We welcome feedback and contributions!
20
20
 
21
21
  ## ✨ Why BetterStructureSql?
22
22
 
@@ -11,8 +11,9 @@ module BetterStructureSql
11
11
  class SchemaVersionsController < ApplicationController
12
12
  # Maximum file size to load into memory (2MB)
13
13
  MAX_MEMORY_SIZE = 2.megabytes
14
- # Maximum file size to display in browser (200KB)
15
- MAX_DISPLAY_SIZE = 200.kilobytes
14
+ # Maximum file size to display in browser (1MB)
15
+ # Large enough for most schemas but keeps browser responsive
16
+ MAX_DISPLAY_SIZE = 1.megabyte
16
17
 
17
18
  # Lists stored schema versions with pagination
18
19
  #
@@ -25,7 +26,7 @@ module BetterStructureSql
25
26
  # Load only metadata for listing (no content or zip_archive)
26
27
  @schema_versions = SchemaVersion
27
28
  .select(:id, :pg_version, :format_type, :output_mode, :created_at,
28
- :content_size, :file_count)
29
+ :content_size, :file_count, :content_hash)
29
30
  .order(created_at: :desc)
30
31
  .limit(100)
31
32
  end
@@ -40,20 +41,26 @@ module BetterStructureSql
40
41
  # @raise [ActiveRecord::RecordNotFound] if schema version not found
41
42
  # GET /better_structure_sql/schema_versions/:id
42
43
  def show
43
- # Load metadata first
44
+ # Load metadata first (no content or ZIP to minimize memory usage)
44
45
  @schema_version = SchemaVersion
45
46
  .select(:id, :pg_version, :format_type, :output_mode, :created_at,
46
- :content_size, :line_count, :file_count)
47
+ :content_size, :line_count, :file_count, :content_hash)
47
48
  .find(params[:id])
48
49
 
49
- # Only load content for small single-file versions
50
- if @schema_version.output_mode == 'single_file' && @schema_version.content_size <= MAX_DISPLAY_SIZE
51
- @schema_version = SchemaVersion.find(params[:id]) # Load with content
52
- elsif @schema_version.output_mode == 'multi_file'
53
- # Load content to extract manifest
54
- full_version = SchemaVersion.select(:id, :content).find(params[:id])
55
- @manifest = extract_manifest_from_content(full_version.content)
50
+ # Only load content for small files to display inline
51
+ # For large files, metadata is sufficient
52
+ if @schema_version.content_size <= MAX_DISPLAY_SIZE
53
+ # Reload full record with content column
54
+ # Note: We don't select zip_archive to avoid loading large binary data
55
+ @schema_version = SchemaVersion.select(
56
+ :id, :pg_version, :format_type, :output_mode, :created_at,
57
+ :content_size, :line_count, :file_count, :content_hash, :content
58
+ ).find(params[:id])
56
59
  end
60
+
61
+ # NOTE: Manifest extraction intentionally skipped to avoid loading
62
+ # potentially large ZIP archives into memory. Manifest is primarily
63
+ # useful for tooling and can be extracted from the download if needed.
57
64
  rescue ActiveRecord::RecordNotFound
58
65
  render plain: 'Schema version not found', status: :not_found
59
66
  end
@@ -176,37 +183,6 @@ module BetterStructureSql
176
183
  end
177
184
  end
178
185
 
179
- # Extracts embedded manifest JSON from multi-file schema content
180
- #
181
- # Manifest is stored between MANIFEST_JSON_START and MANIFEST_JSON_END markers
182
- # as SQL comments. Parses and returns the manifest hash.
183
- #
184
- # @param content [String] the schema content containing embedded manifest
185
- # @return [Hash, nil] parsed manifest hash or nil if not found/invalid
186
- def extract_manifest_from_content(content)
187
- # Manifest is embedded in content between MANIFEST_JSON_START and MANIFEST_JSON_END markers
188
- return nil unless content.include?('MANIFEST_JSON_START')
189
-
190
- # Extract JSON from between markers, removing comment prefixes
191
- start_marker = '-- MANIFEST_JSON_START'
192
- end_marker = '-- MANIFEST_JSON_END'
193
-
194
- start_pos = content.index(start_marker)
195
- end_pos = content.index(end_marker)
196
-
197
- return nil unless start_pos && end_pos
198
-
199
- manifest_section = content[(start_pos + start_marker.length)..(end_pos - 1)]
200
- manifest_json = manifest_section.lines
201
- .map { |line| line.sub(/^--\s?/, '') }
202
- .join
203
-
204
- JSON.parse(manifest_json)
205
- rescue JSON::ParserError => e
206
- Rails.logger.debug { "Failed to parse manifest: #{e.message}" }
207
- nil
208
- end
209
-
210
186
  # Streams large file content from database in chunks
211
187
  #
212
188
  # Sets appropriate headers for streaming downloads and disables proxy buffering.
@@ -27,6 +27,7 @@
27
27
  <thead class="table-light">
28
28
  <tr>
29
29
  <th scope="col" class="text-center" style="width: 80px;">ID</th>
30
+ <th scope="col" style="width: 120px;">Hash</th>
30
31
  <th scope="col" style="width: 120px;">Format</th>
31
32
  <th scope="col" style="width: 150px;">Mode</th>
32
33
  <th scope="col" style="width: 180px;">PostgreSQL</th>
@@ -42,6 +43,11 @@
42
43
  <td class="text-center fw-bold text-muted">
43
44
  #<%= version.id %>
44
45
  </td>
46
+ <td>
47
+ <code class="text-muted small" title="<%= version.content_hash %>">
48
+ <%= version.content_hash[0..7] %>
49
+ </code>
50
+ </td>
45
51
  <td>
46
52
  <%= format_type_badge(version.format_type) %>
47
53
  </td>
@@ -93,6 +93,18 @@
93
93
  </p>
94
94
  </div>
95
95
  </div>
96
+
97
+ <div class="row mt-3">
98
+ <div class="col-md-12">
99
+ <h6 class="text-muted mb-1">
100
+ <i class="bi bi-fingerprint"></i>
101
+ Content Hash (MD5)
102
+ </h6>
103
+ <p class="mb-0">
104
+ <code class="text-muted"><%= @schema_version.content_hash %></code>
105
+ </p>
106
+ </div>
107
+ </div>
96
108
  </div>
97
109
  </div>
98
110
 
@@ -109,7 +121,7 @@
109
121
  Download File
110
122
  <% end %>
111
123
  </a>
112
- <% if @schema_version.respond_to?(:content) && @schema_version.content.present? %>
124
+ <% if @schema_version.content.present? %>
113
125
  <button type="button" class="btn btn-outline-secondary btn-lg" onclick="copyToClipboard()">
114
126
  <i class="bi bi-clipboard"></i>
115
127
  Copy to Clipboard
@@ -118,19 +130,16 @@
118
130
  </div>
119
131
 
120
132
  <!-- Multi-file Info -->
121
- <% if @schema_version.multi_file? && @manifest %>
133
+ <% if @schema_version.multi_file? %>
122
134
  <div class="alert alert-info mb-4">
123
135
  <h6 class="alert-heading">
124
136
  <i class="bi bi-info-circle"></i>
125
137
  Multi-File Schema
126
138
  </h6>
127
- <p class="mb-2">This schema was generated in multi-file format with <%= @schema_version.file_count %> files across organized directories.</p>
128
- <% if @manifest['directories'] %>
129
- <p class="mb-0 small">
130
- <strong>Directories:</strong>
131
- <%= @manifest['directories'].keys.sort.join(', ') %>
132
- </p>
133
- <% end %>
139
+ <p class="mb-0">
140
+ This schema was generated in multi-file format with <%= @schema_version.file_count %> files across organized directories.
141
+ Download the ZIP archive to explore the directory structure and individual files.
142
+ </p>
134
143
  </div>
135
144
  <% end %>
136
145
 
@@ -146,14 +155,18 @@
146
155
  </h5>
147
156
  </div>
148
157
  <div class="card-body p-0">
149
- <% if @schema_version.respond_to?(:content) && @schema_version.content.present? %>
158
+ <% if @schema_version.content.present? %>
150
159
  <pre class="code-block m-0" id="schema-content"><%= @schema_version.content %></pre>
151
160
  <% else %>
152
161
  <div class="alert alert-warning m-3">
153
162
  <i class="bi bi-exclamation-triangle"></i>
154
- <strong>File too large to display</strong>
163
+ <strong>Content not loaded</strong>
155
164
  <p class="mb-0 mt-2">
156
- This schema file is too large to display in the browser (limit: 200 KB).
165
+ <% if @schema_version.content_size && @schema_version.content_size > 1048576 %>
166
+ This schema file is too large to display in the browser (limit: 1 MB, actual size: <%= number_to_human_size(@schema_version.content_size) %>).
167
+ <% else %>
168
+ The schema content is not available for inline display.
169
+ <% end %>
157
170
  Please use the "Download" button above to download and view it locally.
158
171
  </p>
159
172
  </div>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BetterStructureSql
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.2'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_structure_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sebyx07
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-11-20 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: pg
@@ -294,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
294
294
  - !ruby/object:Gem::Version
295
295
  version: '0'
296
296
  requirements: []
297
- rubygems_version: 3.6.2
297
+ rubygems_version: 3.7.2
298
298
  specification_version: 4
299
299
  summary: Clean database schema dumps for Rails (PostgreSQL, MySQL, SQLite) without
300
300
  external tool dependencies