Adopt converts an existing stateless project into virtual mode. Detach reverses the process. Both are interactive operations that require typed confirmation.Documentation Index
Fetch the complete documentation index at: https://docs.sqlbuild.com/llms.txt
Use this file to discover all available pages before exploring further.
Adopt
sqb state adopt takes existing warehouse relations (tables and views) and converts them into versioned physical relations with VDE views at the original names.
Prerequisites
- State store must be initialized (
sqb state init) unsuffixed_virtual_envmust be configured so existing object names are preserved:
unsuffixed_virtual_env, adopt blocks with a config error. This is intentional - without it, existing relations would be renamed to suffixed schemas (e.g. dev__dev.fact_orders), breaking existing consumers.
What happens
- For each model, the existing table is moved/renamed into the physical schema (
dev__sqb_physical.fact_orders__v_<hash>) - A logical VDE view is created at the original name (
dev.fact_orders) pointing to the physical version - Model versions, physical relations, VDE record, and VDE refs are persisted in state
Usage
--allow-copy is required when the adapter does not support native same-schema rename (cross-schema moves, some adapters). Without it, adopt blocks with “requires —allow-copy” if a copy fallback would be needed.
View models
View models are adopted the same way - a versioned physical view is created in the physical schema, and the original name becomes a logical VDE view.Detach
sqb state detach reverses adoption, collapsing a VDE back into normal stateless relations.
Prerequisites
The VDE must befinalized. If the VDE is working (has stale models), detach blocks:
What happens
- For each table model, the physical version is moved/renamed back to the original target name
- For each view model, the view is recreated from compiled SQL at the original target name (not copied from the physical ref)
- The VDE is marked
detachedin state - VDE refs are preserved for audit/recovery and janitor protection
Usage
After detach
A detached VDE is blocked from further virtual operations:sqb buildblocks with “virtual environment is detached”sqb promote --from <detached>or--to <detached>blockssqb rollbackon a detached VDE blocks
Detached VDE cleanup
Detached VDE refs and state rows are cleaned up by the janitor, not by detach itself. This preserves refs for recovery if detach fails partway through.Interrupted operations
Adopt and detach are multi-step warehouse operations that cannot be wrapped in a single transaction. If an operation fails partway through:- A
failedoperation record is persisted in state with the error message - VDE refs and checkpoints remain intact
- The warehouse may have partial artifacts (e.g. table moved to physical schema but view not yet created)
- Run
sqb reconcileto diagnose the current state - Use
sqb reconcile repair-viewor manual warehouse repair as needed - Retry the adopt or detach operation

