trellis-pg 0.3.1 → 0.4.0
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/README.md +145 -153
- data/ext/trellis_ruby/Cargo.lock +6 -5
- data/ext/trellis_ruby/Cargo.toml +3 -3
- data/ext/trellis_ruby/src/lib.rs +112 -17
- data/lib/trellis/error.rb +21 -11
- data/lib/trellis/instance.rb +71 -2
- data/lib/trellis/leave_task.rb +85 -0
- data/lib/trellis/migration.rb +29 -44
- data/lib/trellis/pg.rb +4 -3
- data/lib/trellis/railtie.rb +105 -73
- data/lib/trellis/schema_dump.rb +69 -57
- data/lib/trellis/task_hooks.rb +130 -0
- data/lib/trellis/test_support.rb +8 -8
- data/lib/trellis/values.rb +44 -24
- data/lib/trellis/version.rb +1 -1
- metadata +3 -2
- data/lib/trellis/release_check.rb +0 -165
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cd96adac04baff92684e23cb1b8c537009c3f5600635c2d061dc7bb06e219d91
|
|
4
|
+
data.tar.gz: 3fd455be94102ca285e4e094f6a32f36daba286066ddcc9c7e89c6262154557e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4df55ebf64316e75919cd2787b32204551b410d158e1fa0e41eb3afbaffda614e0ea138fc836b9cba2a2586db8a4556f787e3e97089b906cce49f5f84f02fa49
|
|
7
|
+
data.tar.gz: 180ee5359ead7aca7155ca3c5a526dd8d41020c4f4873f0c1335ee115c1d626e4e0f5dabe3b20dc30a95f47df2ab29f188dc2e772995ed521ae541959b9b55d5
|
data/README.md
CHANGED
|
@@ -18,7 +18,7 @@ as `trellis/pg`. The module is still `Trellis`.
|
|
|
18
18
|
|
|
19
19
|
```ruby
|
|
20
20
|
# Gemfile
|
|
21
|
-
gem "trellis-pg", "~> 0.
|
|
21
|
+
gem "trellis-pg", "~> 0.4.0"
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
`Bundler.require`, which a Rails app's `config/application.rb` runs,
|
|
@@ -60,58 +60,19 @@ Nothing in the binding uses it.
|
|
|
60
60
|
(`:transform_defined`, `:paused`, `:resumed`, ...).
|
|
61
61
|
`Trellis.define(statement)` is an `apply` that refuses anything but a
|
|
62
62
|
`TRANSFORM`, and returns its fully qualified target table.
|
|
63
|
-
- `Trellis.status(target_table)`, `Trellis.definitions`: the catalog reads
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
- `Trellis.status(target_table)`, `Trellis.definitions`: the catalog reads.
|
|
64
|
+
`status` returns a `Trellis::Status` (with nested `Trellis::DrainFailure`,
|
|
65
|
+
`Trellis::SourceIndexGap`, `Trellis::ExtremeIndexGap`,
|
|
66
|
+
`Trellis::CorrectingNode`, `Trellis::VersionHandover`,
|
|
67
|
+
`Trellis::BelowCatalogFloor`, `Trellis::RefusedStep`, `Trellis::JoinStatus`
|
|
68
|
+
and the like) whose fields are named and defined in the
|
|
69
|
+
[status reference](../../docs/status-reference.md).
|
|
66
70
|
- `Trellis.quarantined`, `Trellis.quarantine_status(target)`,
|
|
67
71
|
`Trellis.sample_quarantined(target, limit:, after:)`,
|
|
68
72
|
`Trellis.poisoned_since(time)`: the quarantine reads. Resuming is a
|
|
69
73
|
statement: `Trellis.apply("RESUME TRANSFORM order_totals.total")`.
|
|
70
74
|
`Trellis.release_key(transform, source_table, key)` releases one key a
|
|
71
|
-
transform holds, once its cause is fixed
|
|
72
|
-
holds (`held_keys`). `status` also reports a page the drain keeps failing
|
|
73
|
-
on with nothing charged or paused (`drain_failure`, a
|
|
74
|
-
`Trellis::DrainFailure`), and a finished `self_check` job's report lists
|
|
75
|
-
every one open (`drain_failures`). `status` names the paused upstream columns
|
|
76
|
-
(`paused_upstream_columns`, each `"target.column"`) that make a `live`
|
|
77
|
-
definition report `catching_up`. `status` lists the source indexes a
|
|
78
|
-
`GROUP BY` or `JOIN` target
|
|
79
|
-
needs and lacks (`source_index_gaps`, each a `Trellis::SourceIndexGap` with
|
|
80
|
-
`table`, `columns`, `role` (`:group_by`, `:join_from` or `:join_joined`: the part of
|
|
81
|
-
the definition that needs it), `opted_out` and a `create index` statement as `fix`);
|
|
82
|
-
`self_check` refuses such a target unless it was defined `WITHOUT SOURCE
|
|
83
|
-
INDEX`. `status` lists the source indexes a `MIN`/`MAX` aggregate's probes
|
|
84
|
-
read and the source lacks (`extreme_index_gaps`, each a
|
|
85
|
-
`Trellis::ExtremeIndexGap` with `table`, `columns`, `argument`, `opted_out`
|
|
86
|
-
and `fix`); nothing pauses, and a deleted extreme is re-read by scanning
|
|
87
|
-
its group. `status` lists the partitions of a partitioned source a definition
|
|
88
|
-
is being corrected for while it reads `:backfilling` for them
|
|
89
|
-
(`correcting`, each a `Trellis::CorrectingNode` with `node`, `since` and
|
|
90
|
-
`keys_remaining`). `status` names what a Re-derive build waits on instead
|
|
91
|
-
of its own work (`build_wait_xid`, the transaction id of the fence it
|
|
92
|
-
waits out, `nil` when it waits on nothing). While a process of another
|
|
93
|
-
Trellis version is live, `status` reports that this process stands by
|
|
94
|
-
(`version_handover`, a `Trellis::VersionHandover` with `this_version`,
|
|
95
|
-
`processes`, each a `Trellis::OtherProcess` with `worker_id` and
|
|
96
|
-
`version` (`nil` for a release before 0.2.0),
|
|
97
|
-
`unregistered_staging_worker` and `migrations_pending`), and
|
|
98
|
-
state-changing calls raise a `version_handover` error until it is gone.
|
|
99
|
-
While this binary is below the catalog floor, `status` reports that this
|
|
100
|
-
process stands by (`below_catalog_floor`, a `Trellis::BelowCatalogFloor`
|
|
101
|
-
with `floor` and `this_version`), and state-changing calls raise a
|
|
102
|
-
`version_floor` error.
|
|
103
|
-
For a `JOIN` definition `status` reports its hidden tables (`join`, a
|
|
104
|
-
`Trellis::JoinStatus`): `hidden_tables`, each a `Trellis::HiddenTable` with
|
|
105
|
-
`table`, `name`, `estimated_rows` and `bytes`, the `P`-size warning
|
|
106
|
-
(`partials_warning`, a `Trellis::PartialsWarning`), a 1-1 `JOIN`'s fan-out
|
|
107
|
-
warnings (`fan_out_warnings`, one `Trellis::FanOutWarning` per joined
|
|
108
|
-
position past the threshold, naming its `position`) and the step its build
|
|
109
|
-
runs (`building`, a `Trellis::JoinBuildStep` with `step` and the `side`,
|
|
110
|
-
`part`, `leaf`, `remaining` or `position` its kind of step carries). `join` is
|
|
111
|
-
`nil` for any other definition. `status` reports the oldest Trellis release
|
|
112
|
-
that can run a definition (`floor`, `"major.minor.patch"`), which an
|
|
113
|
-
application reads before rolling back to an earlier Trellis release
|
|
114
|
-
([upgrading](../../docs/upgrading.md#rolling-back)).
|
|
75
|
+
transform holds, once its cause is fixed.
|
|
115
76
|
- `Trellis.request_backfill(source_table)`,
|
|
116
77
|
`Trellis.detect_capture_disruptions` (pauses now the readers of every table
|
|
117
78
|
whose Trellis capture was changed outside Trellis, and returns the tables),
|
|
@@ -130,6 +91,9 @@ Nothing in the binding uses it.
|
|
|
130
91
|
and `self_check_job` returns `nil` for the replaced job or one whose
|
|
131
92
|
transform was dropped. With no drain worker anywhere in the fleet a job
|
|
132
93
|
stays `:queued`.
|
|
94
|
+
- `Trellis.rollback(to:)`, `Trellis.uninstall` and their `_plan` variants,
|
|
95
|
+
which change nothing: leave this release (see
|
|
96
|
+
[Rolling back and uninstalling](#rolling-back-and-uninstalling)).
|
|
133
97
|
- `Trellis::Metrics.render_prometheus`: the process-wide metrics registry as
|
|
134
98
|
Prometheus text (the binding opens no port; `Trellis::Metrics::RackApp` is a
|
|
135
99
|
mountable route and `Trellis::Metrics::Middleware` appends it to an
|
|
@@ -177,6 +141,7 @@ Trellis.shutdown
|
|
|
177
141
|
| `worker_threads:` | `2` | the threads of each Rust runtime a handle owns (its calls', and its background client's), invisible to Ruby's own sizing |
|
|
178
142
|
| `max_call_pool_size:` | `20` | the most connections the handle's call pool opens; the background pool is sized by `staging:` and `drain_threads:` |
|
|
179
143
|
| `call_pool_wait_timeout_ms:` | `30_000` | how long a call waits for a free call-pool connection before a `ConnectivityError` |
|
|
144
|
+
| `claim_grace_period_ms:` | `600_000` | how long the owner version may be silent before a standing-by process of another version claims the instance ([sizing it](../../docs/embedding.md#configuration-from-the-environment)) |
|
|
180
145
|
|
|
181
146
|
The defaults run nothing in the background. Some process in a fleet must set
|
|
182
147
|
`staging: true` and some process must run drain threads, or no definition ever
|
|
@@ -367,7 +332,9 @@ default one included.
|
|
|
367
332
|
`NotFoundError`, `InternalError`, `TimeoutError`, `VersionHandoverError`,
|
|
368
333
|
`VersionFloorError`),
|
|
369
334
|
each with `#code` (a
|
|
370
|
-
symbol)
|
|
335
|
+
symbol), `#error_id` (the engine's per-error code, `"T0042"`, which the
|
|
336
|
+
message starts with; `nil` for an error the binding raises itself) and
|
|
337
|
+
`#message`. A code newer than the binding arrives as
|
|
371
338
|
`UnknownError`, naming the code in its message. `ForkedHandleError` is a
|
|
372
339
|
`ValidationError`. Raising is Ruby's idiom, so where the Elixir binding
|
|
373
340
|
has `{:ok, value}` / `{:error, error}` and bang variants, every Ruby
|
|
@@ -402,18 +369,31 @@ include with a clear error on a Rails without the internals it guards (7.1).
|
|
|
402
369
|
### Configuration and boot
|
|
403
370
|
|
|
404
371
|
The Rails integration reads `Trellis.connect`'s options from one place,
|
|
405
|
-
`config.trellis.connect
|
|
372
|
+
`config.trellis.connect`. Trellis's definitions live in the database, so the
|
|
373
|
+
schema dump must be SQL; Rails's default `:ruby` makes `db:migrate` fail
|
|
374
|
+
([Schema dumps](#schema-dumps)):
|
|
406
375
|
|
|
407
376
|
```ruby
|
|
408
377
|
# config/application.rb (or config/environments/*.rb)
|
|
378
|
+
config.active_record.schema_format = :sql
|
|
409
379
|
config.trellis.connect = {
|
|
410
|
-
|
|
380
|
+
# A direct or session-mode URL, not the app's pooled DATABASE_URL.
|
|
381
|
+
url: ENV.fetch("TRELLIS_DATABASE_URL"),
|
|
411
382
|
# The one dedicated worker process sets TRELLIS_WORKER=1.
|
|
412
383
|
staging: ENV["TRELLIS_WORKER"] == "1",
|
|
413
384
|
drain_threads: ENV["TRELLIS_WORKER"] == "1" ? 2 : 0
|
|
414
385
|
}
|
|
415
386
|
```
|
|
416
387
|
|
|
388
|
+
The dedicated worker is one extra process running your app with that variable,
|
|
389
|
+
for example this `Procfile` line:
|
|
390
|
+
|
|
391
|
+
```
|
|
392
|
+
worker: TRELLIS_WORKER=1 bin/rails runner 'sleep'
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
Connect directly or through a session-mode pooler, never a transaction-mode one ([recommendations](../../docs/recommendations.md#connect-directly-or-through-a-session-mode-pooler)).
|
|
396
|
+
|
|
417
397
|
With it set, the app's default instance connects as the app boots (an
|
|
418
398
|
`after_initialize` hook), and the `at_exit` hook shuts it down. Left `nil`,
|
|
419
399
|
the default, the Railtie connects no default instance.
|
|
@@ -450,8 +430,8 @@ With neither set, the Railtie does nothing. Two exceptions:
|
|
|
450
430
|
preloading Passenger, say). Connect in each child with
|
|
451
431
|
`Trellis::Railtie.connect`.
|
|
452
432
|
|
|
453
|
-
`config.trellis.off_in` turns
|
|
454
|
-
(the `test` environment, by default): see [Testing](#testing).
|
|
433
|
+
`config.trellis.off_in` turns the boot connect off in the environments it
|
|
434
|
+
names (the `test` environment, by default): see [Testing](#testing).
|
|
455
435
|
|
|
456
436
|
### Logs in Rails
|
|
457
437
|
|
|
@@ -561,11 +541,39 @@ end
|
|
|
561
541
|
app uses `structure.sql`.
|
|
562
542
|
|
|
563
543
|
`rails trellis:migrate` creates or upgrades Trellis's own tables the same
|
|
564
|
-
way
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
544
|
+
way, for a deploy step that runs no database task. The helpers run it whenever
|
|
545
|
+
a migration defines something.
|
|
546
|
+
|
|
547
|
+
#### Rake task hooks
|
|
548
|
+
|
|
549
|
+
The instance belongs to the version that last ran `migrate`
|
|
550
|
+
([Upgrading](../../docs/upgrading.md)), so the Rails tasks that move a
|
|
551
|
+
database between schema versions run Trellis's `migrate` after their own work,
|
|
552
|
+
whether or not a migration was pending: `db:migrate` (and `db:migrate:up`,
|
|
553
|
+
`:down`, `:redo`, `db:migrate:<name>`), `db:rollback[:<name>]`, `db:prepare`,
|
|
554
|
+
`db:schema:load[:<name>]`, `db:test:prepare` and `db:test:load_schema[:<name>]`.
|
|
555
|
+
A gem-only bump, with nothing pending, claims the instance too, and so does
|
|
556
|
+
`db:prepare`, which Kamal and the generated Dockerfile run at every boot.
|
|
557
|
+
|
|
558
|
+
- **Once per database per process,** for the `config.trellis.dump_database`
|
|
559
|
+
of each environment the task touches (`db:prepare` in development also does
|
|
560
|
+
the test database). A task on another database of a multi-database app does
|
|
561
|
+
nothing.
|
|
562
|
+
- **After the task succeeds.** A failing task runs no hook, and a failing
|
|
563
|
+
`migrate` fails the task.
|
|
564
|
+
- **In `off_in` environments too,** like the migration helpers.
|
|
565
|
+
- **Rake only.** `ActiveRecord::Tasks::DatabaseTasks.prepare_all` called from
|
|
566
|
+
`rails runner`, or any code that skips Rake, runs no hook: call
|
|
567
|
+
`Trellis::Railtie.migrate_all` there.
|
|
568
|
+
- **Off with** `config.trellis.task_hooks = false`. The schema load still
|
|
569
|
+
restores a dump's definitions ("Schema dumps").
|
|
570
|
+
|
|
571
|
+
Whether `migrate` runs at every container boot or as one deploy job is your
|
|
572
|
+
choice ([where `migrate` runs](../../docs/upgrading.md#where-migrate-runs)).
|
|
573
|
+
No hook covers Capistrano's
|
|
574
|
+
`conditionally_migrate` on a gem-only bump (it skips `db:migrate`), `helm
|
|
575
|
+
rollback` (it runs no pre-upgrade job) or a programmatic caller. A worker's
|
|
576
|
+
own claim is the backstop there.
|
|
569
577
|
|
|
570
578
|
`Trellis::Railtie.with_handle { ... }` is what `trellis:migrate` and the
|
|
571
579
|
helpers use, for a script or rake task of your own that needs Trellis the
|
|
@@ -578,6 +586,13 @@ instance and every instance of `config.trellis.instances`. Neither it nor
|
|
|
578
586
|
Outside Rails, `require "trellis/migration"` and `Trellis.connect` before
|
|
579
587
|
migrating.
|
|
580
588
|
|
|
589
|
+
`db:prepare` in development also migrates the test databases. A migration
|
|
590
|
+
of another environment's database, or of one where Trellis is off, never
|
|
591
|
+
uses a connected handle: the helpers and `with_handle` connect to that
|
|
592
|
+
environment's counterpart of the database the instance's `url` points at
|
|
593
|
+
(the `database.yml` config of the same name), or to the migrating database
|
|
594
|
+
when the `url` names none, with the instance's other options.
|
|
595
|
+
|
|
581
596
|
### Targets as models
|
|
582
597
|
|
|
583
598
|
Only Trellis writes a target. Declare a model over one with
|
|
@@ -616,45 +631,27 @@ Account.find(42).event_counts.sum(:n) # with has_many :event_counts on Account
|
|
|
616
631
|
|
|
617
632
|
### Upgrading the gem
|
|
618
633
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
that migrates before the old worker stops fails at its first Trellis
|
|
624
|
-
migration. Ship the version change by itself, and the migrations in the next
|
|
625
|
-
release.
|
|
626
|
-
|
|
627
|
-
`rails trellis:release_check` fails a build that combines the two:
|
|
628
|
-
|
|
629
|
-
```sh
|
|
630
|
-
bin/rails trellis:release_check BASE=origin/main
|
|
631
|
-
```
|
|
634
|
+
[Upgrading](../../docs/upgrading.md) explains what a version change does to a
|
|
635
|
+
running instance and how to roll back. In a Rails app the migration tasks run
|
|
636
|
+
Trellis's `migrate` ("Rake task hooks"), so a deploy that runs `db:migrate`
|
|
637
|
+
or `db:prepare` upgrades the instance, with or without a Trellis migration.
|
|
632
638
|
|
|
633
|
-
|
|
634
|
-
when `trellis-pg`'s version in the lockfile changed and a migration added
|
|
635
|
-
since then mentions `Trellis`. It reads git and files only: it needs no
|
|
636
|
-
database and doesn't initialize the app.
|
|
639
|
+
### Rolling back and uninstalling
|
|
637
640
|
|
|
638
|
-
|
|
639
|
-
|
|
641
|
+
Both are destructive, run by the release being left with every Trellis
|
|
642
|
+
process stopped. Each prints what it drops and empties, then asks you to
|
|
643
|
+
type its name; with no terminal, `CONFIRM=yes` stands in for it.
|
|
640
644
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
deployed ref: a version change and a migration that merged separately
|
|
650
|
-
still deploy together.
|
|
651
|
-
- It reads `db/migrate` and each database's `migrations_paths`, and sees
|
|
652
|
-
migrations only. A state-changing call from a script or a console is in no
|
|
653
|
-
file it reads; the engine still refuses it.
|
|
645
|
+
- `bin/rails trellis:rollback [TO=0.3.1]` hands the database to an earlier
|
|
646
|
+
release, below the catalog floor included. Then deploy that release and
|
|
647
|
+
run its migrate; it rebuilds every target. Until then, a Rails task with
|
|
648
|
+
the newer gem that runs the [hooks](#rake-task-hooks) (`db:prepare` at a
|
|
649
|
+
container's boot, `db:migrate`, `db:rollback`) takes the database back. See
|
|
650
|
+
[below the catalog floor](../../docs/upgrading.md#below-the-catalog-floor).
|
|
651
|
+
- `bin/rails trellis:uninstall` removes everything Trellis has in the
|
|
652
|
+
database, targets included ([uninstalling](../../docs/operations.md#uninstalling)).
|
|
654
653
|
|
|
655
|
-
|
|
656
|
-
`Trellis::ReleaseCheck.call(root:, base:)`, which returns a result with
|
|
657
|
-
`ok?` and `message`.
|
|
654
|
+
Each runs on the default instance and every one in `config.trellis.instances`.
|
|
658
655
|
|
|
659
656
|
## Testing
|
|
660
657
|
|
|
@@ -664,22 +661,22 @@ never changes, whether or not a worker runs. A target is an ordinary table a
|
|
|
664
661
|
test fills itself.
|
|
665
662
|
|
|
666
663
|
`config.trellis.off_in` (`%w[test]` unless you set it) names the environments
|
|
667
|
-
Trellis is off in.
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
`
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
664
|
+
Trellis's runtime is off in. Only the runtime is off there:
|
|
665
|
+
|
|
666
|
+
- Nothing connects at boot, and `Trellis::Railtie.connect` warns and does
|
|
667
|
+
nothing. `Trellis.enabled?` is false, for code that builds on Trellis (it
|
|
668
|
+
is true without Rails). `Trellis.connect` itself is not gated.
|
|
669
|
+
- The schema load (`maintain_test_schema!`, `db:test:prepare`), the
|
|
670
|
+
migration helpers and `trellis:migrate` run as they do where it's on, so
|
|
671
|
+
the test database has every target and definition, and a new define
|
|
672
|
+
reaches it the next time `rails test` reloads the schema. They connect to
|
|
673
|
+
the database Rails is loading or migrating (the per-worker databases of
|
|
674
|
+
`parallelize` included), and `trellis:migrate` to that environment's
|
|
675
|
+
`config.trellis.dump_database`, with `config.trellis.connect`'s other
|
|
676
|
+
options.
|
|
677
|
+
- With no worker, each definition stays `waiting_to_backfill` and sources
|
|
678
|
+
get no capture triggers, so test writes capture nothing and targets stay
|
|
679
|
+
empty until a test fills them.
|
|
683
680
|
|
|
684
681
|
Stub a target's rows by hand, as the transform would write them; a model
|
|
685
682
|
over the target ("Targets as models") writes here:
|
|
@@ -706,10 +703,10 @@ end
|
|
|
706
703
|
```
|
|
707
704
|
|
|
708
705
|
It computes the target from its sources as they stand, as a fresh build
|
|
709
|
-
would, with the `SELECT` the engine renders from the definition
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
706
|
+
would, with the `SELECT` the engine renders from the recorded definition. It
|
|
707
|
+
doesn't exercise capture, the drain or any pause. A chained target refreshes
|
|
708
|
+
its upstream first. A source the definition names without a schema resolves
|
|
709
|
+
on the test's `search_path`. It
|
|
713
710
|
raises `Trellis::ValidationError` where Trellis is on, since the engine
|
|
714
711
|
maintains the target there (`trellis_on: true` writes anyway).
|
|
715
712
|
|
|
@@ -739,42 +736,39 @@ class EventCountTest < ActiveSupport::TestCase
|
|
|
739
736
|
end
|
|
740
737
|
```
|
|
741
738
|
|
|
742
|
-
|
|
739
|
+
A worker leaves capture triggers and built targets in the database it ran
|
|
740
|
+
on, so run these tests against a database of their own, or run `bin/rails
|
|
741
|
+
db:test:prepare` before the suite that has Trellis off.
|
|
743
742
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
worker (`<name>_<i>` on Rails 8.1, `<name>-<i>` on 8.0), so each worker's
|
|
751
|
-
`config.trellis.connect` has to name its own, and the handle does not
|
|
752
|
-
survive the fork. Connect after the fork, not at boot
|
|
753
|
-
(`config.trellis.connect_on_boot = false`), and register the hook before
|
|
754
|
-
`require "rails/test_help"`, which is what runs the schema load:
|
|
743
|
+
With Trellis on in the test database, `parallelize(workers: n)` loads the
|
|
744
|
+
schema into one database per worker (`<name>_<i>` on Rails 8.1, `<name>-<i>`
|
|
745
|
+
on 8.0), so each worker's `config.trellis.connect` has to name its own, and
|
|
746
|
+
the handle does not survive the fork. Connect after the fork, not at boot
|
|
747
|
+
(`config.trellis.connect_on_boot = false`), and register the hook before
|
|
748
|
+
`require "rails/test_help"`, which is what runs the schema load:
|
|
755
749
|
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
750
|
+
```ruby
|
|
751
|
+
# test/test_helper.rb
|
|
752
|
+
require "active_support/testing/parallelization"
|
|
753
|
+
|
|
754
|
+
ActiveSupport::Testing::Parallelization.after_fork_hook do |worker|
|
|
755
|
+
trellis = Rails.application.config.trellis
|
|
756
|
+
uri = URI.parse(trellis.connect.fetch(:url))
|
|
757
|
+
suffix = ActiveRecord.version >= Gem::Version.new("8.1") ? "_" : "-"
|
|
758
|
+
uri.path = "#{uri.path}#{suffix}#{worker}"
|
|
759
|
+
trellis.connect = trellis.connect.merge(url: uri.to_s)
|
|
760
|
+
end
|
|
767
761
|
|
|
768
|
-
|
|
762
|
+
require "rails/test_help"
|
|
769
763
|
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
764
|
+
class ActiveSupport::TestCase
|
|
765
|
+
parallelize(workers: 2)
|
|
766
|
+
# In a worker, after the schema load; in the one process of a run below
|
|
767
|
+
# Rails' parallelization threshold, the first test. Declare it before any
|
|
768
|
+
# setup that needs the handle (`resume_capture_disruptions`).
|
|
769
|
+
setup { Trellis::Railtie.connect if Trellis::Instance.connected.empty? }
|
|
770
|
+
end
|
|
771
|
+
```
|
|
778
772
|
|
|
779
773
|
### Fixtures and bulk loads
|
|
780
774
|
|
|
@@ -824,7 +818,7 @@ them, so with `schema_format = :ruby` the dump (`db:migrate`'s and
|
|
|
824
818
|
```ruby
|
|
825
819
|
# config/application.rb
|
|
826
820
|
config.active_record.schema_format = :sql
|
|
827
|
-
config.trellis.connect = { url: ENV.fetch("
|
|
821
|
+
config.trellis.connect = { url: ENV.fetch("TRELLIS_DATABASE_URL") }
|
|
828
822
|
```
|
|
829
823
|
|
|
830
824
|
Nothing else is set up. The file has the application's tables, the target
|
|
@@ -861,11 +855,10 @@ How the restore works, and what it refuses, is in
|
|
|
861
855
|
the test config's database, and its host, port, user, password and other
|
|
862
856
|
libpq keywords (`sslmode`, `sslrootcert`, ...) where it names a non-blank
|
|
863
857
|
value (its `url` when it has one).
|
|
864
|
-
- A database of an environment named in `config.trellis.off_in` loads
|
|
865
|
-
|
|
866
|
-
skips the dump of such
|
|
867
|
-
|
|
868
|
-
([Testing](#testing)).
|
|
858
|
+
- A database of an environment named in `config.trellis.off_in` loads and
|
|
859
|
+
dumps the same way, connecting to that database itself
|
|
860
|
+
([Testing](#testing)). `db:prepare` in development skips the dump of such
|
|
861
|
+
a test database: the file is development's.
|
|
869
862
|
- The hook adds each instance's exclusions (its Trellis schema, its ledgers)
|
|
870
863
|
to the flags Rails passes `pg_dump`, and its `target_schema` to the
|
|
871
864
|
`--schema` flags when Rails passes any. `pg_dump` can't leave out one
|
|
@@ -899,8 +892,7 @@ How the restore works, and what it refuses, is in
|
|
|
899
892
|
the Rails integration (`trellis/railtie.rb`, `trellis/migration.rb`,
|
|
900
893
|
`trellis/target.rb`),
|
|
901
894
|
loaded only in an app that has Rails, and the test helpers
|
|
902
|
-
(`trellis/test_support.rb`)
|
|
903
|
-
(`trellis/release_check.rb`), each loaded only when required.
|
|
895
|
+
(`trellis/test_support.rb`), loaded only when required.
|
|
904
896
|
- `ext/trellis_ruby/`: the extension crate, a member of the repository's
|
|
905
897
|
Cargo workspace, and the `extconf.rb` that builds it with rb-sys.
|
|
906
898
|
Plain-data conversion and error codes come from `clients/embed`
|
data/ext/trellis_ruby/Cargo.lock
CHANGED
|
@@ -1729,11 +1729,12 @@ dependencies = [
|
|
|
1729
1729
|
|
|
1730
1730
|
[[package]]
|
|
1731
1731
|
name = "trellis"
|
|
1732
|
-
version = "0.
|
|
1733
|
-
source = "git+https://github.com/salesforce-misc/trellis?rev=
|
|
1732
|
+
version = "0.4.0"
|
|
1733
|
+
source = "git+https://github.com/salesforce-misc/trellis?rev=f1c4f2e3a5468e1c33c8dacf0475ba3de016702c#f1c4f2e3a5468e1c33c8dacf0475ba3de016702c"
|
|
1734
1734
|
dependencies = [
|
|
1735
1735
|
"deadpool",
|
|
1736
1736
|
"deadpool-postgres",
|
|
1737
|
+
"futures-core",
|
|
1737
1738
|
"getrandom 0.4.3",
|
|
1738
1739
|
"metrics",
|
|
1739
1740
|
"metrics-exporter-prometheus",
|
|
@@ -1751,8 +1752,8 @@ dependencies = [
|
|
|
1751
1752
|
|
|
1752
1753
|
[[package]]
|
|
1753
1754
|
name = "trellis-embed"
|
|
1754
|
-
version = "0.
|
|
1755
|
-
source = "git+https://github.com/salesforce-misc/trellis?rev=
|
|
1755
|
+
version = "0.4.0"
|
|
1756
|
+
source = "git+https://github.com/salesforce-misc/trellis?rev=f1c4f2e3a5468e1c33c8dacf0475ba3de016702c#f1c4f2e3a5468e1c33c8dacf0475ba3de016702c"
|
|
1756
1757
|
dependencies = [
|
|
1757
1758
|
"tracing",
|
|
1758
1759
|
"trellis",
|
|
@@ -1760,7 +1761,7 @@ dependencies = [
|
|
|
1760
1761
|
|
|
1761
1762
|
[[package]]
|
|
1762
1763
|
name = "trellis_ruby"
|
|
1763
|
-
version = "0.
|
|
1764
|
+
version = "0.4.0"
|
|
1764
1765
|
dependencies = [
|
|
1765
1766
|
"magnus",
|
|
1766
1767
|
"rb-sys",
|
data/ext/trellis_ruby/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "trellis_ruby"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.4.0"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
publish = false
|
|
6
6
|
|
|
@@ -28,8 +28,8 @@ doctest = false
|
|
|
28
28
|
ruby = ["dep:magnus", "dep:rb-sys"]
|
|
29
29
|
|
|
30
30
|
[dependencies]
|
|
31
|
-
trellis = { git = "https://github.com/salesforce-misc/trellis", rev = "
|
|
32
|
-
trellis-embed = { git = "https://github.com/salesforce-misc/trellis", rev = "
|
|
31
|
+
trellis = { git = "https://github.com/salesforce-misc/trellis", rev = "f1c4f2e3a5468e1c33c8dacf0475ba3de016702c" }
|
|
32
|
+
trellis-embed = { git = "https://github.com/salesforce-misc/trellis", rev = "f1c4f2e3a5468e1c33c8dacf0475ba3de016702c" }
|
|
33
33
|
magnus = { version = "0.9", optional = true, default-features = false, features = ["rb-sys"] }
|
|
34
34
|
rb-sys = { version = "0.9", optional = true }
|
|
35
35
|
|