mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-12-03 16:10:37 +00:00
fix: refuse objects built on a continuous aggregate, show copy warnings in the cli and import
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
443fc4a589
commit
4c71c42e49
@@ -262,7 +262,7 @@ async fn read_hypertables(
|
||||
// A continuous aggregate's view reads a materialization hypertable in `_timescaledb_internal`,
|
||||
// which the dump leaves out, so its definition would fail to replay. It is left out with every
|
||||
// view built on it, and the copy has none of them.
|
||||
plan.left_out_views = client
|
||||
let left_out = client
|
||||
.query(
|
||||
"WITH RECURSIVE dependent(oid) AS (
|
||||
SELECT format('%I.%I', view_schema, view_name)::regclass::oid
|
||||
@@ -273,7 +273,7 @@ async fn read_hypertables(
|
||||
JOIN pg_rewrite r ON d.classid = 'pg_rewrite'::regclass AND r.oid = d.objid
|
||||
WHERE r.ev_class <> dependent.oid
|
||||
)
|
||||
SELECT n.nspname::text, c.relname::text
|
||||
SELECT n.nspname::text, c.relname::text, c.oid
|
||||
FROM dependent
|
||||
JOIN pg_class c ON c.oid = dependent.oid
|
||||
JOIN pg_namespace n ON n.oid = c.relnamespace
|
||||
@@ -282,7 +282,8 @@ async fn read_hypertables(
|
||||
&[&TIMESCALEDB_INTERNAL],
|
||||
)
|
||||
.await
|
||||
.map_err(source_err(dbname))?
|
||||
.map_err(source_err(dbname))?;
|
||||
plan.left_out_views = left_out
|
||||
.iter()
|
||||
.map(|row| {
|
||||
format!(
|
||||
@@ -292,6 +293,34 @@ async fn read_hypertables(
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
// Anything else built on them, such as a function reading one or returning its row type, would
|
||||
// be dumped and fail to replay without them.
|
||||
let oids: Vec<u32> = left_out.iter().map(|row| row.get(2)).collect();
|
||||
let dependents: Vec<String> = client
|
||||
.query(
|
||||
"SELECT DISTINCT pg_describe_object(d.classid, d.objid, d.objsubid)
|
||||
FROM pg_depend d
|
||||
WHERE d.deptype = 'n'
|
||||
AND (d.refclassid = 'pg_class'::regclass AND d.refobjid = ANY($1)
|
||||
OR d.refclassid = 'pg_type'::regclass AND d.refobjid IN (
|
||||
SELECT reltype FROM pg_class WHERE oid = ANY($1)))
|
||||
AND NOT (d.classid = 'pg_rewrite'::regclass AND EXISTS (
|
||||
SELECT 1 FROM pg_rewrite r WHERE r.oid = d.objid AND r.ev_class = ANY($1)))
|
||||
ORDER BY 1",
|
||||
&[&oids],
|
||||
)
|
||||
.await
|
||||
.map_err(source_err(dbname))?
|
||||
.iter()
|
||||
.map(|row| row.get(0))
|
||||
.collect();
|
||||
if !dependents.is_empty() {
|
||||
return Err(Error::BadRequest(format!(
|
||||
"Database '{dbname}' has objects built on TimescaleDB continuous aggregates, which a \
|
||||
copy leaves out: {}",
|
||||
dependents.join(", ")
|
||||
)));
|
||||
}
|
||||
|
||||
// A chunk inherits from its hypertable, internal compressed ones included, in every
|
||||
// TimescaleDB version, while its catalog's columns differ between them.
|
||||
|
||||
@@ -12012,7 +12012,7 @@ async fn archive_workspace(
|
||||
.fetch_optional(&db)
|
||||
.await?
|
||||
.unwrap_or(false)
|
||||
&& !authed.admin_withheld;
|
||||
&& !authed.admin_withheld;
|
||||
if !is_prod_admin && !windmill_api_auth::is_super_admin_authed(&db, &authed).await? {
|
||||
return Err(Error::PermissionDenied(format!(
|
||||
"Archiving dev workspace '{w_id}' requires being an admin of its parent prod workspace '{prod}' (or a superadmin)"
|
||||
|
||||
@@ -24,7 +24,11 @@ import {
|
||||
} from "../../core/conf.ts";
|
||||
|
||||
/** Wait for a fork creation started in the background, by the id its request answered with. */
|
||||
async function waitForForkCreation(parentWorkspace: string, creationId: string) {
|
||||
/** Resolves to what the created fork goes without. */
|
||||
async function waitForForkCreation(
|
||||
parentWorkspace: string,
|
||||
creationId: string,
|
||||
): Promise<string[]> {
|
||||
let failingSince: number | undefined;
|
||||
let lastStep: string | undefined;
|
||||
while (true) {
|
||||
@@ -47,7 +51,7 @@ async function waitForForkCreation(parentWorkspace: string, creationId: string)
|
||||
lastStep = result.step;
|
||||
log.info(colors.gray(`${lastStep}...`));
|
||||
}
|
||||
if (result?.status === "completed") return;
|
||||
if (result?.status === "completed") return result.warnings ?? [];
|
||||
if (result?.status === "failed") {
|
||||
throw new Error(result.error ?? "Unknown error");
|
||||
}
|
||||
@@ -355,7 +359,7 @@ async function createWorkspaceFork(
|
||||
)
|
||||
);
|
||||
|
||||
await wmill.importPgDatabase({
|
||||
const imported = await wmill.importPgDatabase({
|
||||
workspace: workspace.workspaceId,
|
||||
requestBody: {
|
||||
source: `datatable://${dt.name}`,
|
||||
@@ -365,6 +369,9 @@ async function createWorkspaceFork(
|
||||
},
|
||||
});
|
||||
|
||||
for (const warning of imported.split("\n").slice(1)) {
|
||||
log.warn(colors.yellow(` ${warning}`));
|
||||
}
|
||||
log.info(colors.green(` ✓ Datatable "${dt.name}" cloned.`));
|
||||
forkedDatatables.push({ name: dt.name, new_dbname: newDbName });
|
||||
} catch (e) {
|
||||
@@ -420,8 +427,11 @@ async function createWorkspaceFork(
|
||||
},
|
||||
});
|
||||
// A server without background forks ignores the flag and answers once the fork is created.
|
||||
if (!response.startsWith("Created forked workspace")) {
|
||||
await waitForForkCreation(workspace.workspaceId, response);
|
||||
const warnings = response.startsWith("Created forked workspace")
|
||||
? response.split("\n").slice(1)
|
||||
: await waitForForkCreation(workspace.workspaceId, response);
|
||||
for (const warning of warnings) {
|
||||
log.warn(colors.yellow(warning));
|
||||
}
|
||||
|
||||
log.info(colors.green(`✅ Created forked workspace ${trueWorkspaceId}`));
|
||||
|
||||
@@ -334,7 +334,7 @@
|
||||
if (!target) return
|
||||
importLoading = true
|
||||
try {
|
||||
await WorkspaceService.importPgDatabase({
|
||||
const imported = await WorkspaceService.importPgDatabase({
|
||||
workspace: ws,
|
||||
requestBody: {
|
||||
source: toSourceIdentifier(importSource),
|
||||
@@ -343,6 +343,10 @@
|
||||
}
|
||||
})
|
||||
sendUserToast('Database import completed successfully')
|
||||
// The lines after the first name what the import went without.
|
||||
for (const warning of imported.split('\n').slice(1)) {
|
||||
sendUserToast(warning, 'warning', [], undefined, 20000)
|
||||
}
|
||||
importDrawerOpen = false
|
||||
importSource = undefined
|
||||
dbManagerContent?.refresh()
|
||||
|
||||
Reference in New Issue
Block a user