You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add template dependency ordering via @depends-on comments (#61)
#### In This PR
Templates can now declare explicit dependencies on other templates using
`@depends-on` comments:
```sql
-- @depends-on: helper_functions.sql, base_types.sql
CREATE FUNCTION complex_calc() ...
```
During `apply` and `build`, templates are topologically sorted so
dependencies run first. Circular dependencies are detected and reported
as warnings (execution continues with best-effort ordering).
#### The Approach
Originally this branch attempted automatic SQL parsing - extracting
`CREATE TABLE/VIEW/FUNCTION` declarations and detecting `FROM`, `JOIN`,
`REFERENCES` clauses. After review feedback, this was simplified to
explicit `@depends-on` comments. The tradeoffs:
- **Explicit > implicit**: Users know exactly what's happening
- **No false positives**: SQL parsing can't reliably detect all
dependency types (CTEs, dynamic SQL, partial names)
- **Simpler implementation**: ~180 lines of focused code vs regex soup
- **Opt-in granularity**: Only declare dependencies where order matters
#### What Changed
- `dependencyParser.ts` - extracts `@depends-on` comments
(case-insensitive, deduped)
- `dependencyGraph.ts` - builds graph, topological sort, cycle detection
- `Orchestrator.ts` - integrates sorting into `apply()` and `build()`
- `--no-deps` flag on both commands to disable if needed
- Does NOT apply to `watch` (file-at-a-time execution)
#### Refs
Closes TT-XXX
Copy file name to clipboardExpand all lines: README.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,6 +133,18 @@ my_experiment.wip.sql → Applies locally, never builds to migration
133
133
When it's ready: `srtd promote my_experiment.wip.sql`
134
134
135
135
136
+
## Template Dependencies
137
+
138
+
Declare dependencies between templates with `@depends-on` comments:
139
+
140
+
```sql
141
+
-- @depends-on: helper_functions.sql
142
+
CREATEFUNCTIONcomplex_calc() ...
143
+
```
144
+
145
+
During `apply` and `build`, templates are sorted so dependencies run first. Circular dependencies are detected and reported. Use `--no-deps` to disable.
146
+
147
+
136
148
## Existing Projects
137
149
138
150
Already have functions in your database? Create templates for them, then:
0 commit comments