Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/db-schema/news.ts
5865 views
1
/*
2
* This file is part of CoCalc: Copyright © 2023 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { ID } from "./crm";
7
import { Table } from "./types";
8
9
Table({
10
name: "news",
11
fields: {
12
id: ID,
13
date: {
14
type: "timestamp",
15
desc: "date of this news item",
16
},
17
title: {
18
type: "string",
19
desc: "short title of this news item",
20
},
21
text: {
22
type: "string",
23
desc: "markdown text of this news item",
24
},
25
tags: {
26
type: "array",
27
pg_type: "TEXT[]",
28
desc: "list of strings, e.g. ['jupyter', 'python']",
29
},
30
url: {
31
type: "string",
32
desc: "optional url",
33
},
34
channel: {
35
type: "string",
36
desc: 'e.g. "announcement", "feature", …', // defined in @cocalc/util/types/news → CHANNELS
37
},
38
hide: {
39
type: "boolean",
40
desc: "optionally, hide/retract this news item",
41
},
42
until: {
43
type: "timestamp",
44
desc: "optional expiration date - news item will not be shown after this date",
45
},
46
history: {
47
type: "map",
48
desc: "history of changes to this news item",
49
},
50
},
51
rules: {
52
primary_key: "id",
53
pg_indexes: ["date"],
54
anonymous: true, // allow users read access, even if not signed in
55
user_query: {
56
get: {
57
pg_where: [
58
"date >= NOW() - INTERVAL '3 months'",
59
"date <= NOW() + INTERVAL '1 minute'",
60
"channel != 'event'",
61
"hide IS NOT true",
62
"(until IS NULL OR until > NOW())",
63
],
64
pg_changefeed: "news",
65
options: [{ order_by: "-date" }, { limit: 100 }],
66
throttle_changes: 60 * 1000,
67
fields: {
68
// we only send title, and a link to open the news item
69
id: null,
70
date: null,
71
title: null,
72
tags: null,
73
channel: null,
74
hide: null,
75
},
76
},
77
// no set, all done via v2 API
78
},
79
},
80
});
81
82