1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::collections::BTreeMap;

use mongodb::error::Error as MongoDbError;
use thiserror::Error;

use crate::migration_record::MigrationRecord;

#[derive(Error, Debug)]
pub enum MigrationExecution {
    #[error("Failed to create an initial record document for the migration which will be executed - {migration_id}
	    record attempted to serialize: {migration_record:?}
	    the migration: {migration_id}, and following it: {next_not_executed_migrations_ids:?} weren't executed")]
    InitialMigrationRecord {
        migration_id: String,
        migration_record: MigrationRecord,
        next_not_executed_migrations_ids: Vec<String>,
        additional_info: bson::ser::Error,
    },
    #[error("Failed to write an initial record document for the migration which will be executed - {migration_id}
	    the migration: {migration_id}, and following it: {next_not_executed_migrations_ids:?} weren't executed
	    additional_info: {additional_info}")]
    InProgressStatusNotSaved {
        migration_id: String,
        next_not_executed_migrations_ids: Vec<String>,
        additional_info: MongoDbError,
    },
    #[error("Migration - {migration_id} has finished with the status: {migration_status}
	    but the migration_record attempted to be writted as a migration result into migrations collections
	    wasn't successfully serialized: {migration_record:?}, this is why it hasn't written
	    due to inconsistency, following it migrations: {next_not_executed_migrations_ids:?} weren't executed")]
    FinishedButNotSavedDueToSerialization {
        migration_id: String,
        migration_status: String,
        migration_record: MigrationRecord,
        next_not_executed_migrations_ids: Vec<String>,
        additional_info: bson::ser::Error,
    },
    #[error("Failed to write the migration record document for the migration - {migration_id} with its result
	    that migration was completed with the status: {migration_status}
	    due to inconsistency, following it migrations: {next_not_executed_migrations_ids:?} weren't executed
	    additional_info: {additional_info}")]
    FinishedButNotSavedDueMongoError {
        migration_id: String,
        migration_status: String,
        additional_info: MongoDbError,
        next_not_executed_migrations_ids: Vec<String>,
    },
    #[error(
        "Migration wasn't completed successfully - {migration_id}
	 due to that, following it migrations: {next_not_executed_migrations_ids:?} weren't executed"
    )]
    FinishedAndSavedAsFail {
        migration_id: String,
        next_not_executed_migrations_ids: Vec<String>,
    },
    #[error(
        "Migrations weren't executed since there are several migrations with duplicated ids(id, indices vec):
	 {duplicates:?}"
    )]
    PassedMigrationsWithDuplicatedIds {
        duplicates: BTreeMap<String, Vec<usize>>,
    },
    #[error("Single migration for execution wasn't found in migrations vec: {migration_id:?}")]
    MigrationFromVecNotFound { migration_id: String },
}