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
Copy file name to clipboardExpand all lines: readme.md
+47-8
Original file line number
Diff line number
Diff line change
@@ -77,21 +77,19 @@ Because of this, it's often recommended to prefix migrations with a timestamp or
77
77
|-- 002-seats.js
78
78
```
79
79
80
+
> **Note**: You may create the next file via `ley new todos --length 3` where `todos` is a meaningful name for your project.<br>The above command will create the `migrations/003-todos.js` filepath — or similar, depending on your command arguments.
81
+
80
82
***Timestamped***
81
83
82
84
```
83
85
/migrations
84
-
|-- 1581323445664-users.js
85
-
|-- 1581323453868-teams.js
86
-
|-- 1581323458383-seats.js
86
+
|-- 1581323445-users.js
87
+
|-- 1581323453-teams.js
88
+
|-- 1581323458-seats.js
87
89
```
88
90
89
-
**Tip:** Create timestamped migration files on the command line using `touch` and `date`:
91
+
> **Note**: You may create the next file via `ley new todos --timestamp` where `todos` is a meaningful name for your project.<br>The above command will create the `migrations/1584389617-todos.js` filepath — or similar, depending on your command arguments.
90
92
91
-
```
92
-
$ touch "$(date +%s)-users.js"
93
-
#=> 1581785004-users.js
94
-
```
95
93
96
94
**The order of your migrations is critically important!**<br>Migrations must be treated as an append-only immutable task chain. Without this, there's no way to _reliably_ rollback or recreate your database.
By default, only the most recently-applied migration file is invoked.
240
238
241
239
240
+
### ley.new(opts?)
241
+
Returns: `Promise<string>`
242
+
243
+
Returns the newly created _relative filename_ (eg, `000-users.js`).
244
+
245
+
#### opts.filename
246
+
Type: `string`
247
+
248
+
**Required.** The name of the file to be created.
249
+
250
+
> **Note:** A prefix will be prepended based on [`opts.timestamp`](#optstimestamp) and [`opts.length`](#optslength) values.<br>The `.js` extension will be applied unless your input already has an extension.
251
+
252
+
#### opts.timestamp
253
+
Type: `boolean`<br>
254
+
Default: `false`
255
+
256
+
Should the migration file have a timestamped prefix?<br>
257
+
If so, will use `Date.now()` floored to the nearest second.
258
+
259
+
#### opts.length
260
+
Type: `number`<br>
261
+
Default: `5`
262
+
263
+
When **not** using a timestamped prefix, this value controls the prefix total length.<br>
264
+
For example, `00000-users.js` will be followed by `00001-teams.js`.
265
+
266
+
#### opts.cwd
267
+
Type: `string`<br>
268
+
Default: `.`
269
+
270
+
A target location to treat as the current working directory.
271
+
272
+
> **Note:** This value is `path.resolve()`d from the current `process.cwd()` location.
273
+
274
+
#### opts.dir
275
+
Type: `string`<br>
276
+
Default: `migrations`
277
+
278
+
The directory (relative to `opts.cwd`) to find migration files.
0 commit comments