Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typeorm: Use DataSource instead of Connection #1166

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
314b03e
Start of UsersManager tests
fflorent Aug 2, 2024
2f05943
Test ensureExternalUser()
fflorent Aug 2, 2024
48f5d33
new progress on UsersManager unit tests
fflorent Aug 3, 2024
a6bd18a
test deleteUser()
fflorent Aug 3, 2024
d2b185c
Tests for getLoginWithRetry
fflorent Aug 3, 2024
71e0599
initializeSpecialIds and completeProfiles()
fflorent Aug 4, 2024
f9148fe
Fix tests for initializeSpecialIds()
fflorent Aug 5, 2024
4c0b087
Replace uuid with unique local parts
fflorent Aug 5, 2024
ca18de7
make getUserByLogin return Promise<User> (cannot return Promise<nulli…
fflorent Aug 5, 2024
ad499e3
Also force getUserByLoginWithRetry to return a Promise<User>
fflorent Aug 5, 2024
4ecb24b
Self-remarks
fflorent Aug 6, 2024
d7af3af
Fix test failure for getUserByLoginWithRetry
fflorent Aug 5, 2024
cd68866
Apply suggestions from code review
fflorent Aug 6, 2024
705a34f
More remarks taken into account
fflorent Aug 6, 2024
a5fd314
@berhalak remarks and rework of the static methods tests
fflorent Aug 16, 2024
6476676
Rename generator helper function to be more accurate
fflorent Aug 16, 2024
8ebe474
Make a temp dir with random suffix the tests
fflorent Aug 16, 2024
894c55e
Sort imports
fflorent Aug 16, 2024
55d10b3
Skip tests when using Postgresql
fflorent Aug 19, 2024
e1f97ee
Introduce dereferenceConnection for TypeORM to be used in tests
fflorent Aug 19, 2024
eaaff1b
Fix eslint errors after rebase
fflorent Aug 19, 2024
eb1c177
TypeORM: Attempt to DataSources instead of Connections and other
fflorent Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/gen-server/ApiServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function addOrg(
billing?: BillingOptions,
}
): Promise<number> {
return dbManager.connection.transaction(async manager => {
return dbManager.dataSource.transaction(async manager => {
const user = await manager.findOne(User, {where: {id: userId}});
if (!user) { return handleDeletedUser(); }
const query = await dbManager.addOrg(user, props, {
Expand Down Expand Up @@ -429,7 +429,7 @@ export class ApiServer {
throw new ApiError('Name expected in the body', 400);
}
const name = req.body.name;
await this._dbManager.updateUserName(userId, name);
await this._dbManager.updateUser(userId, { name });
res.sendStatus(200);
}));

Expand Down Expand Up @@ -505,7 +505,7 @@ export class ApiServer {
this._app.post('/api/profile/apikey', expressWrap(async (req, res) => {
const userId = getAuthorizedUserId(req);
const force = req.body ? req.body.force : false;
const manager = this._dbManager.connection.manager;
const manager = this._dbManager.dataSource.manager;
let user = await manager.findOne(User, {where: {id: userId}});
if (!user) { return handleDeletedUser(); }
if (!user.apiKey || force) {
Expand All @@ -520,7 +520,7 @@ export class ApiServer {
// Delete apiKey
this._app.delete('/api/profile/apikey', expressWrap(async (req, res) => {
const userId = getAuthorizedUserId(req);
await this._dbManager.connection.transaction(async manager => {
await this._dbManager.dataSource.transaction(async manager => {
const user = await manager.findOne(User, {where: {id: userId}});
if (!user) { return handleDeletedUser(); }
user.apiKey = null;
Expand Down
2 changes: 1 addition & 1 deletion app/gen-server/lib/Activations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Activations {
// 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 => {
return this._db.dataSource.manager.transaction(async manager => {
let activation = await manager.findOne(Activation, {where: {}});
if (!activation) {
activation = manager.create(Activation);
Expand Down
2 changes: 1 addition & 1 deletion app/gen-server/lib/Doom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class Doom {
}
}
const candidate = sortBy(owners, ['email'])[0];
await scrubUserFromOrg(orgId, userId, candidate.id, this._dbManager.connection.manager);
await scrubUserFromOrg(orgId, userId, candidate.id, this._dbManager.dataSource.manager);
}

// List the sites a user has access to.
Expand Down
14 changes: 7 additions & 7 deletions app/gen-server/lib/Housekeeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class Housekeeper {
log.warn("logMetrics siteUsage starting");
// Avoid using a transaction since it may end up being held up for a while, and for no good
// reason (atomicity matters for this reporting).
const manager = this._dbManager.connection.manager;
const manager = this._dbManager.dataSource.manager;
const usageSummaries = await this._getOrgUsageSummaries(manager);

// We sleep occasionally during this logging. We may log many MANY lines, which can hang up a
Expand All @@ -212,7 +212,7 @@ export class Housekeeper {

if (this._telemetry.shouldLogEvent('siteMembership')) {
log.warn("logMetrics siteMembership starting");
const manager = this._dbManager.connection.manager;
const manager = this._dbManager.dataSource.manager;
const membershipSummaries = await this._getOrgMembershipSummaries(manager);
await forEachWithBreaks("logMetrics siteMembership progress", membershipSummaries, summary => {
this._telemetry.logEvent(null, 'siteMembership', {
Expand Down Expand Up @@ -297,7 +297,7 @@ export class Housekeeper {
}

private async _getDocsToDelete() {
const docs = await this._dbManager.connection.createQueryBuilder()
const docs = await this._dbManager.dataSource.createQueryBuilder()
.select('docs')
.from(Document, 'docs')
.leftJoinAndSelect('docs.workspace', 'workspaces')
Expand All @@ -309,7 +309,7 @@ export class Housekeeper {
}

private async _getWorkspacesToDelete() {
const workspaces = await this._dbManager.connection.createQueryBuilder()
const workspaces = await this._dbManager.dataSource.createQueryBuilder()
.select('workspaces')
.from(Workspace, 'workspaces')
.leftJoin('workspaces.docs', 'docs')
Expand All @@ -323,7 +323,7 @@ export class Housekeeper {
}

private async _getForksToDelete() {
const forks = await this._dbManager.connection.createQueryBuilder()
const forks = await this._dbManager.dataSource.createQueryBuilder()
.select('forks')
.from(Document, 'forks')
.where('forks.trunk_id IS NOT NULL')
Expand Down Expand Up @@ -385,7 +385,7 @@ export class Housekeeper {
* don't have to deal with its caprices.
*/
private _getThreshold() {
return fromNow(this._dbManager.connection.driver.options.type, AGE_THRESHOLD_OFFSET);
return fromNow(this._dbManager.dataSource.driver.options.type, AGE_THRESHOLD_OFFSET);
}

// Call a document endpoint with a permit, cleaning up after the call.
Expand Down Expand Up @@ -475,7 +475,7 @@ export async function fixSiteProducts(options: {
}

// Find all billing accounts on teamFree product and change them to the Free.
return await db.connection.transaction(async (t) => {
return await db.dataSource.transaction(async (t) => {
const freeProduct = await t.findOne(Product, {where: {name: 'Free'}});
const freeTeamProduct = await t.findOne(Product, {where: {name: 'teamFree'}});

Expand Down
2 changes: 1 addition & 1 deletion app/gen-server/lib/Usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Usage {

private async _apply(): Promise<void> {
try {
const manager = this._dbManager.connection.manager;
const manager = this._dbManager.dataSource.manager;
// raw count of users
const userCount = await manager.count(User);
// users who have logged in at least once
Expand Down
Loading
Loading