-
-
Notifications
You must be signed in to change notification settings - Fork 554
/
db.code-snippets
47 lines (47 loc) · 1.2 KB
/
db.code-snippets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{
"Database migration": {
"scope": "javascript,typescript",
"prefix": "migration",
"body": [
"import type { Knex } from \"knex\";",
"",
"/**",
" * Migrates database schema to the next version.",
" * @see https://knexjs.org/#Schema",
" */",
"export async function up(db: Knex) {",
" await db.schema.createTable(\"${1:table}\", (table) => {",
" table$0",
" table.timestamps(false, true);",
" });",
"}",
"",
"export async function down(db: Knex) {",
" await db.schema.dropTableIfExists(\"${1:table}\");",
"}",
"",
"export const configuration = { transaction: true };",
"",
],
},
"Database seed": {
"scope": "javascript,typescript",
"prefix": "seed",
"body": [
"/**",
" * @see https://knexjs.org/#Builder",
" * @typedef {import(\"knex\")} Knex",
" */",
"",
"module.exports.seed = async (/** @type {Knex} */ db) => {",
" const ${1:table} = [",
" $0",
" ];",
"",
" await db.table(\"${1:table}\").delete();",
" await db.table(\"${1:table}\").insert(${1:table});",
"};",
"",
],
},
}