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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
use serde::{Deserialize, Serialize};
use crate::imr::Field;
/**
The presentation of a migration file
*/
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct MigrationFile {
/// The migration of the migration file
pub migration: Migration,
}
/**
Representation for a migration.
*/
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct Migration {
/// Hash of the migration
pub hash: String,
/// Marks the migration initial state
pub initial: bool,
/// ID of the migration, derived from filename
#[serde(skip)]
pub id: u16,
/// Name of the migration, derived from filename
#[serde(skip)]
pub name: String,
/// Migration this migration depends on
pub dependency: Option<u16>,
/// List of migrations this migration replaces
pub replaces: Vec<u16>,
/// The operations to execute
pub operations: Vec<Operation>,
}
/**
The representation for all possible database operations
*/
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "Type")]
pub enum Operation {
/// Representation of a CreateModel operation
#[serde(rename_all = "PascalCase")]
CreateModel {
/// Name of the model
name: String,
/// List of fields associated to the model
fields: Vec<Field>,
},
/// Representation of a RenameModel operation
#[serde(rename_all = "PascalCase")]
RenameModel {
/// Old name of the model
old: String,
/// New name of the model
new: String,
},
/// Representation of a DeleteModel operation
#[serde(rename_all = "PascalCase")]
DeleteModel {
/// Name of the model
name: String,
},
/// Representation of a CreateField operation
#[serde(rename_all = "PascalCase")]
CreateField {
/// Name of the model
model: String,
/// The field that should be created
field: Field,
},
/// Representation of a RenameField operation
#[serde(rename_all = "PascalCase")]
RenameField {
/// Name of the table the column lives in
table_name: String,
/// Old name of the column
old: String,
/// New name of the column
new: String,
},
/// Representation of a DeleteField operation
#[serde(rename_all = "PascalCase")]
DeleteField {
/// Name of the model
model: String,
/// Name of the field to delete
name: String,
},
/// Representation of a RawSQL operation
#[serde(rename_all = "PascalCase")]
RawSQL {
/// SQL for sqlite
#[serde(rename = "SQLite")]
sqlite: String,
/// SQL for postgres
#[serde(rename = "Postgres")]
postgres: String,
/// SQL for mysql
#[serde(rename = "MySQL")]
mysql: String,
},
}