Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: clean up legacy policy (#6053)

ecmadao5571ff16179c
diff --git a/frontend/src/components/DatabaseBackup/DatabaseBackupSettingForm.vue b/frontend/src/components/DatabaseBackup/DatabaseBackupSettingForm.vue
index 94f74c0763..a8be86c939 100644
--- a/frontend/src/components/DatabaseBackup/DatabaseBackupSettingForm.vue
+++ b/frontend/src/components/DatabaseBackup/DatabaseBackupSettingForm.vue
@@ -47,7 +47,10 @@
</NPopover>
</div>
- <div v-if="checkedSchedule === 'WEEKLY'" class="flex flex-col gap-y-2">
+ <div
+ v-if="checkedSchedule === BackupPlanSchedule.WEEKLY"
+ class="flex flex-col gap-y-2"
+ >
<label class="textlabel">
{{ $t("database.backup-setting.form.day-of-week") }}
</label>
@@ -68,7 +71,10 @@
</div>
<div
- v-if="checkedSchedule === 'WEEKLY' || checkedSchedule === 'DAILY'"
+ v-if="
+ checkedSchedule === BackupPlanSchedule.WEEKLY ||
+ checkedSchedule === BackupPlanSchedule.DAILY
+ "
class="flex flex-col gap-y-2"
>
<label class="textlabel">
@@ -95,7 +101,10 @@
</div>
<div
- v-if="checkedSchedule === 'WEEKLY' || checkedSchedule === 'DAILY'"
+ v-if="
+ checkedSchedule === BackupPlanSchedule.WEEKLY ||
+ checkedSchedule === BackupPlanSchedule.DAILY
+ "
class="flex flex-col gap-y-2"
>
<label class="textlabel">
@@ -143,13 +152,7 @@
import { computed, PropType, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
import { NPopover } from "naive-ui";
-import {
- BackupPlanPolicySchedule,
- BackupSetting,
- BackupSettingUpsert,
- Database,
- unknown,
-} from "@/types";
+import { BackupSetting, BackupSettingUpsert, Database, unknown } from "@/types";
import {
AVAILABLE_DAYS_OF_WEEK,
AVAILABLE_HOURS_OF_DAY,
@@ -162,6 +165,7 @@ import {
BackupSettingEdit,
} from "./utils";
import { pushNotification, useBackupStore } from "@/store";
+import { BackupPlanSchedule } from "@/types/proto/v1/org_policy_service";
type LocalState = {
setting: BackupSettingEdit;
@@ -181,8 +185,8 @@ const props = defineProps({
type: Boolean,
},
backupPolicy: {
- type: String as PropType<BackupPlanPolicySchedule>,
- default: "UNSET",
+ type: Object as PropType<BackupPlanSchedule>,
+ default: BackupPlanSchedule.UNSET,
},
backupSetting: {
type: Object as PropType<BackupSetting>,
@@ -205,7 +209,7 @@ const backupStore = useBackupStore();
const { t } = useI18n();
const allowDisableAutoBackup = computed(() => {
- return props.allowAdmin && props.backupPolicy == "UNSET";
+ return props.allowAdmin && props.backupPolicy == BackupPlanSchedule.UNSET;
});
const daysOfWeek = computed(() => [
@@ -226,7 +230,7 @@ watch(
{ deep: true }
);
-const checkedSchedule = computed((): BackupPlanPolicySchedule => {
+const checkedSchedule = computed((): BackupPlanSchedule => {
return parseScheduleFromBackupSetting(state.setting);
});
@@ -290,7 +294,7 @@ const handleSave = async () => {
}
};
-function setSchedule(schedule: BackupPlanPolicySchedule) {
+function setSchedule(schedule: BackupPlanSchedule) {
if (!isAllowedScheduleByPolicy(schedule)) {
// show a popup and automatically disappear after several seconds
state.showBackupPolicyEnforcement = true;
@@ -317,10 +321,10 @@ function setSchedule(schedule: BackupPlanPolicySchedule) {
};
switch (schedule) {
- case "UNSET":
+ case BackupPlanSchedule.UNSET:
setting.enabled = false;
break;
- case "WEEKLY":
+ case BackupPlanSchedule.WEEKLY:
setting.enabled = true;
if (setting.dayOfWeek < 0) {
setting.dayOfWeek = 0;
@@ -330,7 +334,7 @@ function setSchedule(schedule: BackupPlanPolicySchedule) {
}
normalizeHour();
break;
- case "DAILY":
+ case BackupPlanSchedule.DAILY:
setting.enabled = true;
setting.dayOfWeek = -1;
if (!setting.retentionPeriodTs || setting.retentionPeriodTs <= 0) {
@@ -377,10 +381,8 @@ function extractEditValue(backupSetting: BackupSetting): BackupSettingEdit {
};
}
-function isAllowedScheduleByPolicy(
- schedule: BackupPlanPolicySchedule
-): boolean {
- if (schedule === "UNSET") {
+function isAllowedScheduleByPolicy(schedule: BackupPlanSchedule): boolean {
+ if (schedule === BackupPlanSchedule.UNSET) {
return allowDisableAutoBackup.value;
}
@@ -388,19 +390,21 @@ function isAllowedScheduleByPolicy(
// can be set separately.
// Now, the database backup policy can be configured when its environment
// backup policy is "Not enforced"
- return props.backupPolicy === schedule || props.backupPolicy === "UNSET";
+ return (
+ props.backupPolicy === schedule ||
+ props.backupPolicy === BackupPlanSchedule.UNSET
+ );
}
-function nameOfSchedule(schedule: BackupPlanPolicySchedule): string {
+function nameOfSchedule(schedule: BackupPlanSchedule): string {
switch (schedule) {
- case "UNSET":
- return t("database.backup-setting.schedule.disabled");
- case "WEEKLY":
+ case BackupPlanSchedule.WEEKLY:
return t("database.backup-setting.schedule.weekly");
- case "DAILY":
+ case BackupPlanSchedule.DAILY:
return t("database.backup-setting.schedule.daily");
+ default:
+ return t("database.backup-setting.schedule.disabled");
}
- console.assert(false, "should never reach this line");
}
function nameOfDay(day: number): string {
diff --git a/frontend/src/components/DatabaseBackup/utils.ts b/frontend/src/components/DatabaseBackup/utils.ts
index 6ba3f3affb..718bcaa7df 100644
--- a/frontend/src/components/DatabaseBackup/utils.ts
+++ b/frontend/src/components/DatabaseBackup/utils.ts
@@ -1,14 +1,15 @@
-import { BackupPlanPolicySchedule, BackupSetting } from "@/types";
+import { BackupSetting } from "@/types";
+import { BackupPlanSchedule } from "@/types/proto/v1/org_policy_service";
export type BackupSettingEdit = Pick<
BackupSetting,
"enabled" | "dayOfWeek" | "hour" | "retentionPeriodTs"
>;
-export const PLAN_SCHEDULES: BackupPlanPolicySchedule[] = [
- "UNSET",
- "WEEKLY",
- "DAILY",
+export const PLAN_SCHEDULES: BackupPlanSchedule[] = [
+ BackupPlanSchedule.UNSET,
+ BackupPlanSchedule.WEEKLY,
+ BackupPlanSchedule.DAILY,
];
export const AVAILABLE_DAYS_OF_WEEK = [...Array(7).keys()]; // [0...6]
@@ -20,13 +21,13 @@ export const DEFAULT_BACKUP_RETENTION_PERIOD_TS =
export function parseScheduleFromBackupSetting(
backupSetting: BackupSettingEdit
-) {
- if (!backupSetting.enabled) return "UNSET";
- if (backupSetting.dayOfWeek === -1) return "DAILY";
- return "WEEKLY";
+): BackupPlanSchedule {
+ if (!backupSetting.enabled) return BackupPlanSchedule.UNSET;
+ if (backupSetting.dayOfWeek === -1) return BackupPlanSchedule.DAILY;
+ return BackupPlanSchedule.WEEKLY;
}
-export function levelOfSchedule(schedule: BackupPlanPolicySchedule) {
+export function levelOfSchedule(schedule: BackupPlanSchedule) {
return PLAN_SCHEDULES.indexOf(schedule) || 0;
}
diff --git a/frontend/src/components/DatabaseBackupPanel.vue b/frontend/src/components/DatabaseBackupPanel.vue
index 7faa272b08..15b4ba931c 100644
--- a/frontend/src/components/DatabaseBackupPanel.vue
+++ b/frontend/src/components/DatabaseBackupPanel.vue
@@ -182,7 +182,6 @@ import {
POLL_JITTER,
MINIMUM_POLL_INTERVAL,
UNKNOWN_ID,
- BackupPlanPolicySchedule,
} from "../types";
import BackupTable from "../components/BackupTable.vue";
import DatabaseBackupCreateForm from "../components/DatabaseBackupCreateForm.vue";
@@ -195,7 +194,10 @@ import {
localFromUTC,
parseScheduleFromBackupSetting,
} from "@/components/DatabaseBackup/";
-import { usePolicyV1Store } from "@/store/modules/v1/policy";
+import {
+ usePolicyV1Store,
+ defaultBackupSchedule,
+} from "@/store/modules/v1/policy";
import { getEnvironmentPathByLegacyEnvironment } from "@/store/modules/v1/common";
import {
PolicyType,
@@ -359,21 +361,14 @@ export default defineComponent({
return state.autoBackupRetentionPeriodTs / 3600 / 24;
});
- const backupPolicy = computed((): BackupPlanPolicySchedule => {
+ const backupPolicy = computed((): BackupPlanSchedule => {
const policy = policyV1Store.getPolicyByParentAndType({
parentPath: getEnvironmentPathByLegacyEnvironment(
props.database.instance.environment
),
policyType: PolicyType.BACKUP_PLAN,
});
- switch (policy?.backupPlanPolicy?.schedule) {
- case BackupPlanSchedule.DAILY:
- return "DAILY";
- case BackupPlanSchedule.WEEKLY:
- return "WEEKLY";
- default:
- return "UNSET";
- }
+ return policy?.backupPlanPolicy?.schedule ?? defaultBackupSchedule;
});
const hasBackupPolicyViolation = computed((): boolean => {
diff --git a/frontend/src/store/modules/sqlReview.ts b/frontend/src/store/modules/sqlReview.ts
index 65df07cff4..151339e81c 100644
--- a/frontend/src/store/modules/sqlReview.ts
+++ b/frontend/src/store/modules/sqlReview.ts
@@ -1,10 +1,8 @@
import { pullAt } from "lodash-es";
import {
- empty,
PolicyId,
EnvironmentId,
RowStatus,
- EMPTY_ID,
SchemaPolicyRule,
SQLReviewPolicy,
IdType,
@@ -259,10 +257,6 @@ export const useSQLReviewStore = defineStore("sqlReview", {
getReviewPolicyByEnvironmentUID(
environmentUID: EnvironmentId
): SQLReviewPolicy | undefined {
- if (environmentUID == EMPTY_ID) {
- return empty("SQL_REVIEW") as SQLReviewPolicy;
- }
-
return this.reviewPolicyList.find(
(g) => g.environment.uid == environmentUID
);
diff --git a/frontend/src/types/anomaly.ts b/frontend/src/types/anomaly.ts
index 2b6b9e6c59..fc00229862 100644
--- a/frontend/src/types/anomaly.ts
+++ b/frontend/src/types/anomaly.ts
@@ -1,6 +1,5 @@
import {
AnomalyId,
- BackupPlanPolicySchedule,
Database,
DatabaseId,
EnvironmentId,
@@ -9,6 +8,7 @@ import {
Principal,
RowStatus,
} from ".";
+import { BackupPlanSchedule } from "@/types/proto/v1/org_policy_service";
export type AnomalyType =
| "bb.anomaly.instance.connection"
@@ -24,12 +24,12 @@ export type AnomalyInstanceConnectionPayload = {
export type AnomalyDatabaseBackupPolicyViolationPayload = {
environmentId: EnvironmentId;
- expectedSchedule: BackupPlanPolicySchedule;
- actualSchedule: BackupPlanPolicySchedule;
+ expectedSchedule: BackupPlanSchedule;
+ actualSchedule: BackupPlanSchedule;
};
export type AnomalyDatabaseBackupMissingPayload = {
- expectedSchedule: BackupPlanPolicySchedule;
+ expectedSchedule: BackupPlanSchedule;
lastBackupTs: number;
};
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index e504f10c62..e88cd15c0b 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -16,10 +16,11 @@ import { Principal } from "./principal";
import { Project, ProjectMember } from "./project";
import { Repository } from "./repository";
import { VCS } from "./vcs";
-import { Policy } from "./policy";
import { Sheet } from "./sheet";
import { SQLReviewPolicy } from "./sqlReview";
import { AuditLog, AuditActivityType, AuditActivityLevel } from "./auditLog";
+import { BackupPlanSchedule } from "@/types/proto/v1/org_policy_service";
+import { EnvironmentTier } from "@/types/proto/v1/environment_service";
// System bot id
export const SYSTEM_BOT_ID = 1;
@@ -143,7 +144,6 @@ interface ResourceMaker {
(type: "BACKUP_SETTING"): BackupSetting;
(type: "ISSUE"): Issue;
(type: "PIPELINE"): Pipeline;
- (type: "POLICY"): Policy;
(type: "STAGE"): Stage;
(type: "TASK_PROGRESS"): TaskProgress;
(type: "TASK"): Task;
@@ -182,7 +182,7 @@ const makeUnknown = (type: ResourceType) => {
rowStatus: "NORMAL",
name: "<<Unknown environment>>",
order: 0,
- tier: "UNPROTECTED",
+ tier: EnvironmentTier.UNPROTECTED,
};
const UNKNOWN_PROJECT: Project = {
@@ -402,8 +402,8 @@ const makeUnknown = (type: ResourceType) => {
severity: "MEDIUM",
payload: {
environmentId: UNKNOWN_ID,
- expectedSchedule: "DAILY",
- actualSchedule: "UNSET",
+ expectedSchedule: BackupPlanSchedule.DAILY,
+ actualSchedule: BackupPlanSchedule.UNSET,
},
};
@@ -501,7 +501,7 @@ const makeEmpty = (type: ResourceType) => {
rowStatus: "NORMAL",
name: "",
order: 0,
- tier: "UNPROTECTED",
+ tier: EnvironmentTier.UNPROTECTED,
};
const EMPTY_PROJECT: Project = {
@@ -721,8 +721,8 @@ const makeEmpty = (type: ResourceType) => {
severity: "MEDIUM",
payload: {
environmentId: EMPTY_ID,
- expectedSchedule: "DAILY",
- actualSchedule: "UNSET",
+ expectedSchedule: BackupPlanSchedule.DAILY,
+ actualSchedule: BackupPlanSchedule.UNSET,
},
};
@@ -749,14 +749,6 @@ const makeEmpty = (type: ResourceType) => {
size: 0,
};
- const EMPTY_SQL_REVIEW_POLICY: SQLReviewPolicy = {
- id: EMPTY_ID,
- rowStatus: "NORMAL",
- environment: EMPTY_ENVIRONMENT,
- name: "",
- ruleList: [],
- };
-
const EMPTY_AUDIT_LOG: AuditLog = {
createdTs: 0,
creator: EMPTY_PRINCIPAL.email,
@@ -809,8 +801,6 @@ const makeEmpty = (type: ResourceType) => {
return EMPTY_ANOMALY;
case "SHEET":
return EMPTY_SHEET;
- case "SQL_REVIEW":
- return EMPTY_SQL_REVIEW_POLICY;
case "AUDIT_LOG":
return EMPTY_AUDIT_LOG;
}
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index 21b5f278b6..5c385347ca 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -25,7 +25,6 @@ export * from "./notification";
export * from "./oauth";
export * from "./pipeline";
export * from "./plan";
-export * from "./policy";
export * from "./principal";
export * from "./project";
export * from "./repository";
diff --git a/frontend/src/types/policy.ts b/frontend/src/types/policy.ts
deleted file mode 100644
index 827fb9ec18..0000000000
--- a/frontend/src/types/policy.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-// TODO: retire legacy api
-export type BackupPlanPolicySchedule = "UNSET" | "DAILY" | "WEEKLY";
diff --git a/frontend/src/views/EnvironmentDetail.vue b/frontend/src/views/EnvironmentDetail.vue
index 16e13d76b9..d966087248 100644
--- a/frontend/src/views/EnvironmentDetail.vue
+++ b/frontend/src/views/EnvironmentDetail.vue
@@ -163,16 +163,15 @@ const doUpdate = (environmentPatch: EnvironmentPatch) => {
pendingUpdate.order = environmentPatch.order;
}
if (environmentPatch.tier) {
+ if (
+ pendingUpdate.tier !== defaultEnvironmentTier &&
+ !hasFeature("bb.feature.environment-tier-policy")
+ ) {
+ state.missingRequiredFeature = "bb.feature.environment-tier-policy";
+ return;
+ }
pendingUpdate.tier = environmentPatch.tier;
}
- if (
- pendingUpdate.tier &&
- pendingUpdate.tier !== defaultEnvironmentTier &&
- !hasFeature("bb.feature.environment-tier-policy")
- ) {
- state.missingRequiredFeature = "bb.feature.environment-tier-policy";
- return;
- }
environmentV1Store.updateEnvironment(pendingUpdate).then((environment) => {
assignEnvironment(environment);