feat(safety): add production environment safeguards
This commit is contained in:
1 parent
be66d6f46b
commit
1be66fb115
80 files changed
+4220
-234
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import { ref } from "vue";
|
||||
import { defineStore } from "pinia";
|
||||
|
||||
export interface ProductionConfirmationRequest {
|
||||
sql: string;
|
||||
connectionName?: string;
|
||||
database?: string;
|
||||
productionDatabases?: string[];
|
||||
source?: string;
|
||||
}
|
||||
|
||||
interface QueuedConfirmationRequest {
|
||||
request: ProductionConfirmationRequest;
|
||||
resolve: (confirmed: boolean) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Coordinates the single production-write confirmation dialog shared by all
|
||||
* workbench surfaces. The request is intentionally transient and is never
|
||||
* persisted, so every production write requires a fresh user decision.
|
||||
*/
|
||||
export const useProductionSafetyStore = defineStore("productionSafety", () => {
|
||||
const pending = ref<ProductionConfirmationRequest>();
|
||||
const queue: QueuedConfirmationRequest[] = [];
|
||||
let resolvePending: ((confirmed: boolean) => void) | undefined;
|
||||
|
||||
function requestConfirmation(request: ProductionConfirmationRequest): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve) => {
|
||||
if (pending.value) {
|
||||
// Keep concurrent production writes visible instead of silently denying
|
||||
// the later operation while the user is reviewing the current SQL.
|
||||
queue.push({ request, resolve });
|
||||
return;
|
||||
}
|
||||
beginRequest(request, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
function beginRequest(request: ProductionConfirmationRequest, resolve: (confirmed: boolean) => void) {
|
||||
pending.value = request;
|
||||
resolvePending = resolve;
|
||||
}
|
||||
|
||||
function settle(confirmed: boolean) {
|
||||
const resolve = resolvePending;
|
||||
resolvePending = undefined;
|
||||
pending.value = undefined;
|
||||
resolve?.(confirmed);
|
||||
|
||||
const next = queue.shift();
|
||||
if (next) beginRequest(next.request, next.resolve);
|
||||
}
|
||||
|
||||
function confirm() {
|
||||
settle(true);
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
settle(false);
|
||||
}
|
||||
|
||||
return { pending, requestConfirmation, confirm, cancel };
|
||||
});
|
||||
Reference in new issue
Block a user