Module: Polyrun::Database::CloneShards

Defined in:
lib/polyrun/database/clone_shards.rb

Overview

Prepare canonical template DBs with one bin/rails db:prepare (all DATABASE_URL* keys in one process for multi-DB apps), then create per-shard databases in parallel (PostgreSQL CREATE DATABASE … TEMPLATE …). Other ActiveRecord adapters (MySQL, SQL Server, SQLite, …) are not automated here—use polyrun env URLs with your own db:* scripts. Replaces shell loops like dropdb / createdb -T when polyrun.yml databases: lists primary + connections.

Class Method Summary collapse

Class Method Details

.provision!(databases_hash, workers:, rails_root:, migrate: true, replace: true, force_drop: false, dry_run: false, silent: true) ⇒ Object

See provision! on the singleton class for options.

Raises:



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/polyrun/database/clone_shards.rb', line 10

def provision!(databases_hash, workers:, rails_root:, migrate: true, replace: true, force_drop: false, dry_run: false, silent: true)
  dh = databases_hash.is_a?(Hash) ? databases_hash : {}
  workers = Integer(workers)
  raise Polyrun::Error, "workers must be >= 1" if workers < 1

  rails_root = File.expand_path(rails_root)

  migrate_canonical_databases!(dh, rails_root, dry_run, silent) if migrate
  create_shards_from_plan!(dh, workers, replace, force_drop, dry_run)
  true
end