FieldValueMigration.h header

#include <ew/app/FieldValueMigration.h>

Namespace ew::app

FieldValueMigrationProblem struct

struct ew::app::FieldValueMigrationProblem

One value the migration could not turn into the type its field declares.

Reported, never dropped. A migration that quietly discarded "about forty" from a Number field would destroy the only record that anybody had written it, and would do so in the one operation a writer has no reason to watch. The value stays exactly as it was, as Text, and appears here.

Members

ew::core::foundation::ContentId ew::app::entity::FieldValueMigrationProblem::entityId

The entity holding it.

QString ew::app::entity::FieldValueMigrationProblem::entityName

What the entity is called, so the report reads as a place rather than an id.

QString ew::app::entity::FieldValueMigrationProblem::key

The field key.

QString ew::app::entity::FieldValueMigrationProblem::text

The text that would not convert, verbatim.

QString ew::app::entity::FieldValueMigrationProblem::message

One sentence naming what is wrong with it.

bool operator==(const FieldValueMigrationProblem &, const FieldValueMigrationProblem &)=default

Problems compare equal when every field matches.

FieldValueMigrationReport struct

struct ew::app::FieldValueMigrationReport

What a migration did, and what it could not do.

Members

int ew::app::entity::FieldValueMigrationReport::converted = 0

How many values were converted from text to their declared type.

int ew::app::entity::FieldValueMigrationReport::alreadyTyped = 0

How many were already of the right type, or were text fields needing no conversion.

std::vector<FieldValueMigrationProblem> ew::app::entity::FieldValueMigrationReport::problems

Every value that would not convert. See FieldValueMigrationProblem.

bool ew::app::entity::FieldValueMigrationReport::isEmpty() const

Whether anything at all needs doing.

Functions

QString ew::app::entity::describeFieldValueMigration(const FieldValueMigrationReport &report)

report written for a person to read, as Markdown.

The problems come first and are named individually. A count alone would tell a writer that something was left behind without telling them where to look, which is the same as not telling them.

std::unique_ptr< ew::core::undo::Command > ew::app::entity::makeFieldValueMigrationCommand(ew::core::project::Project &project)

The command that performs the migration described by planFieldValueMigration.

Undoable like any other edit – which matters more here than almost anywhere, because it touches every entity in the project at once and a writer who dislikes the result must be able to say so. Values that will not convert are left exactly as they are.

Returns null when there is nothing to convert, so a caller can tell "already done" from "done".

FieldValueMigrationReport ew::app::entity::planFieldValueMigration(const ew::core::project::Project &project)

What migrating project would do, without doing it.

Every value stored as Text whose field declares another type is a candidate: projects written before values were typed hold all of them that way. A value already of its declared type is left alone and counted, so running this twice is safe and the second run reports nothing to do.