From a0f22c88d54d351b060c2d0d9f0a8cbf5f412ba2 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Nov 2026 15:02:23 +0000 Subject: enstate: --migrate, renames both ways, kept entries What a generation sees of a snapshot accepted under another schema: same name and type, renamedFrom, a rename in the stored schema read backwards, and entries kept, with their types, in the snapshot's kept/. Plans start from what is seen, and store it under the running schema; a generation change rewrites no snapshot. --migrate (and --dry-run) says what each channel sees, refuses for required slots nothing fills, puts the views in place and runs their reactions; --materialize and --status go by what is seen, too. A view made from an unfilled required slot isn't there. The rollback cases of migrations.md that need no converters or steps are tests. --- src/plan.rs | 104 ++++++++++++++++++++---------------------------------------- 1 file changed, 34 insertions(+), 70 deletions(-) (limited to 'src/plan.rs') diff --git a/src/plan.rs b/src/plan.rs index 952f3aa..80e2bad 100644 --- a/src/plan.rs +++ b/src/plan.rs @@ -16,11 +16,12 @@ use serde::Serialize; use crate::content::{self, Content}; use crate::media; +use crate::migrate; use crate::name::Address; use crate::program::{self, Given, ProgramFailed, Role}; use crate::schema::{Reactions, Schema}; use crate::scratch::Scratch; -use crate::store::Store; +use crate::store::{Kept, Store}; use crate::submission::{Change, Item, Submission}; use crate::view::{self, FileChange}; @@ -72,6 +73,7 @@ pub struct ViewOutcome { pub struct Planned { pub plan: Plan, content: Content, + kept: Kept, content_changes: bool, rendered: Vec<(String, Option, bool)>, } @@ -81,6 +83,7 @@ fn refused(plan: Plan) -> Result { Ok(Planned { plan, content: Content::new(), + kept: Kept::new(), content_changes: false, rendered: Vec::new(), }) @@ -134,8 +137,11 @@ pub fn plan(schema: &Schema, store: &Store, submission: &Submission) -> Result

&snapshot.content, + (Some(_), false) => &seen.content, _ => &empty, }; // Other channels, for validators and views given their slots. @@ -156,10 +162,7 @@ pub fn plan(schema: &Schema, store: &Store, submission: &Submission) -> Result

Result

Result

Result

Vec { } failed } - -/// Renders every view of `schema` from the current snapshots, puts those that differ -/// from what is in place there, and takes away views the schema doesn't have: at boot, -/// and after a generation change. Runs no reactions. Returns how each view changed. -pub fn materialize(schema: &Schema, store: &Store) -> Result> { - let mut contents: BTreeMap = BTreeMap::new(); - for channel in schema.channels.keys() { - if let Some(snapshot) = store.current(channel)? { - contents.insert(channel.clone(), snapshot.content); - } - } - let entries: view::Entries = contents - .iter() - .map(|(name, content)| (name.as_str(), content)) - .collect(); - let mut outcomes = Vec::new(); - for (name, view_spec) in schema.views_of(None) { - let secret = schema.view_is_secret(view_spec); - let rendered = view::render(schema, name, view_spec, &entries, &store.scratch()) - .with_context(|| format!("view {name}"))?; - let installed = store.installed_view(name); - let (change, files) = view::compare( - installed.as_deref(), - rendered.as_ref().map(Scratch::path), - secret, - )?; - if change != view::Change::Unchanged { - store.install_view(name, rendered, secret)?; - } - outcomes.push(ViewOutcome { - name: name.clone(), - secret, - change, - files, - }); - } - let views = store.run.join("views"); - if let Ok(entries) = std::fs::read_dir(&views) { - for entry in entries { - let name = entry?.file_name().to_string_lossy().into_owned(); - if name == ".generations" - || name.ends_with(".new-link") - || schema.views.contains_key(&name) - { - continue; - } - if store.installed_view(&name).is_some() { - store.install_view(&name, None, false)?; - outcomes.push(ViewOutcome { - name, - secret: false, - change: view::Change::Removed, - files: Vec::new(), - }); - } - } - } - Ok(outcomes) -} -- cgit v1.3.1