Path: blob/master/src/packages/database/postgres/personal.ts
1503 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Functionality related to running cocalc in personal mode.7*/89import { PostgreSQL } from "./types";10import { reuseInFlight } from "@cocalc/util/reuse-in-flight";11import { uuid } from "@cocalc/util/misc";1213async function _get_personal_user(database: PostgreSQL): Promise<string> {14// Get account_id of the one and only user, or if there is no user, create one and return its account_id.1516const result = await database.async_query({17query:18"SELECT account_id FROM accounts WHERE created is not NULL ORDER BY created LIMIT 1",19});20for (const row of result.rows) {21return row.account_id;22}23// No results, so create THE account.24const account_id = uuid();25await database.async_query({26query: "INSERT INTO accounts",27values: {28account_id,29first_name: "Your",30last_name: "Name",31created: new Date(),32groups: ["admin"],33},34});35return account_id;36}3738export const get_personal_user = reuseInFlight(_get_personal_user, {39createKey: () => "",40});414243