Path: blob/master/src/packages/util/db-schema/project-log.ts
1447 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { deep_copy, uuid } from "../misc";6import { SCHEMA as schema } from "./index";7import { Table } from "./types";89const DEFAULT_LIMIT = 750;1011Table({12name: "project_log",13rules: {14primary_key: "id",15// db_standby feels too slow for this, since the user only16// does this query when they actually click to show the log.17//db_standby: "unsafe",18durability: "soft", // dropping a log entry (e.g., "foo opened a file") wouldn't matter much1920pg_indexes: ["project_id", "time", "account_id"],2122user_query: {23get: {24pg_where: ["time >= NOW() - interval '2 months'", "projects"],25pg_changefeed: "projects",26options: [{ order_by: "-time" }, { limit: DEFAULT_LIMIT }],27throttle_changes: 2000,28fields: {29id: null,30project_id: null,31time: null,32account_id: null,33event: null,34},35},36set: {37fields: {38id(obj) {39return obj.id != null ? obj.id : uuid();40},41project_id: "project_write",42account_id: "account_id",43time: true,44event: true,45},46},47},48},49fields: {50id: {51type: "uuid",52desc: "which",53},54project_id: {55type: "uuid",56desc: "where",57render: { type: "project_link" },58},59time: {60type: "timestamp",61desc: "when",62},63account_id: {64type: "uuid",65desc: "who",66render: { type: "account" },67},68event: {69type: "map",70desc: "what",71render: { type: "json" },72},73},74});7576// project_log_all -- exactly like project_log, but loads up77// to the most recent **many** log entries (so a LOT).78schema.project_log_all = deep_copy(schema.project_log);79// This happens rarely, and user is prepared to wait.80schema.project_log_all.db_standby = "unsafe";81schema.project_log_all.virtual = "project_log";82// no time constraint:83if (schema.project_log_all.user_query?.get == null) {84throw Error("make typescript happy");85}86schema.project_log_all.user_query.get.pg_where = ["projects"];87schema.project_log_all.user_query.get.options = [88{ order_by: "-time" },89{ limit: 7500 },90];9192Table({93name: "crm_project_log",94rules: {95virtual: "project_log",96primary_key: "id",97user_query: {98get: {99admin: true, // only admins can do get queries on this table100fields: schema.project_log.user_query?.get?.fields ?? {},101},102},103},104fields: schema.project_log.fields,105});106107108