Path: redb/redb.Core/Attributes/RedbRenameAttribute.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Attributes/RedbRenameAttribute.cs
----
using System;
namespace redb.Core.Attributes
{
///
/// Declares a previous name of a Props property, so that the scheme sync renames the stored property instead of
/// adding a new one and deleting the old one with its values.
///
/// On the sync, a property whose name is not in the database but whose previous name is gets the stored structure
/// renamed in place: the structure id stays, and with it every stored value. The next sync finds the property under
/// its name and does nothing. When both the name and a previous name are in the database, the sync stops with
/// and changes nothing: choosing one of them would lose the
/// values of the other.
///
///
/// The attribute is repeated for a chain of renames (A to B to C: two attributes on
/// C), so that a database that missed a version is renamed too. The previous names are kept in the
/// database (_structures._renamed_from): a node that still runs a class with the previous name stops at
/// its sync with instead of adding the property again and
/// deleting the renamed one.
///
///
/// The attribute stays on the property for good, in the order of the chain, the first name first: the first name
/// orders the property in the object hash, so the hashes stored before the rename stay valid after it. The sync
/// checks the first attribute against the history the database keeps and stops with
/// when they disagree or the attributes are gone. A database
/// created directly with the renamed class has no history yet, so there the check cannot fire.
///
///
/// A freed previous name may be taken by a new property of the same class once the rename is applied. While the
/// database still stores the previous name and not the current one, the sync stops with an error: the stored
/// structure could belong to either property.
///
///
/// Two properties whose last attributes (the attribute declared last) name each other's current name swap the
/// names in one step, which the sync refuses from the class alone: swap through a temporary name, one deployment
/// per rename.
///
///
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public sealed class RedbRenameAttribute : Attribute
{
/// The previous name of the property.
public string OldName { get; }
/// The previous name of the property.
public RedbRenameAttribute(string oldName)
{
if (string.IsNullOrWhiteSpace(oldName))
throw new ArgumentException("The previous name of a property cannot be empty", nameof(oldName));
OldName = oldName;
}
}
}