activerecord-virgodb-adapter 0.1.7 → 0.1.8
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 +27 -14
- 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: b21e3613bde955c3741ba92692bb2465036783609e4d11f9540ce0283ea83732
|
|
4
|
+
data.tar.gz: 34b1d14f797d629a6f09c029d422803353df2d86cb8c0682883bbb90d56fde18
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cbafb03b4df28cc059ed39deffd6504916232cb545b4ae2c7bce66e55121837e90cb3a76c8ecc6fd074277665abd6c438042ecce57530a5960b0fc6391a2d314
|
|
7
|
+
data.tar.gz: 79aae8c9a8cbcc419ac83295f371d24122cfddf291d5974c473d23cbafa512b3a177109197b86f090c349af594eb1533d47bea3e2bd84e7a2a28fe835d08c02a
|
|
@@ -134,32 +134,45 @@ module ActiveRecord
|
|
|
134
134
|
# history here isn't a correctness requirement. It also isn't a
|
|
135
135
|
# readability win: each version's `columns` re-lists every column from
|
|
136
136
|
# scratch, so N migrations means N near-duplicate JSON blobs, longer
|
|
137
|
-
# every time. The
|
|
138
|
-
#
|
|
139
|
-
#
|
|
140
|
-
#
|
|
141
|
-
#
|
|
142
|
-
#
|
|
143
|
-
#
|
|
137
|
+
# every time. The migration files themselves (db/migrate_virgodb_*/*.rb,
|
|
138
|
+
# timestamped, under git blame) are already the authoritative "what
|
|
139
|
+
# changed when" record. `register_schema_version`'s additive-only check
|
|
140
|
+
# is unaffected: it only ever compares a new migration's proposed
|
|
141
|
+
# columns against the CURRENT version, which is exactly what's still
|
|
142
|
+
# dumped.
|
|
143
|
+
#
|
|
144
|
+
# `applied_at` is dumped as a fixed `0`, and no per-version history
|
|
145
|
+
# comment is written -- both used to carry real wall-clock data
|
|
146
|
+
# (`Time.now.to_i` at migration time), which made this file diff on
|
|
147
|
+
# every clean rebuild (`db:drop` + `db:migrate`) even when the actual
|
|
148
|
+
# schema hadn't changed at all. Confirmed nothing reads either back:
|
|
149
|
+
# `current_schema_version` only ever selects `version, columns` (see
|
|
150
|
+
# above), and this adapter's own `assert_additive!`/
|
|
151
|
+
# `record_added_column!` only ever read `columns` too. The live
|
|
152
|
+
# manifest's real `schema_versions` table is untouched by this --
|
|
153
|
+
# `applied_at` still gets a real timestamp there at migration time,
|
|
154
|
+
# useful for a human inspecting the live table directly. This only
|
|
155
|
+
# changes what a fresh `structure_load` seeds into a NEW database,
|
|
156
|
+
# where a wall-clock value was never reproducible enough to belong in
|
|
157
|
+
# a checked-in file meant to represent "current schema shape," not
|
|
158
|
+
# "when someone last regenerated this file."
|
|
144
159
|
def dump_schema_versions!(filename)
|
|
145
160
|
return unless connection.data_source_exists?("schema_versions")
|
|
146
161
|
|
|
147
|
-
rows = connection.select_all("SELECT id, table_name, version, columns
|
|
162
|
+
rows = connection.select_all("SELECT id, table_name, version, columns FROM schema_versions ORDER BY table_name, version")
|
|
148
163
|
return if rows.to_a.empty?
|
|
149
164
|
|
|
150
165
|
File.open(filename, "a") do |f|
|
|
151
166
|
f.puts
|
|
152
167
|
rows.to_a.group_by { |r| r["table_name"] }.each do |table_name, versions|
|
|
153
168
|
latest = versions.max_by { |r| r["version"] }
|
|
154
|
-
history = versions.map { |r| "v#{r['version']} (#{Time.at(r['applied_at'].to_i).utc.strftime('%Y-%m-%d')})" }.join(", ")
|
|
155
169
|
|
|
156
|
-
f.puts "-- #{table_name} schema history: #{history} -- only the current version is dumped below; see db/migrate_virgodb_*/ for the rest"
|
|
157
170
|
pretty_columns = JSON.pretty_generate(JSON.parse(latest["columns"]))
|
|
158
171
|
f.puts(
|
|
159
172
|
"INSERT INTO \"schema_versions\" (id, table_name, version, columns, applied_at) VALUES (\n" \
|
|
160
173
|
" #{latest['id']}, #{connection.quote(table_name)}, #{latest['version']},\n" \
|
|
161
174
|
" #{connection.quote(pretty_columns)},\n" \
|
|
162
|
-
"
|
|
175
|
+
" 0\n" \
|
|
163
176
|
");"
|
|
164
177
|
)
|
|
165
178
|
f.puts
|
|
@@ -199,7 +212,7 @@ module ActiveRecord
|
|
|
199
212
|
# `SQLiteDatabaseTasks#structure_dump`'s `ignore_tables`-triggered
|
|
200
213
|
# fallback (used whenever `ActiveRecord::SchemaDumper.ignore_tables` is
|
|
201
214
|
# non-empty, e.g. excluding tables owned by a separate replication/
|
|
202
|
-
# backup mechanism -- exactly
|
|
215
|
+
# backup mechanism -- exactly a host app's own Litestream initializer)
|
|
203
216
|
# runs `SELECT sql || ';' FROM sqlite_master WHERE tbl_name NOT IN
|
|
204
217
|
# (...) ORDER BY tbl_name, type DESC, name` through the `sqlite3` CLI.
|
|
205
218
|
# Any table with a non-INTEGER (so non-rowid-alias) PRIMARY KEY --
|
|
@@ -271,8 +284,8 @@ module ActiveRecord
|
|
|
271
284
|
|
|
272
285
|
# Matches `db/clickhouse_structure.sql` and `db/schema.rb`'s own
|
|
273
286
|
# convention (both, unprompted, separate every top-level table
|
|
274
|
-
# definition with a blank line -- confirmed directly against
|
|
275
|
-
#
|
|
287
|
+
# definition with a blank line -- confirmed directly against a real
|
|
288
|
+
# host app's dumps of each, not assumed) rather than inventing a
|
|
276
289
|
# new one here. Only CREATE TABLE gets a leading blank line, not
|
|
277
290
|
# CREATE INDEX/CREATE UNIQUE INDEX -- those stay glued directly under
|
|
278
291
|
# their own table, same as clickhouse_structure.sql has no equivalent
|