|
| 1 | +package definitions |
| 2 | + |
| 3 | +// Op identifier of operations that can be invoked |
| 4 | +type Op int |
| 5 | + |
| 6 | +const ( |
| 7 | + |
| 8 | + // CreateModelOp creates a new model and the corresponding database table |
| 9 | + CreateModelOp Op = iota |
| 10 | + |
| 11 | + // DeleteModelOp deletes a model and drops its database table |
| 12 | + DeleteModelOp |
| 13 | + |
| 14 | + // RenameModelOp renames a model and renames its database table |
| 15 | + RenameModelOp |
| 16 | + |
| 17 | + // AlterModelTableOp renames the database table for a model |
| 18 | + AlterModelTableOp |
| 19 | + |
| 20 | + // AlterUniqueTogetherOp changes the unique constraints of a model |
| 21 | + AlterUniqueTogetherOp |
| 22 | + |
| 23 | + // AlterIndexTogetherOp changes the indexes of a model |
| 24 | + AlterIndexTogetherOp |
| 25 | + |
| 26 | + // AlterOrderWithRespectToOp creates or deletes the _order column for a model |
| 27 | + AlterOrderWithRespectToOp |
| 28 | + |
| 29 | + // AlterModelOptionsOp changes various model options without affecting the database |
| 30 | + AlterModelOptionsOp |
| 31 | + |
| 32 | + // AddFieldOp adds a field to a model and the corresponding column in the database |
| 33 | + AddFieldOp |
| 34 | + |
| 35 | + // RemoveFieldOp removes a field from a model and drops the corresponding column from the database |
| 36 | + RemoveFieldOp |
| 37 | + |
| 38 | + // AlterFieldOp changes a field’s definition and alters its database column if necessary |
| 39 | + AlterFieldOp |
| 40 | + |
| 41 | + // RenameFieldOp renames a field and, if necessary, also its database column |
| 42 | + RenameFieldOp |
| 43 | + |
| 44 | + // AddIndexOp creates an index in the database table for the model |
| 45 | + AddIndexOp |
| 46 | + |
| 47 | + // RemoveIndexOp removes an index in the database table for the model |
| 48 | + RemoveIndexOp |
| 49 | +) |
| 50 | + |
| 51 | +// FieldConstraint ... |
| 52 | +type FieldConstraint int |
| 53 | + |
| 54 | +const ( |
| 55 | + |
| 56 | + // OnDeleteCascadeConstraint ... |
| 57 | + OnDeleteCascadeConstraint FieldConstraint = 1 |
| 58 | + |
| 59 | + // OnUpdateCascaseConstraint ... |
| 60 | + OnUpdateCascaseConstraint |
| 61 | +) |
| 62 | + |
| 63 | +// OpColumn ... |
| 64 | +type OpColumn struct { |
| 65 | + |
| 66 | + // this is the column name. If name is provided by the tags, gormgx will use that. |
| 67 | + // Otherwise, lowercase, underscore separated name from struct will be used |
| 68 | + CanonicalName string |
| 69 | + |
| 70 | + FieldType BasicType |
| 71 | + |
| 72 | + // the type of the field that corresponds to what the database expects |
| 73 | + DatabaseType string |
| 74 | + |
| 75 | + // whether this column can take nulls |
| 76 | + IsNull bool |
| 77 | + |
| 78 | + // the maximum number of characters. this is for `VARCHAR`, INT and Floats types |
| 79 | + Size int |
| 80 | + |
| 81 | + // the default of the the column, It's an interface since we don't know the `DatabaseType` for hand |
| 82 | + Default interface{} |
| 83 | + |
| 84 | + // the timezone to use for date fields. All date/time fields in gormgx are timezone by default |
| 85 | + TimeZone string |
| 86 | + |
| 87 | + IsNullable bool |
| 88 | + |
| 89 | + IsPrimaryKey bool |
| 90 | + |
| 91 | + IsAutoIncrement bool |
| 92 | + |
| 93 | + // whether this column should considered as an index |
| 94 | + IsIndex bool |
| 95 | + |
| 96 | + IsUnique bool |
| 97 | + |
| 98 | + IsForeignKey bool |
| 99 | + |
| 100 | + // the table that this column is foreignKey to. the value will be like `Model.Field` |
| 101 | + ForeignKeyTo string |
| 102 | + |
| 103 | + ForeignKeyConstraints FieldConstraint |
| 104 | + |
| 105 | + // applied for floats data types |
| 106 | + Precision int |
| 107 | + |
| 108 | + Scale int |
| 109 | +} |
| 110 | + |
| 111 | +// Operation describes a single operation with all it's relevant metadata |
| 112 | +type Operation struct { |
| 113 | + Op Op |
| 114 | + TableName string |
| 115 | + Columns []*OpColumn |
| 116 | +} |
| 117 | + |
| 118 | +// MigrationDump ... |
| 119 | +type MigrationDump struct { |
| 120 | + IsInitial bool `yaml:"is_initial"` |
| 121 | + Dependencies []string `yaml:"dependencies"` |
| 122 | + Operations []Operation `yaml:"operations"` |
| 123 | +} |
0 commit comments