Skip to content

Commit 39f6052

Browse files
karlhorkylukeed
andauthored
chore: add "Typed Migrations" README section (#14)
* Add setup for TypeScript and JSDoc to readme * chore: spacing and reword Co-authored-by: Luke Edwards <[email protected]>
1 parent f5da929 commit 39f6052

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

readme.md

+40
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,46 @@ With any of these, if `driver` is a string then it will be passed through `requi
208208
> **Important:** All drivers must adhere to the [`Driver` interface](/ley.d.ts#L45-L67)!
209209

210210

211+
## Typed Migrations
212+
213+
For extra confidence while writing your migration file(s), there are two options:
214+
215+
### TypeScript
216+
217+
1. Ensure [`ts-node`](https://www.npmjs.com/package/ts-node) is installed
218+
219+
2. Define a `ts-node` configuration block inside your `tsconfig.json` file:
220+
221+
```json
222+
{
223+
"ts-node": {
224+
"transpileOnly": true,
225+
"compilerOptions": {
226+
"module": "commonjs"
227+
}
228+
}
229+
}
230+
```
231+
232+
3. Run `ley` with the [`require`](#optsrequire) option so that `ts-node` can process file(s)
233+
234+
```sh
235+
$ ley -r ts-node/register <cmd>
236+
# or
237+
$ ley --require ts-node/register <cmd>
238+
```
239+
240+
### JSDoc
241+
242+
You may also use [JSDoc](https://jsdoc.app/) annotations throughout your file to achieve (most) of the benefits of TypeScript, but without installing and configuring TypeScript.
243+
244+
```js
245+
/** @param {import('pg').Client} DB */
246+
exports.up = async function (DB) {
247+
await DB.query(...)
248+
}
249+
```
250+
211251
## API
212252

213253
> **Important:** See [Options](#options) for common options shared all commands. <br>In this `API` section, you will only find **command-specific** options listed.

0 commit comments

Comments
 (0)