gristlabs_grist-core/app/gen-server/lib/Activations.ts
Paul Fitzpatrick d7b3fb972c (core) upgrade typeorm so we can support newer postgres
Summary:
upgrade typeorm version, so Grist can run against newer versions of postgres.

Dusted off some old benchmarking code to verify that important queries don't get slower. They don't appear to, unlike for some intermediate versions of typeorm I tried in the past.

Most of the changes are because `findOne` changed how it interprets its arguments, and the value it returns when nothing is found. For the return value, I stuck with limiting its impact by emulating old behavior (returning undefined rather than null) rather than propagating the change out to parts of the code unrelated to the database.

Test Plan: existing tests pass; manual testing with postgres 10 and 14

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3613
2022-09-02 15:34:21 -04:00

29 lines
986 B
TypeScript

import { makeId } from 'app/server/lib/idUtils';
import { Activation } from 'app/gen-server/entity/Activation';
import { HomeDBManager } from 'app/gen-server/lib/HomeDBManager';
/**
* Manage activations. Not much to do currently, there is at most one
* activation. The activation singleton establishes an id and creation
* time for the installation.
*/
export class Activations {
constructor(private _db: HomeDBManager) {
}
// Get the current activation row, creating one if necessary.
// It will be created with an empty key column, which will get
// filled in once an activation key is presented.
public current(): Promise<Activation> {
return this._db.connection.manager.transaction(async manager => {
let activation = await manager.findOne(Activation, {where: {}});
if (!activation) {
activation = manager.create(Activation);
activation.id = makeId();
await activation.save();
}
return activation;
});
}
}