Path: redb/redb.Export/Models/ExportRecord.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.Export/Models/ExportRecord.cs ---- using System.Text.Json.Serialization; namespace redb.Export.Models; /// /// Abstract base class for all data records in a .redb JSONL stream. /// Each concrete subclass maps to one REDB database table. /// JSON polymorphism is handled via the "type" discriminator property. /// [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] [JsonDerivedType(typeof(TypeRecord), "type")] [JsonDerivedType(typeof(RoleRecord), "role")] [JsonDerivedType(typeof(UserRecord), "user")] [JsonDerivedType(typeof(UserRoleRecord), "user_role")] [JsonDerivedType(typeof(ListRecord), "list")] [JsonDerivedType(typeof(ListItemRecord), "list_item")] [JsonDerivedType(typeof(SchemeRecord), "scheme")] [JsonDerivedType(typeof(StructureRecord), "structure")] [JsonDerivedType(typeof(MigrationRecord), "migration")] [JsonDerivedType(typeof(ObjectRecord), "object")] [JsonDerivedType(typeof(PermissionRecord), "permission")] [JsonDerivedType(typeof(ValueRecord), "value")] public abstract class ExportRecord { } /// /// Represents a row from the _types table (REDB type definition). /// public sealed class TypeRecord : ExportRecord { /// Primary key. public long Id { get; init; } /// Type name. public string Name { get; init; } = ""; /// Database-specific type name (e.g. "bigint"). public string? DbType { get; init; } /// .NET CLR type name (e.g. "System.Int64"). public string? DotnetType { get; init; } } /// /// Represents a row from the _roles table. /// public sealed class RoleRecord : ExportRecord { /// Primary key. public long Id { get; init; } /// Role name. public string Name { get; init; } = ""; /// Optional configuration object reference. public long? IdConfiguration { get; init; } } /// /// Represents a row from the _users table. /// public sealed class UserRecord : ExportRecord { /// Primary key. public long Id { get; init; } /// Login (username). public string Login { get; init; } = ""; /// Password hash. public string Password { get; init; } = ""; /// Display name. public string Name { get; init; } = ""; /// Phone number. public string? Phone { get; init; } /// E-mail address. public string? Email { get; init; } /// Registration timestamp. public DateTimeOffset DateRegister { get; init; } /// Dismissal timestamp (null if user is active). public DateTimeOffset? DateDismiss { get; init; } /// Whether the user account is enabled. public bool Enabled { get; init; } /// Optional numeric key. public long? Key { get; init; } /// Optional integer code. public long? CodeInt { get; init; } /// Optional string code. public string? CodeString { get; init; } /// Optional GUID code. public Guid? CodeGuid { get; init; } /// Free-text note. public string? Note { get; init; } /// Row hash for change tracking. public Guid? Hash { get; init; } /// Optional configuration object reference. public long? IdConfiguration { get; init; } } /// /// Represents a row from the _users_roles junction table. /// public sealed class UserRoleRecord : ExportRecord { /// Primary key. public long Id { get; init; } /// Foreign key to _roles. public long IdRole { get; init; } /// Foreign key to _users. public long IdUser { get; init; } } /// /// Represents a row from the _lists table (enumeration/lookup list). /// public sealed class ListRecord : ExportRecord { /// Primary key. public long Id { get; init; } /// List display name. public string Name { get; init; } = ""; /// Machine-friendly alias. public string? Alias { get; init; } } /// /// Represents a row from the _list_items table. /// public sealed class ListItemRecord : ExportRecord { /// Primary key. public long Id { get; init; } /// Foreign key to the parent _lists row. public long IdList { get; init; } /// Display value of the list item. public string? Value { get; init; } /// Machine-friendly alias. public string? Alias { get; init; } /// Optional object reference. public long? IdObject { get; init; } } /// /// Represents a row from the _schemes table (schema/class definition). /// public sealed class SchemeRecord : ExportRecord { /// Primary key. public long Id { get; init; } /// Parent scheme identifier (for inheritance). public long? IdParent { get; init; } /// Scheme name. public string Name { get; init; } = ""; /// Machine-friendly alias. public string? Alias { get; init; } /// Namespace for code generation. public string? NameSpace { get; init; } /// Hash of the scheme structure for change detection. public Guid? StructureHash { get; init; } /// Scheme type discriminator (0 = normal, 1 = primitive, etc.). public long SchemeType { get; init; } /// Free-form marker of the scheme ([RedbTags] or written by an extension); null when unset. public string? Tags { get; init; } /// /// Previous names of the scheme, oldest first, as the JSON array text of _schemes._renamed_from; null when /// the scheme was never renamed, and in files written before the column existed. /// public string? RenamedFrom { get; init; } } /// /// Represents a row from the _structures table (field/property definition). /// public sealed class StructureRecord : ExportRecord { /// Primary key. public long Id { get; init; } /// Parent structure identifier (for nested fields). public long? IdParent { get; init; } /// Foreign key to the owning scheme. public long IdScheme { get; init; } /// Override reference for inherited fields. public long? IdOverride { get; init; } /// Foreign key to _types. public long IdType { get; init; } /// Foreign key to _lists (for enumeration-typed fields). public long? IdList { get; init; } /// Field name. public string Name { get; init; } = ""; /// Machine-friendly alias. public string? Alias { get; init; } /// Display order within the scheme. public long? Order { get; init; } /// Whether the field is read-only. public bool? Readonly { get; init; } /// Whether the field requires a non-null value. public bool? AllowNotNull { get; init; } /// Collection type (0 = none, 1 = list, 2 = dictionary, etc.). public long? CollectionType { get; init; } /// Key type for dictionary-typed fields. public long? KeyType { get; init; } /// Whether the value is stored compressed. public bool? IsCompress { get; init; } /// Whether explicit NULLs are persisted. public bool? StoreNull { get; init; } /// Whether the field is a unique key within its scheme ([RedbUnique]). public bool? Unique { get; init; } /// Encoder version the stored keys were computed with. public long? UniqueVersion { get; init; } /// Whether the reference is lazy (`virtual` in the CLR model, V4). public bool? Lazy { get; init; } /// Element-key scope of a collection key (null = default, 1 = scheme elements, 2 = collection elements). public long? UniqueScope { get; init; } /// Free-form marker of the field ([RedbTags] or written by an extension); null when unset. public string? Tags { get; init; } /// /// Previous names of the field, oldest first, as the JSON array text of _structures._renamed_from; null /// when the field was never renamed, and in files written before the column existed. /// public string? RenamedFrom { get; init; } /// Serialized default value. public byte[]? DefaultValue { get; init; } /// Editor hint for UI generation. public string? DefaultEditor { get; init; } } /// /// Represents a row from the _migrations table: one data migration applied to a scheme (redb Pro). The rows /// tell a later migration run what the data already has, so an imported database does not get a migration twice. /// Written after the structures; a database that never ran a migration writes none. /// public sealed class MigrationRecord : ExportRecord { /// Primary key. public long Id { get; init; } /// Identifier of the migration within its scheme (e.g. "OrderProps_TotalPrice_v1"). public string MigrationId { get; init; } = ""; /// Scheme the migration was applied to. public long SchemeId { get; init; } /// Structure the migration changed; null for the whole scheme. public long? StructureId { get; init; } /// Name of the property the migration changed. public string? PropertyName { get; init; } /// Hash of the migration's expression, used to detect a changed migration. public string? ExpressionHash { get; init; } /// Kind of migration (e.g. "ComputedFrom", "Transform"). public string MigrationType { get; init; } = ""; /// When the migration was applied. public DateTimeOffset AppliedAt { get; init; } /// Who applied the migration. public string? AppliedBy { get; init; } /// The statement the migration ran, kept for audit. public string? SqlExecuted { get; init; } /// Rows the migration changed. public long? AffectedRows { get; init; } /// How long the migration ran, in milliseconds. public long? DurationMs { get; init; } /// Whether the row records a dry run, which changed nothing. public bool DryRun { get; init; } } /// /// Represents a row from the _objects table (entity instance). /// public sealed class ObjectRecord : ExportRecord { /// Primary key. public long Id { get; init; } /// Parent object identifier (for tree structures). public long? IdParent { get; init; } /// Foreign key to the defining scheme. public long IdScheme { get; init; } /// Owner user identifier. public long IdOwner { get; init; } /// User who last modified the object. public long IdWhoChange { get; init; } /// Creation timestamp. public DateTimeOffset DateCreate { get; init; } /// Last modification timestamp. public DateTimeOffset DateModify { get; init; } /// Optional workflow start date. public DateTimeOffset? DateBegin { get; init; } /// Optional workflow completion date. public DateTimeOffset? DateComplete { get; init; } /// Optional numeric key. public long? Key { get; init; } /// Display name. public string? Name { get; init; } /// Free-text note. public string? Note { get; init; } /// Row hash for change tracking. public Guid? Hash { get; init; } // --- Primitive value columns for RedbPrimitive --- /// Inline value (for primitive schemes). public long? ValueLong { get; init; } /// Inline value (for primitive schemes). public string? ValueString { get; init; } /// Inline value (for primitive schemes). public Guid? ValueGuid { get; init; } /// Inline value (for primitive schemes). public bool? ValueBool { get; init; } /// Inline value (for primitive schemes). public double? ValueDouble { get; init; } /// Inline value (for primitive schemes). public decimal? ValueNumeric { get; init; } /// Inline value (for primitive schemes). public DateTimeOffset? ValueDatetime { get; init; } /// Inline binary value (for primitive schemes). public byte[]? ValueBytes { get; init; } /// Unique key within the scheme (V4, UNIQUE stage 1). public string? ValueUnique { get; init; } } /// /// Represents a row from the _permissions table. /// public sealed class PermissionRecord : ExportRecord { /// Primary key. public long Id { get; init; } /// Role to which the permission applies (mutually exclusive with ). public long? IdRole { get; init; } /// User to which the permission applies (mutually exclusive with ). public long? IdUser { get; init; } /// Reference identifier (scheme or object) the permission targets. public long IdRef { get; init; } /// SELECT permission flag. public bool? Select { get; init; } /// INSERT permission flag. public bool? Insert { get; init; } /// UPDATE permission flag. public bool? Update { get; init; } /// DELETE permission flag. public bool? Delete { get; init; } } /// /// Represents a row from the _values table (EAV property value). /// Exactly one of the typed value columns is populated per row. /// public sealed class ValueRecord : ExportRecord { /// Primary key. public long Id { get; init; } /// Foreign key to _structures. public long IdStructure { get; init; } /// Foreign key to _objects. public long IdObject { get; init; } /// String value. public string? String { get; init; } /// Integer value. public long? Long { get; init; } /// GUID value. public Guid? Guid { get; init; } /// Double-precision floating-point value. public double? Double { get; init; } /// Date/time value with timezone offset. public DateTimeOffset? DateTimeOffset { get; init; } /// Boolean value. public bool? Boolean { get; init; } /// Binary (byte array) value. public byte[]? ByteArray { get; init; } /// Decimal (numeric) value. public decimal? Numeric { get; init; } /// Foreign key to _list_items. public long? ListItem { get; init; } /// Foreign key to another _objects row (object reference). public long? Object { get; init; } /// Parent row identifier for array/collection elements. public long? ArrayParentId { get; init; } /// Index or key within an array/dictionary. public string? ArrayIndex { get; init; } /// /// Unique-key hash of a [RedbUnique] field (V4). Absent in pre-V4 exports: the /// import then leaves _values._unique NULL, and the next scheme synchronisation /// recomputes the keys from the stored values (rows with a value but no key are a /// standing recompute trigger). /// public Guid? Unique { get; init; } }