Skip to content

Commit

Permalink
✨ feat(settings): remove force introspection
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Nov 22, 2023
1 parent 08342c3 commit 0852ed5
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 62 deletions.
1 change: 0 additions & 1 deletion src/__tests__/_/api-handlers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const ENTITY_VIEWS = (entity: string): ITableTab[] => [

const CONFIG_VALUES = {
system_settings: {
forceIntrospection: true,
tokenValidityDurationInDays: 5,
},
site_settings: {
Expand Down
4 changes: 0 additions & 4 deletions src/__tests__/admin/settings/system.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe("pages/admin/settings/system", () => {
screen.getByLabelText("Token Validity Duration In Days")
).toHaveValue(5);
});
expect(screen.getByLabelText("Force Introspection")).toBeChecked();
});

it("should update system settings successfully", async () => {
Expand All @@ -42,8 +41,6 @@ describe("pages/admin/settings/system", () => {
"9"
);

userEvent.click(screen.getByLabelText("Force Introspection"));

await userEvent.click(
screen.getByRole("button", { name: "Save System Settings" })
);
Expand All @@ -64,6 +61,5 @@ describe("pages/admin/settings/system", () => {
screen.getByLabelText("Token Validity Duration In Days")
).toHaveValue(59);
});
expect(screen.getByLabelText("Force Introspection")).not.toBeChecked();
});
});
1 change: 0 additions & 1 deletion src/__tests__/api/_test-utils/_app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const TEST_APP_CONFIG: Partial<Record<string, unknown>> = {
plural: "Base Model Plural",
},
system_settings: {
forceIntrospection: false,
tokenValidityDurationInDays: 1,
},
};
Expand Down
46 changes: 22 additions & 24 deletions src/backend/schema/__tests__/schema.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { credentialsApiService } from "backend/integrations-configurations";
import { createConfigDomainPersistenceService } from "backend/lib/config-persistence";
import { IDBSchema } from "shared/types/db";
import { configurationApiService } from "backend/configuration/configuration.service";
import {
setupAppConfigTestData,
setupCredentialsTestData,
} from "__tests__/api/_test-utils";
import { setupCredentialsTestData } from "__tests__/api/_test-utils";
import { getDbConnection } from "backend/lib/connection/db";
import { SchemasApiService } from "../schema.service";

Expand Down Expand Up @@ -45,15 +41,14 @@ const setupTestDatabaseData = async (modified: boolean) => {
};

