Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/util/db-schema/project-log.ts
Views: 687
/*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";89Table({10name: "project_log",11rules: {12primary_key: "id",13// db_standby feels too slow for this, since the user only14// does this query when they actually click to show the log.15//db_standby: "unsafe",16durability: "soft", // dropping a log entry (e.g., "foo opened a file") wouldn't matter much1718pg_indexes: ["project_id", "time"],1920user_query: {21get: {22pg_where: ["time >= NOW() - interval '2 months'", "projects"],23pg_changefeed: "projects",24options: [{ order_by: "-time" }, { limit: 300 }],25throttle_changes: 2000,26fields: {27id: null,28project_id: null,29time: null,30account_id: null,31event: null,32},33},34set: {35fields: {36id(obj) {37return obj.id != null ? obj.id : uuid();38},39project_id: "project_write",40account_id: "account_id",41time: true,42event: true,43},44},45},46},47fields: {48id: {49type: "uuid",50desc: "which",51},52project_id: {53type: "uuid",54desc: "where",55render: { type: "project_link" },56},57time: {58type: "timestamp",59desc: "when",60},61account_id: {62type: "uuid",63desc: "who",64render: { type: "account" },65},66event: {67type: "map",68desc: "what",69render: { type: "json" },70},71},72});7374// project_log_all -- exactly like project_log, but loads up75// to the most recent **many** log entries (so a LOT).76schema.project_log_all = deep_copy(schema.project_log);77// This happens rarely, and user is prepared to wait.78schema.project_log_all.db_standby = "unsafe";79schema.project_log_all.virtual = "project_log";80// no time constraint:81if (schema.project_log_all.user_query?.get == null) {82throw Error("make typescript happy");83}84schema.project_log_all.user_query.get.pg_where = ["projects"];85schema.project_log_all.user_query.get.options = [86{ order_by: "-time" },87{ limit: 7500 },88];8990Table({91name: "crm_project_log",92rules: {93virtual: "project_log",94primary_key: "id",95user_query: {96get: {97admin: true, // only admins can do get queries on this table98fields: schema.project_log.user_query?.get?.fields ?? {},99},100},101},102fields: schema.project_log.fields,103});104105106