| | | 1 | | namespace ZhEaIsNsAaBn.DbSeeder; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// The errors and warnings of seed migrations. Type: <c>SeedError</c>. Warnings (<see cref="ChecksumMismatch"/>, |
| | | 5 | | /// <see cref="OutOfOrderMigration"/>) have <see cref="Severity.Low"/> and come back in <see cref="SeedRunResult.Warning |
| | | 6 | | /// Database failures are classified by the provider (<see cref="ISeedDatabaseProvider.Classify"/>). |
| | | 7 | | /// </summary> |
| | | 8 | | public static class SeedErrors |
| | | 9 | | { |
| | | 10 | | private const string SeedError = nameof( SeedError ); |
| | | 11 | | |
| | | 12 | | |
| | | 13 | | /// <summary>A migration's manifest lists a table file that isn't embedded.</summary> |
| | | 14 | | /// <param name="migrationId">The migration id.</param> |
| | | 15 | | /// <param name="file">The missing file name.</param> |
| | | 16 | | /// <returns>The <c>MigrationNotFound</c> error (severity High).</returns> |
| | | 17 | | public static Error MigrationNotFound( string migrationId, string file ) |
| | 7 | 18 | | => new( nameof( MigrationNotFound ), SeedError, "ملف بيانات ترحيل البيانات الأولية غير موجود.", "A seed migratio |
| | 7 | 19 | | additionalData: Data( ( "MigrationId", migrationId ), ( "File", file ) ) ); |
| | | 20 | | |
| | | 21 | | /// <summary>The target migration id isn't one of the context's seed migrations.</summary> |
| | | 22 | | /// <param name="targetMigrationId">The requested id.</param> |
| | | 23 | | /// <returns>The <c>TargetNotFound</c> error (severity Medium).</returns> |
| | | 24 | | public static Error TargetNotFound( string targetMigrationId ) |
| | 7 | 25 | | => new( nameof( TargetNotFound ), SeedError, "ترحيل البيانات الأولية المطلوب غير موجود.", "The target seed migra |
| | 7 | 26 | | additionalData: Data( ( "MigrationId", targetMigrationId ) ) ); |
| | | 27 | | |
| | | 28 | | /// <summary>The schema migration the seed migration needs isn't applied yet.</summary> |
| | | 29 | | /// <param name="migrationId">The seed migration id.</param> |
| | | 30 | | /// <param name="schemaMigrationId">The EF migration it needs.</param> |
| | | 31 | | /// <returns>The <c>SchemaNotReady</c> error (severity High).</returns> |
| | | 32 | | public static Error SchemaNotReady( string migrationId, string schemaMigrationId ) |
| | 6 | 33 | | => new( nameof( SchemaNotReady ), SeedError, "مخطط قاعدة البيانات غير محدث لهذه البيانات الأولية.", "The databas |
| | 6 | 34 | | Severity.High, additionalData: Data( ( "MigrationId", migrationId ), ( "RequiresSchemaMigration", schema |
| | | 35 | | |
| | | 36 | | /// <summary>Seed rows can't be deleted because other rows still reference them.</summary> |
| | | 37 | | /// <param name="table">The table of the seed rows.</param> |
| | | 38 | | /// <param name="blockers">The referencing tables, columns and row counts.</param> |
| | | 39 | | /// <returns>The <c>RowsReferenced</c> error (severity High).</returns> |
| | | 40 | | public static Error RowsReferenced( string table, IReadOnlyList<SeedBlocker> blockers ) |
| | 11 | 41 | | => new( nameof( RowsReferenced ), SeedError, "لا يمكن حذف البيانات الأولية لأنها مستخدمة في سجلات أخرى.", "The s |
| | 11 | 42 | | Severity.High, additionalData: Data( ( "Table", table ), ( "Blockers", blockers ) ) ); |
| | | 43 | | |
| | | 44 | | /// <summary>A soft delete was asked for an entity without a soft-delete flag.</summary> |
| | | 45 | | /// <param name="entity">The entity type name.</param> |
| | | 46 | | /// <returns>The <c>SoftDeleteNotSupported</c> error (severity Medium).</returns> |
| | | 47 | | public static Error SoftDeleteNotSupported( string entity ) |
| | 4 | 48 | | => new( nameof( SoftDeleteNotSupported ), SeedError, "هذا الكيان لا يدعم الحذف المنطقي.", "This entity doesn't s |
| | 4 | 49 | | additionalData: Data( ( "Entity", entity ) ) ); |
| | | 50 | | |
| | | 51 | | /// <summary>Warning: an applied migration's files changed since it was applied.</summary> |
| | | 52 | | /// <param name="migrationId">The migration id.</param> |
| | | 53 | | /// <returns>The <c>ChecksumMismatch</c> warning (severity Low).</returns> |
| | | 54 | | public static Error ChecksumMismatch( string migrationId ) |
| | 9 | 55 | | => new( nameof( ChecksumMismatch ), SeedError, "تم تعديل ملفات ترحيل بيانات أولية بعد تطبيقه.", "An applied seed |
| | 9 | 56 | | Severity.Low, additionalData: Data( ( "MigrationId", migrationId ) ) ); |
| | | 57 | | |
| | | 58 | | /// <summary>Warning: a pending migration is older than the newest applied one; it was applied anyway.</summary> |
| | | 59 | | /// <param name="migrationId">The migration id.</param> |
| | | 60 | | /// <returns>The <c>OutOfOrderMigration</c> warning (severity Low).</returns> |
| | | 61 | | public static Error OutOfOrderMigration( string migrationId ) |
| | 6 | 62 | | => new( nameof( OutOfOrderMigration ), SeedError, "تم تطبيق ترحيل بيانات أولية أقدم من آخر ترحيل مطبق.", "A seed |
| | 6 | 63 | | Severity.Low, additionalData: Data( ( "MigrationId", migrationId ) ) ); |
| | | 64 | | |
| | | 65 | | /// <summary>Another runner holds the seed lock and it wasn't released in time.</summary> |
| | | 66 | | /// <param name="timeout">How long the runner waited.</param> |
| | | 67 | | /// <returns>The <c>LockTimeout</c> error (severity Medium).</returns> |
| | | 68 | | public static Error LockTimeout( TimeSpan timeout ) |
| | 7 | 69 | | => new( nameof( LockTimeout ), SeedError, "انتهت مهلة انتظار قفل ترحيل البيانات الأولية.", "Timed out waiting fo |
| | 7 | 70 | | additionalData: Data( ( "Timeout", timeout ) ) ); |
| | | 71 | | |
| | | 72 | | /// <summary>A manifest or table file is malformed or doesn't fit the model.</summary> |
| | | 73 | | /// <param name="file">The file (resource) name.</param> |
| | | 74 | | /// <param name="reason">What is wrong, in English, for logs.</param> |
| | | 75 | | /// <param name="exception">The parse exception, if any.</param> |
| | | 76 | | /// <returns>The <c>InvalidDataFile</c> error (severity High).</returns> |
| | | 77 | | public static Error InvalidDataFile( string file, string reason, Exception? exception = null ) |
| | 78 | 78 | | => new( nameof( InvalidDataFile ), SeedError, "ملف البيانات الأولية غير صالح.", "A seed data file is invalid.", |
| | 78 | 79 | | Data( ( "File", file ), ( "Reason", reason ) ) ); |
| | | 80 | | |
| | | 81 | | /// <summary>A data file names a property the entity doesn't have.</summary> |
| | | 82 | | /// <param name="file">The file (resource) name.</param> |
| | | 83 | | /// <param name="entity">The entity type name.</param> |
| | | 84 | | /// <param name="property">The unknown property.</param> |
| | | 85 | | /// <returns>The <c>UnknownProperty</c> error (severity High).</returns> |
| | | 86 | | public static Error UnknownProperty( string file, string entity, string property ) |
| | 6 | 87 | | => new( nameof( UnknownProperty ), SeedError, "ملف البيانات الأولية يحتوي على خاصية غير معروفة.", "A seed data f |
| | 6 | 88 | | additionalData: Data( ( "File", file ), ( "Entity", entity ), ( "Property", property ) ) ); |
| | | 89 | | |
| | | 90 | | /// <summary>The tables of a migration reference each other in a cycle, so there is no safe order.</summary> |
| | | 91 | | /// <param name="migrationId">The migration id.</param> |
| | | 92 | | /// <param name="entities">The entities in the cycle.</param> |
| | | 93 | | /// <returns>The <c>CycleDetected</c> error (severity High).</returns> |
| | | 94 | | public static Error CycleDetected( string migrationId, IReadOnlyList<string> entities ) |
| | 6 | 95 | | => new( nameof( CycleDetected ), SeedError, "توجد علاقات دائرية بين جداول البيانات الأولية.", "The seed tables r |
| | 6 | 96 | | additionalData: Data( ( "MigrationId", migrationId ), ( "Entities", entities ) ) ); |
| | | 97 | | |
| | | 98 | | /// <summary>An entity has created-by / updated-by / deleted-by fields, but no system user is configured.</summary> |
| | | 99 | | /// <param name="entity">The entity type name.</param> |
| | | 100 | | /// <returns>The <c>SystemUserRequired</c> error (severity High).</returns> |
| | | 101 | | public static Error SystemUserRequired( string entity ) |
| | 6 | 102 | | => new( nameof( SystemUserRequired ), SeedError, "يجب تحديد مستخدم النظام للبيانات الأولية.", "A system user mus |
| | 6 | 103 | | additionalData: Data( ( "Entity", entity ) ) ); |
| | | 104 | | |
| | | 105 | | |
| | 153 | 106 | | private static Dictionary<string, object> Data( params (string Key, object Value)[] values ) => values.ToDictionary( |
| | | 107 | | } |