describe("SchemaService", () => {
const OLD_ENV = process.env;
const schemaPersistenceService =
createConfigDomainPersistenceService<IDBSchema>("schema");

beforeAll(async () => {
await setupAppConfigTestData({
system_settings: {
forceIntrospection: false,
},
});
// @ts-ignore
process.env.NODE_ENV = "development";

await setupCredentialsTestData({
DATABASE___dataSourceType:
"aad0f7e776963ae66b7459222d54871433f8e119ab9a9712d4e82e8cbb77246e47a750a773c0ea316c110a1d3f2ee16c2509906fb89f1c4b039d09f139b1d7eacc26908c25137c46f269cfb13f63221da2f1631bf4f59cbe14cc18cbfb8993098bd7e2d865f20717",
Expand All @@ -66,11 +61,19 @@ describe("SchemaService", () => {
await schemaPersistenceService.resetState("name", []);
});

beforeEach(() => {
jest.resetModules();
process.env = { ...OLD_ENV };
});

afterEach(() => {
process.env = OLD_ENV;
});

it("should introspect database correctly when there is no schema data", async () => {
const schemasService = new SchemasApiService(
schemaPersistenceService,
credentialsApiService,
configurationApiService
credentialsApiService
);

expect(JSON.parse(JSON.stringify(await schemasService.getDBSchema())))
Expand Down Expand Up @@ -163,31 +166,26 @@ describe("SchemaService", () => {
`);
});

it("should not introspect database when schema data already exists when `forceIntrospection` is `false`", async () => {
it("should not introspect database when schema data already exists when not on PROD", async () => {
const schemasService = new SchemasApiService(
schemaPersistenceService,
credentialsApiService,
configurationApiService
credentialsApiService
);

await setupTestDatabaseData(true);

expect(await schemasService.getDBSchema()).toHaveLength(2);
});

it("should introspect database when schema data already exists when `forceIntrospection` is `true`", async () => {
it("should introspect database when schema data already exists when on PROD", async () => {
// @ts-ignore
process.env.NODE_ENV = "production";

const schemasService = new SchemasApiService(
schemaPersistenceService,
credentialsApiService,
configurationApiService
credentialsApiService
);

await setupAppConfigTestData({
system_settings: {
forceIntrospection: true,
},
});

await setupTestDatabaseData(true);

expect(await schemasService.getDBSchema()).toHaveLength(3);
Expand Down
14 changes: 3 additions & 11 deletions src/backend/schema/schema.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { introspect, Entity } from "@dashpress/bacteria";
import {
ConfigurationApiService,
configurationApiService,
} from "backend/configuration/configuration.service";
import {
CredentialsApiService,
credentialsApiService,
Expand All @@ -22,8 +18,7 @@ export class SchemasApiService implements IApplicationService {

constructor(
private _schemaConfigDataPersistenceService: AbstractConfigDataPersistenceService<IDBSchema>,
private _credentialsService: CredentialsApiService,
private _configurationService: ConfigurationApiService
private _credentialsService: CredentialsApiService
) {}

async bootstrap() {
Expand All @@ -50,9 +45,7 @@ export class SchemasApiService implements IApplicationService {
}

private async initDBSchema() {
if (
await this._configurationService.getSystemSettings("forceIntrospection")
) {
if (process.env.NODE_ENV === "production") {
return await this.doIntrospection();
}

Expand Down Expand Up @@ -159,6 +152,5 @@ const schemaPersistenceService =

export const schemasApiService = new SchemasApiService(
schemaPersistenceService,
credentialsApiService,
configurationApiService
credentialsApiService
);
10 changes: 0 additions & 10 deletions src/frontend/docs/system-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ export function SystemSettingsDocumentation(props: IDocumentationRootProps) {
that invalidation duration.
</p>

<h4>Force Introspection</h4>
<p>
We introspect your database every time the application runs and save the
schema. This behavior is good for 99% of production use cases as you
want the schema to be up to date whenever you run the application so
that DashPress shows you the latest database changes. In case you do not
want your schema up to date for any reason then you can always toggle
this off here.
</p>

<InfoAlert message="This setting is not respected when your schema is empty so we will always introspect when running for the first time or if you delete the saved schema for any reason." />
</DocumentationRoot>
);
Expand Down
4 changes: 0 additions & 4 deletions src/frontend/views/settings/System/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export function SystemSettingsForm({
},
],
},
forceIntrospection: {
type: "boolean",
validations: [],
},
}}
/>
);
Expand Down
6 changes: 1 addition & 5 deletions src/frontend/views/settings/System/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ export function SystemSettings() {
<ViewStateMachine
loading={systemSettings.isLoading}
error={systemSettings.error}
loader={
<FormSkeleton
schema={[FormSkeletonSchema.Input, FormSkeletonSchema.Input]}
/>
}
loader={<FormSkeleton schema={[FormSkeletonSchema.Input]} />}
>
<SystemSettingsForm
onSubmit={async (values) => {
Expand Down
2 changes: 0 additions & 2 deletions src/shared/configurations/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import {
} from "./portal";

export type IBaseSystemSettings = {
forceIntrospection: boolean;
tokenValidityDurationInDays: number;
};

export type ISystemSettings = IBaseSystemSettings & IPortalSystemSettings;

export const DEFAULT_SYSTEM_SETTINGS: ISystemSettings = {
...PORTAL_DEFAULT_SYSTEM_SETTINGS,
forceIntrospection: process.env.NODE_ENV === "production",
tokenValidityDurationInDays: 14,
};

0 comments on commit 0852ed5

Please sign in to comment.