activerecord-virgodb-adapter 0.1.5 → 0.1.7
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 +4 -4
- data/lib/active_record/tasks/virgodb_database_tasks.rb +66 -11
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d70a70ab0e46de3acd4d283c69e7c385873c7bb9ec817423f62ff09dbc601350
|
|
4
|
+
data.tar.gz: 1f7b6259306a3d61f2e3d05fb345373a5d350b2742309804be1d91ac096886a1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 64c5716aa1f9d1ea110aacd562ad131acb5d8d76bbd4e8d0ed459a2191530d7b27c6c1f924b59a70840defed6f285c668e6fc9a56f97b134719bd2033ed42b6f
|
|
7
|
+
data.tar.gz: 9f2de20a524c86e2bafc0a43b6f49b8d86bdf127a54b8a5276972f75b10e937c5c7fe3b89b88172eaca32b4aaee09aa0aa52a34f947c614dc3926c3d1878f82e
|
|
@@ -72,7 +72,9 @@ 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)
|
|
77
|
+
separate_create_table_statements_with_blank_lines!(filename)
|
|
76
78
|
annotate_physical_layout!(filename)
|
|
77
79
|
dump_schema_versions!(filename)
|
|
78
80
|
end
|
|
@@ -194,18 +196,48 @@ module ActiveRecord
|
|
|
194
196
|
File.write(filename, content)
|
|
195
197
|
end
|
|
196
198
|
|
|
197
|
-
# `
|
|
198
|
-
#
|
|
199
|
+
# `SQLiteDatabaseTasks#structure_dump`'s `ignore_tables`-triggered
|
|
200
|
+
# fallback (used whenever `ActiveRecord::SchemaDumper.ignore_tables` is
|
|
199
201
|
# non-empty, e.g. excluding tables owned by a separate replication/
|
|
200
|
-
# backup mechanism
|
|
201
|
-
#
|
|
202
|
-
#
|
|
203
|
-
#
|
|
204
|
-
#
|
|
205
|
-
#
|
|
206
|
-
#
|
|
207
|
-
#
|
|
208
|
-
#
|
|
202
|
+
# backup mechanism -- exactly hintpot's own litestream initializer)
|
|
203
|
+
# runs `SELECT sql || ';' FROM sqlite_master WHERE tbl_name NOT IN
|
|
204
|
+
# (...) ORDER BY tbl_name, type DESC, name` through the `sqlite3` CLI.
|
|
205
|
+
# Any table with a non-INTEGER (so non-rowid-alias) PRIMARY KEY --
|
|
206
|
+
# `maintenance_lease`, `flush_completions`, `ar_internal_metadata`,
|
|
207
|
+
# `schema_migrations`, all `TEXT PRIMARY KEY` -- gets a second,
|
|
208
|
+
# *hidden* row in `sqlite_master` for its `sqlite_autoindex_*`, whose
|
|
209
|
+
# `sql` column is NULL (an autoindex has no CREATE INDEX text of its
|
|
210
|
+
# own; SQLite generates it implicitly). `NULL || ';'` is NULL, and the
|
|
211
|
+
# `sqlite3` CLI's default `.nullvalue` prints a NULL result as nothing
|
|
212
|
+
# -- so each such table silently donates one stray blank line to the
|
|
213
|
+
# dump, unrelated to any table's real position or content (confirmed
|
|
214
|
+
# directly against a real `sqlite_master`; every non-blank-line-
|
|
215
|
+
# producing table here is either INTEGER PRIMARY KEY, a rowid alias
|
|
216
|
+
# needing no separate index, or has no primary key at all). The other
|
|
217
|
+
# `structure_dump` path (`.schema --nosys`, taken when
|
|
218
|
+
# `ignore_tables` is empty) already skips these rows itself --
|
|
219
|
+
# confirmed empirically too -- so this is purely a gap in the
|
|
220
|
+
# raw-SQL fallback, not something either path does on purpose.
|
|
221
|
+
# Stripping now, before `reformat_create_table_statements!` and
|
|
222
|
+
# `separate_create_table_statements_with_blank_lines!` (below) touch
|
|
223
|
+
# anything, gives those steps a clean slate -- every blank line in the
|
|
224
|
+
# dump from this point on is one THEY deliberately added, not this
|
|
225
|
+
# accidental one.
|
|
226
|
+
def strip_null_autoindex_blank_lines!(filename)
|
|
227
|
+
content = File.read(filename)
|
|
228
|
+
content.gsub!(/\n\n+/, "\n")
|
|
229
|
+
File.write(filename, content)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Reformats one-line CREATE TABLE statements (both `structure_dump`
|
|
233
|
+
# paths -- see `strip_null_autoindex_blank_lines!` above for the two --
|
|
234
|
+
# produce these one column crammed after another) into one column per
|
|
235
|
+
# line. Fine for SQLite to load back either way (structure_load
|
|
236
|
+
# doesn't care about whitespace), useless to a human reading the dump
|
|
237
|
+
# next to `db/clickhouse_structure.sql` (ClickHouse's own `SHOW CREATE
|
|
238
|
+
# TABLE` is naturally one-column-per-line, for comparison). Purely
|
|
239
|
+
# cosmetic, safe to do unconditionally: only rewrites the exact same
|
|
240
|
+
# statement with different whitespace, no DDL semantics change.
|
|
209
241
|
#
|
|
210
242
|
# Must handle statements that ALREADY span multiple lines, not just
|
|
211
243
|
# single-line ones: every virgodb-side manifest table (`crates/
|
|
@@ -237,6 +269,29 @@ module ActiveRecord
|
|
|
237
269
|
File.write(filename, content)
|
|
238
270
|
end
|
|
239
271
|
|
|
272
|
+
# Matches `db/clickhouse_structure.sql` and `db/schema.rb`'s own
|
|
273
|
+
# convention (both, unprompted, separate every top-level table
|
|
274
|
+
# definition with a blank line -- confirmed directly against
|
|
275
|
+
# hintpot's real dumps of each, not assumed) rather than inventing a
|
|
276
|
+
# new one here. Only CREATE TABLE gets a leading blank line, not
|
|
277
|
+
# CREATE INDEX/CREATE UNIQUE INDEX -- those stay glued directly under
|
|
278
|
+
# their own table, same as clickhouse_structure.sql has no equivalent
|
|
279
|
+
# to disagree with and virgodb's own tables (e.g. `inline_batches` +
|
|
280
|
+
# `idx_inline_batches_table_name`) already read naturally that way.
|
|
281
|
+
# Runs after `reformat_create_table_statements!` (so every `CREATE
|
|
282
|
+
# TABLE` is unambiguously alone at the start of its own line already,
|
|
283
|
+
# nothing left to normalize first) but before
|
|
284
|
+
# `annotate_physical_layout!` (so a table WITH a physical-layout
|
|
285
|
+
# comment gets the blank line ahead of the comment block, not
|
|
286
|
+
# wedged between the comment and its own `CREATE TABLE`).
|
|
287
|
+
# `(?<!\A)` skips the very first statement in the file, which should
|
|
288
|
+
# start right at the top with no leading blank line.
|
|
289
|
+
def separate_create_table_statements_with_blank_lines!(filename)
|
|
290
|
+
content = File.read(filename)
|
|
291
|
+
content.gsub!(/(?<!\A)^CREATE TABLE /) { |match| "\n#{match}" }
|
|
292
|
+
File.write(filename, content)
|
|
293
|
+
end
|
|
294
|
+
|
|
240
295
|
# Splits a CREATE TABLE column list on commas that are NOT nested
|
|
241
296
|
# inside a type's own parens (e.g. `Decimal(18,2)`) -- a plain
|
|
242
297
|
# `String#split(",")` would wrongly cut `Decimal(18` and `2)` apart.
|