Fix release version labels across deployment views
This commit is contained in:
@@ -171,6 +171,7 @@ function buildRecipe(
|
||||
path: script.target_rel_path,
|
||||
versionId: version.id,
|
||||
version: version.version,
|
||||
releaseVersion: version.release_version,
|
||||
sha256: version.sha256,
|
||||
size: version.size
|
||||
});
|
||||
@@ -187,6 +188,7 @@ function buildRecipe(
|
||||
kind: 'config',
|
||||
versionId: null,
|
||||
version: null,
|
||||
releaseVersion: null,
|
||||
sha256: sha256Buffer(content),
|
||||
size: content.length,
|
||||
...(includeContent ? { content: content.toString('base64') } : {})
|
||||
@@ -249,18 +251,41 @@ export function recipeSummaryForDeployment(
|
||||
)
|
||||
.get(id) as { recipe_summary: string | null; blueprint_name: string | null } | undefined;
|
||||
if (!row) return null;
|
||||
if (row.recipe_summary !== null)
|
||||
return { recipe: JSON.parse(row.recipe_summary), blueprintName: row.blueprint_name };
|
||||
if (row.recipe_summary !== null) {
|
||||
const saved: LaunchRecipeSummary = JSON.parse(row.recipe_summary);
|
||||
const summary = withHistoricalReleaseVersions(saved);
|
||||
if (summary !== saved)
|
||||
db()
|
||||
.prepare(
|
||||
'UPDATE server_launch_recipes SET recipe_summary = ? WHERE deployment_id = ?'
|
||||
)
|
||||
.run(JSON.stringify(summary), id);
|
||||
return { recipe: summary, blueprintName: row.blueprint_name };
|
||||
}
|
||||
// Old snapshots remain readable. Populate on first access, without making
|
||||
// controller startup scan and decode every retained plugin in its history.
|
||||
const launch = recipeForDeployment(id)!;
|
||||
const summary = summarizeRecipe(launch.recipe);
|
||||
const summary = withHistoricalReleaseVersions(summarizeRecipe(launch.recipe));
|
||||
db()
|
||||
.prepare('UPDATE server_launch_recipes SET recipe_summary = ? WHERE deployment_id = ?')
|
||||
.run(JSON.stringify(summary), id);
|
||||
return { recipe: summary, blueprintName: row.blueprint_name };
|
||||
}
|
||||
|
||||
/** Restore display metadata from the exact retained upload, preserving the captured recipe. */
|
||||
function withHistoricalReleaseVersions(summary: LaunchRecipeSummary): LaunchRecipeSummary {
|
||||
const files = summary.files.map((file) => {
|
||||
if (file.releaseVersion !== undefined || file.versionId === null) return file;
|
||||
const version = getVersionMetadata(file.versionId);
|
||||
if (!version || version.version !== file.version || version.sha256 !== file.sha256)
|
||||
return file;
|
||||
return { ...file, releaseVersion: version.release_version };
|
||||
});
|
||||
return files.some((file, index) => file !== summary.files[index])
|
||||
? { ...summary, files }
|
||||
: summary;
|
||||
}
|
||||
|
||||
export function recipeForDeployment(
|
||||
id: string
|
||||
): { recipe: LaunchRecipePlan; blueprintName: string | null } | null {
|
||||
|
||||
@@ -192,12 +192,17 @@ export function getVersion(id: number): ScriptVersionRow | undefined {
|
||||
ScriptVersionRow | undefined;
|
||||
}
|
||||
|
||||
export type ScriptVersionMetadata = Pick<ScriptVersionRow, 'id' | 'version' | 'sha256' | 'size'>;
|
||||
export type ScriptVersionMetadata = Pick<
|
||||
ScriptVersionRow,
|
||||
'id' | 'version' | 'release_version' | 'sha256' | 'size'
|
||||
>;
|
||||
|
||||
/** Planning a launch never needs to load potentially large script or plugin bytes. */
|
||||
export function getVersionMetadata(id: number): ScriptVersionMetadata | undefined {
|
||||
return db()
|
||||
.prepare('SELECT id, version, sha256, size FROM script_versions WHERE id = ?')
|
||||
.prepare(
|
||||
'SELECT id, version, release_version, sha256, size FROM script_versions WHERE id = ?'
|
||||
)
|
||||
.get(id) as ScriptVersionMetadata | undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ export function applyActivationFiles(
|
||||
): void {
|
||||
const changes = db()
|
||||
.prepare(
|
||||
`SELECT f.*, ${blobSize('f.content_hash')} AS size, v.version FROM staged_file_changes f
|
||||
`SELECT f.*, ${blobSize('f.content_hash')} AS size, v.version, v.release_version FROM staged_file_changes f
|
||||
JOIN provisioning_sources s ON s.kind=f.source_kind AND s.source_id=f.source_id AND s.server=f.server
|
||||
LEFT JOIN script_versions v ON v.id=f.script_version_id
|
||||
WHERE s.operation_id=? AND f.state='pending' ORDER BY f.id`
|
||||
@@ -21,6 +21,7 @@ export function applyActivationFiles(
|
||||
content_hash: string | null;
|
||||
size: number;
|
||||
version: number | null;
|
||||
release_version: string | null;
|
||||
})[];
|
||||
for (const change of changes) {
|
||||
assertPublicFileTarget(change.server, change.kind, change.rel_path);
|
||||
@@ -36,6 +37,7 @@ export function applyActivationFiles(
|
||||
path: change.rel_path,
|
||||
versionId: change.script_version_id,
|
||||
version: change.version,
|
||||
releaseVersion: change.release_version,
|
||||
sha256: change.content_hash,
|
||||
size: change.size,
|
||||
...(includeContent
|
||||
|
||||
@@ -38,11 +38,17 @@ export function captureMoveRecipe(server: string): LaunchRecipePlan {
|
||||
? undefined
|
||||
: (db()
|
||||
.prepare(
|
||||
`SELECT v.version,v.kind,s.name
|
||||
`SELECT v.version,v.release_version,v.kind,s.name
|
||||
FROM script_versions v JOIN scripts s ON s.id=v.script_id WHERE v.id=?`
|
||||
)
|
||||
.get(file.script_version_id) as
|
||||
{ version: number; kind: string; name: string } | undefined);
|
||||
| {
|
||||
version: number;
|
||||
release_version: string | null;
|
||||
kind: string;
|
||||
name: string;
|
||||
}
|
||||
| undefined);
|
||||
const kind = version?.kind === 'baseline' ? 'config' : (version?.kind ?? before?.kind);
|
||||
if (!['script', 'plugin', 'config'].includes(kind ?? ''))
|
||||
throw new Error(`The deployed file type is unavailable for ${file.rel_path}.`);
|
||||
@@ -59,6 +65,7 @@ export function captureMoveRecipe(server: string): LaunchRecipePlan {
|
||||
path: file.rel_path,
|
||||
versionId: file.script_version_id,
|
||||
version: version?.version ?? null,
|
||||
releaseVersion: version?.release_version ?? null,
|
||||
sha256: file.sha256,
|
||||
size: file.size
|
||||
};
|
||||
|
||||
@@ -1149,7 +1149,8 @@ function sameLaunchFiles(first: LaunchRecipePlan, second: LaunchRecipePlan): boo
|
||||
expectedMap: recipe.expectedMap,
|
||||
configFile: recipe.configFile,
|
||||
configSource: recipe.configSource,
|
||||
files: recipe.files
|
||||
// Older frozen recipes lack release labels; display metadata does not change a launch.
|
||||
files: recipe.files.map(({ releaseVersion: _releaseVersion, ...file }) => file)
|
||||
});
|
||||
return JSON.stringify(selected(first)) === JSON.stringify(selected(second));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user