|
5 | 5 | // |
6 | 6 | // # Overview |
7 | 7 | // |
8 | | -// A Schema value manages the schema of a SQLite database that will be modified |
9 | | -// over time. The current database schema is stored in the Current field, and |
10 | | -// migrations from previous versions are captured as UpdateRules. |
| 8 | +// A [Schema] value manages the schema of a SQLite database that will be |
| 9 | +// modified over time. The current database schema is stored in the Current |
| 10 | +// field, and migrations from previous versions are captured as UpdateRules. |
11 | 11 | // |
12 | | -// When the program starts up, it should pass the open database to the Apply |
13 | | -// method of the Schema. This verifies that the Schema is valid, then checks |
| 12 | +// When the program starts up, it should pass the open database to the |
| 13 | +// [Schema.Apply] method. This verifies that the Schema is valid, then checks |
14 | 14 | // whether the database is up-to-date. If not, it applies any relevant update |
15 | 15 | // rules to bring it to the current state. If Apply fails, the database is |
16 | 16 | // rolled back. |
|
22 | 22 | // |
23 | 23 | // # Update Rules |
24 | 24 | // |
25 | | -// The Updates field of the Schema must contain an ordered list of update rules |
26 | | -// for all the versions of the schema prior to the Current one, from oldest to |
27 | | -// newest. Each rule has the hash of a previous schema version and a function |
28 | | -// that can be applied to the database to upgrade it to the next version in |
29 | | -// sequence. |
| 25 | +// The Updates field of the [Schema] must contain an ordered list of |
| 26 | +// [UpdateRule] for each version of the schema prior to the Current one from |
| 27 | +// oldest to newest. Each rule has the hash of a previous schema version and a |
| 28 | +// function that can be applied to the database to upgrade it to the next |
| 29 | +// version in sequence. |
30 | 30 | // |
31 | 31 | // When revising the schema, you must add a new rule mapping the old (existing) |
32 | 32 | // schema to the new one. These rules are intended to be a permanent record of |
|
45 | 45 | // |
46 | 46 | // # Validation |
47 | 47 | // |
48 | | -// You use the Validate function to check that the current schema in the |
| 48 | +// You use the [Validate] function to check that the current schema in the |
49 | 49 | // special sqlite_schema table maintained by SQLite matches a schema written as |
50 | 50 | // SQL text. If not, it reports a diff describing the differences between what |
51 | 51 | // the text wants and what the real schema has. |
@@ -130,20 +130,20 @@ func (s *Schema) logf(msg string, args ...any) { |
130 | 130 |
|
131 | 131 | type ctxSchemaKey struct{} |
132 | 132 |
|
133 | | -// Logf sends a log message to the logger attached to ctx, or to log.Printf if |
134 | | -// ctx does not have a logger attached. The context passed to the apply |
135 | | -// function of an UpdateRule will have this set to the logger for the Schema. |
| 133 | +// Logf sends a log message to the logger attached to ctx, or to [log.Printf] |
| 134 | +// if ctx does not have a logger attached. The context passed to the apply |
| 135 | +// function of an UpdateRule will have this set to the logger for the [Schema]. |
136 | 136 | func Logf(ctx context.Context, msg string, args ...any) { |
137 | 137 | s, _ := ctx.Value(ctxSchemaKey{}).(*Schema) |
138 | 138 | s.logf(msg, args...) |
139 | 139 | } |
140 | 140 |
|
141 | 141 | // Apply applies any pending schema migrations to the given database. It |
142 | | -// reports an error immediately if s is not consistent (per Check); otherwise |
143 | | -// it creates a new transaction and attempts to apply all applicable upgrades |
144 | | -// to db within it. If this succeeds and the transaction commits successfully, |
145 | | -// then Apply succeeds. Otherwise, the transaction is rolled back and Apply |
146 | | -// reports the reason wny. |
| 142 | +// reports an error immediately if s is not consistent (per [Schema.Check]); |
| 143 | +// otherwise it creates a new transaction and attempts to apply all applicable |
| 144 | +// upgrades to db within it. If this succeeds and the transaction commits |
| 145 | +// successfully, then Apply succeeds. Otherwise, the transaction is rolled back |
| 146 | +// and Apply reports the reason why. |
147 | 147 | // |
148 | 148 | // When applying a schema to an existing unmanaged database, Apply reports an |
149 | 149 | // error if the current schema is not compatible with the existing schema; |
@@ -335,7 +335,7 @@ func History(ctx context.Context, db DBConn) ([]HistoryRow, error) { |
335 | 335 | return out, nil |
336 | 336 | } |
337 | 337 |
|
338 | | -// HistoryRow is a row in the schema history maintained by the Schema type. |
| 338 | +// HistoryRow is a row in the schema history maintained by the [Schema] type. |
339 | 339 | type HistoryRow struct { |
340 | 340 | Timestamp time.Time `json:"timestamp"` // In UTC |
341 | 341 | Digest string `json:"digest"` // The digest of the schema at this update |
|
0 commit comments