activerecord-virgodb-adapter 0.1.5 → 0.1.6

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: 19cfa01c6fa3ae36139e4412c022abfe3039c670fd4b29fbffdb399f47c8c36d
4
- data.tar.gz: 5180372a507b33cd5a51670c3439894efafd72ca8d22538efc5b0a738eeb3937
3
+ metadata.gz: '0390e08c3ff3f57f95bce4609600461132e9af55122f1d9be076bd59171bc37d'
4
+ data.tar.gz: 216fb2576dd924f68d9e0e635824a825b0bc6863db6f3694438943343a630df3
5
5
  SHA512:
6
- metadata.gz: 4ffee29b035fe6705dd22022056b35e281f4275c9e009075508d136e87b03e804e62db4052ac8d581a010a50036568a6a6299ee7aa03f33137a56c28532b9a81
7
- data.tar.gz: 5303c2ceaf69703a4739614f76fd518741ea4555b18cc3bab4276d19c04189e03a9d192b8402dde926f235136bf87ac5e361a331f9e2efc7510f33d761fd19eb
6
+ metadata.gz: d3bfd3b9cdad22f0385a1f9d13a84483aa26c89cc3c16f38d231f8c8885b2af9a1beac0ef7d53ee6237b87092c074026fab6370fab4b605230342a81a8c574b5
7
+ data.tar.gz: 52c0f3df23b6a21a97a6322f58d59aa2c75511c998a21ce4e3eb54d8049f674c97d1b61061f377fcd1e028832669b7573033d2a6409804ffc241749cf91492bf
@@ -72,6 +72,7 @@ module ActiveRecord
72
72
 
73
73
  def structure_dump(filename, extra_flags)
74
74
  super
75
+ strip_null_autoindex_blank_lines!(filename)
75
76
  reformat_create_table_statements!(filename)
76
77
  annotate_physical_layout!(filename)
77
78
  dump_schema_versions!(filename)
@@ -194,18 +195,48 @@ module ActiveRecord
194
195
  File.write(filename, content)
195
196
  end
196
197
 
197
- # `SQLite3Adapter#structure_dump`'s raw `SELECT sql FROM sqlite_master`
198
- # path (used whenever `ActiveRecord::SchemaDumper.ignore_tables` is
198
+ # `SQLiteDatabaseTasks#structure_dump`'s `ignore_tables`-triggered
199
+ # fallback (used whenever `ActiveRecord::SchemaDumper.ignore_tables` is
199
200
  # non-empty, e.g. excluding tables owned by a separate replication/
200
- # backup mechanism) reproduces each CREATE TABLE exactly as SQLite
201
- # stored it -- one long line, every column crammed together, for a
202
- # table ActiveRecord generated. Fine for SQLite to load back
203
- # (structure_load doesn't care about whitespace), useless to a human
204
- # reading the dump next to `db/clickhouse_structure.sql` (ClickHouse's
205
- # own `SHOW CREATE TABLE` is naturally one-column-per-line, for
206
- # comparison). Purely cosmetic, safe to do unconditionally: only
207
- # rewrites the exact same statement with different whitespace, no DDL
208
- # semantics change.
201
+ # backup mechanism -- exactly hintpot's own litestream initializer)
202
+ # runs `SELECT sql || ';' FROM sqlite_master WHERE tbl_name NOT IN
203
+ # (...) ORDER BY tbl_name, type DESC, name` through the `sqlite3` CLI.
204
+ # Any table with a non-INTEGER (so non-rowid-alias) PRIMARY KEY --
205
+ # `maintenance_lease`, `flush_completions`, `ar_internal_metadata`,
206
+ # `schema_migrations`, all `TEXT PRIMARY KEY` -- gets a second,
207
+ # *hidden* row in `sqlite_master` for its `sqlite_autoindex_*`, whose
208
+ # `sql` column is NULL (an autoindex has no CREATE INDEX text of its
209
+ # own; SQLite generates it implicitly). `NULL || ';'` is NULL, and the
210
+ # `sqlite3` CLI's default `.nullvalue` prints a NULL result as nothing
211
+ # -- so each such table silently donates one stray blank line to the
212
+ # dump, unrelated to any table's real position or content (confirmed
213
+ # directly against a real `sqlite_master`; every non-blank-line-
214
+ # producing table here is either INTEGER PRIMARY KEY, a rowid alias
215
+ # needing no separate index, or has no primary key at all). The other
216
+ # `structure_dump` path (`.schema --nosys`, taken when
217
+ # `ignore_tables` is empty) already skips these rows itself --
218
+ # confirmed empirically too -- so this is purely a gap in the
219
+ # raw-SQL fallback, not something either path does on purpose.
220
+ # Stripping now, before `reformat_create_table_statements!` touches
221
+ # anything, means later steps never have to reason about which blank
222
+ # lines are "real" -- there aren't any yet at this point in the
223
+ # pipeline (`dump_schema_versions!`'s own deliberate ones are added
224
+ # after this runs).
225
+ def strip_null_autoindex_blank_lines!(filename)
226
+ content = File.read(filename)
227
+ content.gsub!(/\n\n+/, "\n")
228
+ File.write(filename, content)
229
+ end
230
+
231
+ # Reformats one-line CREATE TABLE statements (both `structure_dump`
232
+ # paths -- see `strip_null_autoindex_blank_lines!` above for the two --
233
+ # produce these one column crammed after another) into one column per
234
+ # line. Fine for SQLite to load back either way (structure_load
235
+ # doesn't care about whitespace), useless to a human reading the dump
236
+ # next to `db/clickhouse_structure.sql` (ClickHouse's own `SHOW CREATE
237
+ # TABLE` is naturally one-column-per-line, for comparison). Purely
238
+ # cosmetic, safe to do unconditionally: only rewrites the exact same
239
+ # statement with different whitespace, no DDL semantics change.
209
240
  #
210
241
  # Must handle statements that ALREADY span multiple lines, not just
211
242
  # single-line ones: every virgodb-side manifest table (`crates/
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-virgodb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - virgodb