mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 02:05:37 +08:00
Previously, the migrations tooling was a single flat `migrations/` tree, autoloaded by one global Zeitwerk loader and driven by a Thor CLI, so each planned next step had nowhere clean to land. This change splits it into four `path:`-referenced gems — `migrations-core`, `migrations-tooling`, `migrations-converters`, and `migrations-importer` — served by a single Samovar-based `disco` binary, without rewriting any domain logic. ### Why now The DSL refactor that replaced the IntermediateDB YAML config just landed, which is the cheapest moment to do this. Everything queued behind it — column coverage verification, the `discourse-migrations` validation plugin, the transformer framework, and private converter isolation — either has nowhere clean to land in the flat tree or would have to be retrofitted into a gem layout later. Doing the split now, while it's still a pure move (suite green, no domain logic touched), is far cheaper than after another round of features has built on the flat layout. ### What changes - **Four gems under `migrations/`**, all `path:`-referenced from the root `Gemfile` (nothing is published to RubyGems): `core` (CLI framework, UI, DB infrastructure, IntermediateDB, and the conversion framework), `tooling` (schema DSL and `schema` commands), `converters` (implementations and source adapters), and `importer` (row and uploads import). - **A single CLI binary:** `migrations/bin/cli` (Thor) becomes `disco` (Samovar), with each gem registering its own commands. Same surface — `convert`, `import`, `upload`, `schema generate|validate|…` — and Rails is still booted lazily. - **Isolated test suites:** each gem runs its own no-Rails specs in a new CI job, while the existing job keeps running the Rails-integration specs.
114 lines
2.8 KiB
Ruby
Executable file
Vendored
114 lines
2.8 KiB
Ruby
Executable file
Vendored
#!/usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
require "bundler/inline"
|
|
|
|
gemfile(true) do
|
|
source "https://rubygems.org"
|
|
gem "benchmark-ips"
|
|
gem "extralite-bundle"
|
|
gem "sqlite3"
|
|
end
|
|
|
|
require "extralite"
|
|
require "benchmark/ips"
|
|
require "time"
|
|
require "securerandom"
|
|
|
|
User = Data.define(:id, :name, :email, :created_at)
|
|
|
|
USER_HASH =
|
|
begin
|
|
name = SecureRandom.hex(10)
|
|
{ id: 1, name:, email: "#{name}@example.com", created_at: Time.now.utc.iso8601 }
|
|
end
|
|
|
|
USER_DATA =
|
|
User.new(
|
|
id: USER_HASH[:id],
|
|
name: USER_HASH[:name],
|
|
email: USER_HASH[:email],
|
|
created_at: USER_HASH[:created_at],
|
|
)
|
|
|
|
SQL_TABLE = <<~SQL
|
|
CREATE TABLE users (
|
|
id INTEGER,
|
|
name TEXT,
|
|
email TEXT,
|
|
created_at DATETIME
|
|
)
|
|
SQL
|
|
SQL_INSERT = "INSERT INTO users VALUES (?, ?, ?, ?)"
|
|
SQL_INSERT_NAMED = "INSERT INTO users VALUES (:id, :name, :email, :created_at)"
|
|
|
|
def create_extralite_db
|
|
db = Extralite::Database.new(":memory:")
|
|
db.execute(SQL_TABLE)
|
|
db
|
|
end
|
|
|
|
def create_sqlite3_db
|
|
db = SQLite3::Database.new(":memory:")
|
|
db.execute(SQL_TABLE)
|
|
db
|
|
end
|
|
|
|
def create_users(row_count)
|
|
row_count.times.map { |id| }
|
|
end
|
|
|
|
def insert_extralite_regular(stmt, user)
|
|
stmt.execute(user.id, user.name, user.email, user.created_at)
|
|
end
|
|
|
|
def insert_extralite_hash(stmt, user)
|
|
stmt.execute(user)
|
|
end
|
|
|
|
def insert_extralite_data(stmt, user)
|
|
stmt.execute(user)
|
|
end
|
|
|
|
def insert_sqlite3_regular(stmt, user)
|
|
stmt.execute(user.id, user.name, user.email, user.created_at)
|
|
end
|
|
|
|
def insert_sqlite3_hash(stmt, user)
|
|
stmt.execute(user)
|
|
end
|
|
|
|
puts "",
|
|
"Extralite SQLite version: #{Extralite.sqlite3_version}",
|
|
"SQLite version: #{SQLite3::SQLITE_VERSION}",
|
|
""
|
|
|
|
extralite_db = create_extralite_db
|
|
extralite_stmt_regular = extralite_db.prepare(SQL_INSERT)
|
|
extralite_stmt_named = extralite_db.prepare(SQL_INSERT_NAMED)
|
|
|
|
sqlite3_db = create_sqlite3_db
|
|
sqlite3_stmt_regular = sqlite3_db.prepare(SQL_INSERT)
|
|
sqlite3_stmt_named = sqlite3_db.prepare(SQL_INSERT_NAMED)
|
|
|
|
Benchmark.ips do |x|
|
|
x.config(time: 10, warmup: 2)
|
|
x.report("Extralite regular") { insert_extralite_regular(extralite_stmt_regular, USER_DATA) }
|
|
x.report("Extralite hash") { insert_extralite_hash(extralite_stmt_named, USER_HASH) }
|
|
x.report("Extralite data") { insert_extralite_data(extralite_stmt_regular, USER_DATA) }
|
|
x.report("Extralite data/array") do
|
|
insert_extralite_data(extralite_stmt_regular, USER_DATA.deconstruct)
|
|
end
|
|
x.report("SQLite3 regular") { insert_sqlite3_regular(sqlite3_stmt_regular, USER_DATA) }
|
|
x.report("SQLite3 hash") { insert_sqlite3_hash(sqlite3_stmt_named, USER_HASH) }
|
|
x.report("SQLite3 data/hash") { insert_sqlite3_hash(sqlite3_stmt_named, USER_DATA.to_h) }
|
|
x.compare!
|
|
end
|
|
|
|
extralite_stmt_regular.close
|
|
extralite_stmt_named.close
|
|
extralite_db.close
|
|
|
|
sqlite3_stmt_regular.close
|
|
sqlite3_stmt_named.close
|
|
sqlite3_db.close
|