Skip to content
Snippets Groups Projects
Unverified Commit a7351e9b authored by Gustavo Saiani's avatar Gustavo Saiani Committed by GitHub
Browse files

When creating database, pass syncing schedule options to api (#17639)

parent 8c33a9d4
No related merge requests found
......@@ -12,6 +12,8 @@ import MetabaseSettings from "metabase/lib/settings";
import { MetabaseApi } from "metabase/services";
import Databases from "metabase/entities/databases";
import { editParamsForUserControlledScheduling } from "./editParamsForUserControlledScheduling";
// Default schedules for db sync and deep analysis
export const DEFAULT_SCHEDULES = {
cache_field_values: {
......@@ -165,10 +167,12 @@ export const proceedWithDbCreation = function(database) {
if (database.details["let-user-control-scheduling"]) {
try {
dispatch.action(VALIDATE_DATABASE_STARTED);
const { valid } = await MetabaseApi.db_validate({ details: database });
if (valid) {
dispatch.action(SET_DATABASE_CREATION_STEP, {
database: database,
database,
step: DB_EDIT_FORM_SCHEDULING_TAB,
});
} else {
......@@ -190,6 +194,8 @@ export const proceedWithDbCreation = function(database) {
};
export const createDatabase = function(database) {
editParamsForUserControlledScheduling(database);
return async function(dispatch, getState) {
try {
dispatch.action(CREATE_DATABASE_STARTED, {});
......
export function editParamsForUserControlledScheduling(database) {
editSyncParamsForUserControlledScheduling(database);
editScheduleParamsForUserControlledScheduling(database);
}
function editSyncParamsForUserControlledScheduling(database) {
if (database.details["let-user-control-scheduling"]) {
database.is_full_sync = false;
}
}
function editScheduleParamsForUserControlledScheduling(database) {
const { details, schedules } = database;
if (details["let-user-control-scheduling"] && !schedules?.metadata_sync) {
database.schedules.metadata_sync = {
schedule_type: "daily",
};
}
}
import { editParamsForUserControlledScheduling } from "./editParamsForUserControlledScheduling";
it("adds full_sync param if user will control scheduling", () => {
const database = {
schedules: {},
details: { "let-user-control-scheduling": true },
};
editParamsForUserControlledScheduling(database);
expect(database.is_full_sync).toBe(false);
});
it("does not add full_sync param if user will not control scheduling", () => {
const database = {
schedules: {},
details: {},
};
editParamsForUserControlledScheduling(database);
expect(database.is_full_sync).toBe(undefined);
});
it("adds metadata_sync param if user will control scheduling and no metadata_sync data is present", () => {
const database = {
schedules: {},
details: { "let-user-control-scheduling": true },
};
editParamsForUserControlledScheduling(database);
expect(database.schedules.metadata_sync.schedule_type).toBe("daily");
});
it("does not add metadata_sync param if user will not control scheduling", () => {
const database = {
schedules: {},
details: {},
};
editParamsForUserControlledScheduling(database);
expect(database.schedules).toStrictEqual({});
});
it("does not add metadata_sync param if user will control scheduling and metadata_sync data is present", () => {
const database = {
schedules: { metadata_sync: { schedule_type: "hourly" } },
details: { "let-user-control-scheduling": true },
};
editParamsForUserControlledScheduling(database);
expect(database.schedules.metadata_sync.schedule_type).toBe("hourly");
});
......@@ -184,7 +184,7 @@ describe("scenarios > admin > databases > add", () => {
);
});
it.skip("should respect users' decision to manually sync large database (metabase#17450)", () => {
it("should respect users' decision to manually sync large database (metabase#17450)", () => {
const H2_CONNECTION_STRING =
"zip:./target/uberjar/metabase.jar!/sample-dataset.db;USER=GUEST;PASSWORD=guest";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment