-
Notifications
You must be signed in to change notification settings - Fork 388
/
1649621949432_create-content-table.js
76 lines (64 loc) · 1.49 KB
/
1649621949432_create-content-table.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
exports.up = async (pgm) => {
await pgm.createTable('contents', {
id: {
type: 'uuid',
default: pgm.func('gen_random_uuid()'),
notNull: true,
primaryKey: true,
unique: true,
},
parent_id: {
type: 'uuid',
notNull: false,
},
owner_id: {
type: 'uuid',
notNull: true,
},
slug: {
type: 'varchar',
check: 'length(slug) <= 256',
notNull: true,
},
title: {
type: 'varchar',
check: 'length(title) <= 256',
notNull: false,
},
body: {
type: 'text',
check: 'length(body) <= 20000',
notNull: true,
},
status: {
type: 'varchar',
default: 'draft',
notNull: true,
check: "status IN ('draft', 'published')",
},
source_url: {
type: 'varchar',
check: 'length(source_url) <= 2000',
notNull: false,
},
published_at: {
type: 'timestamp with time zone',
notNull: false,
},
created_at: {
type: 'timestamp with time zone',
notNull: true,
default: pgm.func("(now() at time zone 'utc')"),
},
updated_at: {
type: 'timestamp with time zone',
notNull: true,
default: pgm.func("(now() at time zone 'utc')"),
},
});
await pgm.addConstraint('contents', 'contents_uniqueness_fkey', 'UNIQUE ("owner_id", "slug")');
};
exports.down = async (pgm) => {
await pgm.dropConstraint('contents', 'contents_uniqueness_fkey');
await pgm.dropTable('contents');
};