@@ -51,72 +51,85 @@ public function __construct(Registry $registry, string $role)
51
51
$ this ->defaults = $ registry ->getDefaults ();
52
52
}
53
53
54
- public function addDatetimeColumn (string $ columnName , string $ fieldName ): AbstractColumn
54
+ public function addDatetimeColumn (string $ columnName , string $ fieldName, int | null $ generated = null ): AbstractColumn
55
55
{
56
56
if ($ this ->fields ->has ($ fieldName )) {
57
57
if (!static ::isDatetimeType ($ this ->fields ->get ($ fieldName )->getType ())) {
58
58
throw new BehaviorCompilationException (sprintf ('Field %s must be of type datetime. ' , $ fieldName ));
59
59
}
60
60
$ this ->validateColumnName ($ fieldName , $ columnName );
61
+ $ this ->fields ->get ($ fieldName )->setGenerated ($ generated );
61
62
62
63
return $ this ->table ->column ($ columnName );
63
64
}
64
65
65
- $ this ->fields ->set (
66
- $ fieldName ,
67
- (new Field ())->setColumn ($ columnName )->setType ('datetime ' )->setTypecast ('datetime ' )
68
- );
66
+ $ field = (new Field ())
67
+ ->setColumn ($ columnName )
68
+ ->setType ('datetime ' )
69
+ ->setTypecast ('datetime ' )
70
+ ->setGenerated ($ generated );
71
+ $ this ->fields ->set ($ fieldName , $ field );
69
72
70
73
return $ this ->table ->column ($ columnName )->type (self ::DATETIME_COLUMN );
71
74
}
72
75
73
- public function addIntegerColumn (string $ columnName , string $ fieldName ): AbstractColumn
76
+ public function addIntegerColumn (string $ columnName , string $ fieldName, int | null $ generated = null ): AbstractColumn
74
77
{
75
78
if ($ this ->fields ->has ($ fieldName )) {
76
79
if (!static ::isIntegerType ($ this ->fields ->get ($ fieldName )->getType ())) {
77
80
throw new BehaviorCompilationException (sprintf ('Field %s must be of type integer. ' , $ fieldName ));
78
81
}
79
82
$ this ->validateColumnName ($ fieldName , $ columnName );
83
+ $ this ->fields ->get ($ fieldName )->setGenerated ($ generated );
80
84
81
85
return $ this ->table ->column ($ columnName );
82
86
}
83
87
84
- $ this ->fields ->set ($ fieldName , (new Field ())->setColumn ($ columnName )->setType ('integer ' )->setTypecast ('int ' ));
88
+ $ field = (new Field ())
89
+ ->setColumn ($ columnName )
90
+ ->setType ('integer ' )
91
+ ->setTypecast ('int ' )
92
+ ->setGenerated ($ generated );
93
+ $ this ->fields ->set ($ fieldName , $ field );
85
94
86
95
return $ this ->table ->column ($ columnName )->type (self ::INT_COLUMN );
87
96
}
88
97
89
- public function addStringColumn (string $ columnName , string $ fieldName ): AbstractColumn
98
+ public function addStringColumn (string $ columnName , string $ fieldName, int | null $ generated = null ): AbstractColumn
90
99
{
91
100
if ($ this ->fields ->has ($ fieldName )) {
92
101
if (!static ::isStringType ($ this ->fields ->get ($ fieldName )->getType ())) {
93
102
throw new BehaviorCompilationException (sprintf ('Field %s must be of type string. ' , $ fieldName ));
94
103
}
95
104
$ this ->validateColumnName ($ fieldName , $ columnName );
105
+ $ this ->fields ->get ($ fieldName )->setGenerated ($ generated );
96
106
97
107
return $ this ->table ->column ($ columnName );
98
108
}
99
109
100
- $ this ->fields ->set ($ fieldName , (new Field ())->setColumn ($ columnName )->setType ('string ' ));
110
+ $ field = (new Field ())->setColumn ($ columnName )->setType ('string ' )->setGenerated ($ generated );
111
+ $ this ->fields ->set ($ fieldName , $ field );
101
112
102
113
return $ this ->table ->column ($ columnName )->type (self ::STRING_COLUMN );
103
114
}
104
115
105
116
/**
106
117
* @throws BehaviorCompilationException
107
118
*/
108
- public function addUuidColumn (string $ columnName , string $ fieldName ): AbstractColumn
119
+ public function addUuidColumn (string $ columnName , string $ fieldName, int | null $ generated = null ): AbstractColumn
109
120
{
110
121
if ($ this ->fields ->has ($ fieldName )) {
111
122
if (!static ::isUuidType ($ this ->fields ->get ($ fieldName )->getType ())) {
112
123
throw new BehaviorCompilationException (sprintf ('Field %s must be of type uuid. ' , $ fieldName ));
113
124
}
114
125
$ this ->validateColumnName ($ fieldName , $ columnName );
126
+ $ this ->fields ->get ($ fieldName )->setGenerated ($ generated );
115
127
116
128
return $ this ->table ->column ($ columnName );
117
129
}
118
130
119
- $ this ->fields ->set ($ fieldName , (new Field ())->setColumn ($ columnName )->setType ('uuid ' ));
131
+ $ field = (new Field ())->setColumn ($ columnName )->setType ('uuid ' )->setGenerated ($ generated );
132
+ $ this ->fields ->set ($ fieldName , $ field );
120
133
121
134
return $ this ->table ->column ($ columnName )->type (self ::UUID_COLUMN );
122
135
}
0 commit comments