Lone Badger Tech

Repeatables

Views, procedures, functions and environment-only scripts that re-run when they change.

Objects that are defined rather than migrated, such as views, stored procedures, functions and triggers, belong in repeatable/. Write them with CREATE OR ALTER. After the changes in a deploy, bsm applies every repeatable whose hash differs from the one it last applied, each in its own transaction.

Order

Repeatables run in path order (ordinal), with declared dependencies first:

repeatable/procedures/usp_FindCustomer.sql
-- bsm:requires views/vActiveCustomer.sql functions/fnFullName.sql
CREATE OR ALTER PROCEDURE dbo.usp_FindCustomer ...

Names are paths relative to repeatable/, with forward slashes. Cycles and unknown names are reported by plan check.

Environment-only scripts

Scripts under environments/<name>/ behave like repeatables but run only in that environment, after the shared ones. They are named @<name>/path and may require shared repeatables. Use them for seed data, test users and environment-specific grants. Write them idempotently (MERGE, IF NOT EXISTS).

What is recorded

For each repeatable, the journal keeps the current and previous script and hash, and a repeatable event. Repeatables are not part of the plan certificate: they are re-applied by content, not by position.

Reverting a repeatable

bsm revert --repeatable views/vCustomer.sql -e test
bsm revert --repeatable views/a.sql --repeatable @test/seed.sql --dry-run

Runs the definition the repeatable had before its last apply (stored in the journal) and records it as current, with a revert event. Running it twice swaps back. Use it to back out a bad view or procedure quickly; the working copy still has the newer version, so the next deploy applies it again unless you fix it too. A repeatable applied only once has nothing to go back to: remove the object with a new change instead.

Changes or repeatables?

  • Tables, columns, indexes, data: changes (they need explicit migrations and reverts).
  • Views, procedures, functions, triggers: repeatables (the latest definition wins).
  • Something a change depends on during deploy (for example a function used in a computed column): a change, because repeatables run after changes.