Sublimate. TestHelpers
(Sublimate v0.1.4)
Copy Markdown
Test-support helpers for applications that use Sublimate.
For use in test suites only, not production.
Summary
Types
Functions
@spec uninstall_all_artifacts(database_options()) :: :ok | {:error, Exception.t()}
Clean up artifacts
Removes all Sublimate projection artifacts from the database: every trigger
whose name contains _delta_trigger, every function ending in _trigger or
_merge_deltas, and every *_deltas table.
This is a blanket sweep keyed on Sublimate's internal naming conventions. It does not target a specific projection - it removes the artifacts of every projection (and every Sublimate consumer) in the database. Use it only in a controlled test database where clearing all projection artifacts between tests is the intent.
To tear down a specific projection precisely (by config), use the consumer's own
teardown (e.g. Sublimate.uninstall/2 or Sublimate.uninstall_all/2, or a
consumer's config-derived reset helper) instead.
Attempts every drop even if one fails; returns the first error encountered, or
:ok if all succeed.
Requires the sandbox in :auto mode (triggers act on committed data).
Clean up data
uninstall_all_artifacts removes the triggers, functions, and deltas tables Sublimate created,
but leaves your source and destination data tables alone.
Under :auto mode, every change a test makes is committed, so you also need to reset your data
between tests, or changes from one test (a deleted row, an inserted record) will carry into the next.
Reset your data with TRUNCATE ... RESTART IDENTITY CASCADE to reset the auto-incrementing identity sequence:
setup do
Sublimate.TestHelpers.uninstall_all_artifacts(repo: Repo)
Repo.query!("""
TRUNCATE your_source_table, your_join_table
RESTART IDENTITY CASCADE
"")
# ... insert fresh fixtures
:ok
endThe destination table is not removed or emptied by either the artifact sweep or the source truncate - clear it separately if your tests depend on a clean destination.