Class: ActiveRecord::ConnectionAdapters::VirgodbAdapter
- Inherits:
-
SQLite3Adapter
- Object
- SQLite3Adapter
- ActiveRecord::ConnectionAdapters::VirgodbAdapter
- Defined in:
- lib/activerecord-virgodb-adapter.rb
Overview
ActiveRecord adapter for virgodb migrations -- lets any Rails app
define and evolve a virgodb table's schema the same way it already
does for SQLite (bin/rails db:migrate) and ClickHouse (the
clickhouse-activerecord gem): real ActiveRecord::Migration subclasses,
raw type strings, picked up by rails db:migrate alongside every
other database.
virgodb's manifest is already a real SQLite file, so subclassing
SQLite3Adapter (not building from AbstractAdapter) gets
structure_dump/structure_load -- the :sql schema format -- for free,
zero custom dumper code. Only create_table/add_column need
overriding: call super for a real, if never-written-to, SQLite
table (SQLite's type-name grammar accepts arbitrary bare-word type
declarations -- verified against a real connection, see
crates/compact/src/schema.rs's doc comment for the exact grammar and
why it has to be "AnyLast String updated_at", not
"AnyLast(String, updated_at)"), and additionally record the column
in a schema_versions table matching exactly what
compact::schema_from_columns on the Rust side expects to parse.
One manifest can back several virgodb tables sharing a single
database.yml connection and migrations path -- the same way a host
app's clickhouse: connection might already hold all of its ClickHouse
tables under one connection. schema_versions (and the Rust-side
manifest's run_files/inline_batches/orphaned_files/
maintenance_lease catalog tables) are scoped by table_name
specifically to make this safe: each logical table's schema history
and physical run files stay independent even though they live in the
same SQLite file.
Additive-only, matching Manifest::register_schema_version's own
rule and virgodb's immutable-Parquet philosophy: remove_column,
rename_column, and change_column are all disabled outright rather
than silently letting the real SQLite table drift out of sync with
what schema_versions describes.
Constant Summary collapse
- ADAPTER_NAME =
"Virgodb"
Instance Method Summary collapse
- #add_column(table_name, column_name, type, **options) ⇒ Object
- #change_column(table_name, column_name, type, **options) ⇒ Object
-
#configure_connection ⇒ Object
Real bug, found (not assumed) by testing: setting
auto_vacuum = INCREMENTALfromcreate_table-- even from create_table's very FIRST call on a brand-new manifest, before any table exists -- was already too late. - #create_table(table_name, **options, &block) ⇒ Object
- #remove_column(table_name, column_name, type = nil, **options) ⇒ Object
- #rename_column(table_name, column_name, new_column_name) ⇒ Object
Instance Method Details
#add_column(table_name, column_name, type, **options) ⇒ Object
80 81 82 83 84 |
# File 'lib/activerecord-virgodb-adapter.rb', line 80 def add_column(table_name, column_name, type, **) result = super record_added_column!(table_name, column_name, type, ) result end |
#change_column(table_name, column_name, type, **options) ⇒ Object
94 95 96 |
# File 'lib/activerecord-virgodb-adapter.rb', line 94 def change_column(table_name, column_name, type, **) raise NotImplementedError, "virgodb schemas are additive-only -- an existing column's type can't change" end |
#configure_connection ⇒ Object
Real bug, found (not assumed) by testing: setting auto_vacuum = INCREMENTAL from create_table -- even from create_table's very
FIRST call on a brand-new manifest, before any table exists -- was
already too late. SQLite3Adapter's own configure_connection sets
journal_mode = wal via DEFAULT_PRAGMAS (super, below) as part of
establishing the connection itself, which happens before this
adapter's create_table ever runs -- and switching journal_mode to
WAL requires SQLite to actually write to the file (creating the -wal
file, an implicit checkpoint), which "poisons" the database from
auto_vacuum's perspective the same way any other content would.
Confirmed directly: a manual PRAGMA auto_vacuum = INCREMENTAL
issued immediately after establish_connection, before ANY table or
migration ran, still silently failed. The pragma has to be set
before super runs here, not merely before the first CREATE TABLE.
69 70 71 72 |
# File 'lib/activerecord-virgodb-adapter.rb', line 69 def configure_connection @raw_connection.auto_vacuum = "incremental" if @raw_connection.respond_to?(:auto_vacuum=) super end |
#create_table(table_name, **options, &block) ⇒ Object
74 75 76 77 78 |
# File 'lib/activerecord-virgodb-adapter.rb', line 74 def create_table(table_name, **, &block) result = super record_schema_version!(table_name) result end |
#remove_column(table_name, column_name, type = nil, **options) ⇒ Object
86 87 88 |
# File 'lib/activerecord-virgodb-adapter.rb', line 86 def remove_column(table_name, column_name, type = nil, **) raise NotImplementedError, "virgodb schemas are additive-only -- columns can be added, never removed (see schema_versions)" end |
#rename_column(table_name, column_name, new_column_name) ⇒ Object
90 91 92 |
# File 'lib/activerecord-virgodb-adapter.rb', line 90 def rename_column(table_name, column_name, new_column_name) raise NotImplementedError, "virgodb schemas are additive-only -- columns can't be renamed once created" end |