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

fix(core): disable the db by default #28747

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions packages/nx/src/hasher/hash-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { ProjectGraph } from '../config/project-graph';
import { NxJsonConfiguration } from '../config/nx-json';
import { readNxJson } from '../config/nx-json';
import { HashedTask, IS_WASM, TaskDetails } from '../native';
import { getDbConnection } from '../utils/db-connection';
import { databaseSupportEnabled, getDbConnection } from '../utils/database';

let taskDetails: TaskDetails;

export function getTaskDetails(): TaskDetails | null {
// TODO: Remove when wasm supports sqlite
if (process.env.NX_DISABLE_DB === 'true' || IS_WASM) {
if (!databaseSupportEnabled() || IS_WASM) {
return null;
}
if (!taskDetails) {
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/native/tests/cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TaskDetails, NxCache } from '../index';
import { join } from 'path';
import { TempFs } from '../../internal-testing-utils/temp-fs';
import { rmSync } from 'fs';
import { getDbConnection } from '../../utils/db-connection';
import { getDbConnection } from '../../utils/database';
import { randomBytes } from 'crypto';

describe('Cache', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/native/tests/task_history.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TaskDetails, NxTaskHistory } from '../index';
import { join } from 'path';
import { TempFs } from '../../internal-testing-utils/temp-fs';
import { rmSync } from 'fs';
import { getDbConnection } from '../../utils/db-connection';
import { getDbConnection } from '../../utils/database';
import { randomBytes } from 'crypto';

const dbOutputFolder = 'temp-db-task';
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/tasks-runner/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { cacheDir } from '../utils/cache-directory';
import { Task } from '../config/task-graph';
import { machineId } from 'node-machine-id';
import { NxCache, CachedResult as NativeCacheResult, IS_WASM } from '../native';
import { getDbConnection } from '../utils/db-connection';
import { databaseSupportEnabled, getDbConnection } from '../utils/database';
import { isNxCloudUsed } from '../utils/nx-cloud-utils';
import { NxJsonConfiguration, readNxJson } from '../config/nx-json';
import { verifyOrUpdateNxCloudClient } from '../nx-cloud/update-manager';
Expand All @@ -32,7 +32,7 @@ export type TaskWithCachedResult = { task: Task; cachedResult: CachedResult };
export function dbCacheEnabled(nxJson: NxJsonConfiguration = readNxJson()) {
return (
!IS_WASM &&
process.env.NX_DISABLE_DB !== 'true' &&
databaseSupportEnabled() &&
nxJson.useLegacyCache !== true &&
process.env.NX_DB_CACHE !== 'false'
);
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/tasks-runner/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { shouldStreamOutput } from './utils';
import chalk = require('chalk');
import type { Observable } from 'rxjs';
import { printPowerpackLicense } from '../utils/powerpack';
import { databaseSupportEnabled } from '../utils/database';

async function getTerminalOutputLifeCycle(
initiatingProject: string,
Expand Down Expand Up @@ -711,7 +712,7 @@ function constructLifeCycles(lifeCycle: LifeCycle): LifeCycle[] {
}
if (!isNxCloudUsed(readNxJson())) {
lifeCycles.push(
process.env.NX_DISABLE_DB !== 'true' && !IS_WASM
databaseSupportEnabled() && !IS_WASM
? new TaskHistoryLifeCycle()
: new LegacyTaskHistoryLifeCycle()
);
Expand Down
16 changes: 16 additions & 0 deletions packages/nx/src/utils/database.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { databaseSupportEnabled } from './database';

describe('test if database is enabled', () => {
it('should be disabled by default', () => {
process.env.NX_DISABLE_DB = undefined;
expect(databaseSupportEnabled()).toBe(false);
});
it('should be disabled if NX_DISABLE_DB is explicitly set to `true`', () => {
process.env.NX_DISABLE_DB = 'true';
expect(databaseSupportEnabled()).toBe(false);
});
it('should be enabled if NX_DISABLE_DB is explicitly set to `false`', () => {
process.env.NX_DISABLE_DB = 'false';
expect(databaseSupportEnabled()).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ function getEntryOrSet<TKey, TVal>(
map.set(key, val);
return val;
}

// database is disabled by default
export function databaseSupportEnabled() {
return process.env.NX_DISABLE_DB === 'false';
}
4 changes: 2 additions & 2 deletions packages/nx/src/utils/task-history.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { daemonClient } from '../daemon/client/client';
import { isOnDaemon } from '../daemon/is-on-daemon';
import { IS_WASM, NxTaskHistory, TaskRun, TaskTarget } from '../native';
import { getDbConnection } from './db-connection';
import { databaseSupportEnabled, getDbConnection } from './database';

export class TaskHistory {
taskHistory = new NxTaskHistory(getDbConnection());
Expand Down Expand Up @@ -42,7 +42,7 @@ let taskHistory: TaskHistory;
* @returns singleton instance of TaskHistory, null if database is disabled or WASM is enabled
*/
export function getTaskHistory(): TaskHistory | null {
if (process.env.NX_DISABLE_DB === 'true' || IS_WASM) {
if (!databaseSupportEnabled() || IS_WASM) {
return null;
}

Expand Down