@@ -15,30 +15,46 @@ impl MigrationTrait for Migration {
15
15
profit_margin : Set ( 10.4 ) ,
16
16
..Default :: default ( )
17
17
} ;
18
- let sea = Bakery :: insert ( bakery) . exec ( db) . await ?. last_insert_id ;
18
+ let sea = Bakery :: insert ( bakery)
19
+ . exec ( db)
20
+ . await ?
21
+ . last_insert_id
22
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
19
23
20
24
let bakery = bakery:: ActiveModel {
21
25
name : Set ( "LakeSide Bakery" . to_owned ( ) ) ,
22
26
profit_margin : Set ( 5.8 ) ,
23
27
..Default :: default ( )
24
28
} ;
25
- let lake = Bakery :: insert ( bakery) . exec ( db) . await ?. last_insert_id ;
29
+ let lake = Bakery :: insert ( bakery)
30
+ . exec ( db)
31
+ . await ?
32
+ . last_insert_id
33
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
26
34
27
35
let alice = baker:: ActiveModel {
28
36
name : Set ( "Alice" . to_owned ( ) ) ,
29
37
contact : Set ( "+44 15273388" . to_owned ( ) ) ,
30
38
bakery_id : Set ( Some ( sea) ) ,
31
39
..Default :: default ( )
32
40
} ;
33
- let alice = Baker :: insert ( alice) . exec ( db) . await ?. last_insert_id ;
41
+ let alice = Baker :: insert ( alice)
42
+ . exec ( db)
43
+ . await ?
44
+ . last_insert_id
45
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
34
46
35
47
let bob = baker:: ActiveModel {
36
48
name : Set ( "Bob" . to_owned ( ) ) ,
37
49
contact : Set ( "+852 12345678" . to_owned ( ) ) ,
38
50
bakery_id : Set ( Some ( lake) ) ,
39
51
..Default :: default ( )
40
52
} ;
41
- let bob = Baker :: insert ( bob) . exec ( db) . await ?. last_insert_id ;
53
+ let bob = Baker :: insert ( bob)
54
+ . exec ( db)
55
+ . await ?
56
+ . last_insert_id
57
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
42
58
43
59
let cake = cake:: ActiveModel {
44
60
name : Set ( "Chocolate Cake" . to_owned ( ) ) ,
@@ -47,7 +63,11 @@ impl MigrationTrait for Migration {
47
63
bakery_id : Set ( Some ( sea) ) ,
48
64
..Default :: default ( )
49
65
} ;
50
- let choco = Cake :: insert ( cake) . exec ( db) . await ?. last_insert_id ;
66
+ let choco = Cake :: insert ( cake)
67
+ . exec ( db)
68
+ . await ?
69
+ . last_insert_id
70
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
51
71
52
72
let mut cake = cake:: ActiveModel {
53
73
name : Set ( "Double Chocolate" . to_owned ( ) ) ,
@@ -56,9 +76,17 @@ impl MigrationTrait for Migration {
56
76
bakery_id : Set ( Some ( sea) ) ,
57
77
..Default :: default ( )
58
78
} ;
59
- let double_1 = Cake :: insert ( cake. clone ( ) ) . exec ( db) . await ?. last_insert_id ;
79
+ let double_1 = Cake :: insert ( cake. clone ( ) )
80
+ . exec ( db)
81
+ . await ?
82
+ . last_insert_id
83
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
60
84
cake. bakery_id = Set ( Some ( lake) ) ;
61
- let double_2 = Cake :: insert ( cake) . exec ( db) . await ?. last_insert_id ;
85
+ let double_2 = Cake :: insert ( cake)
86
+ . exec ( db)
87
+ . await ?
88
+ . last_insert_id
89
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
62
90
63
91
let mut cake = cake:: ActiveModel {
64
92
name : Set ( "Lemon Cake" . to_owned ( ) ) ,
@@ -67,9 +95,17 @@ impl MigrationTrait for Migration {
67
95
bakery_id : Set ( Some ( sea) ) ,
68
96
..Default :: default ( )
69
97
} ;
70
- let lemon_1 = Cake :: insert ( cake. clone ( ) ) . exec ( db) . await ?. last_insert_id ;
98
+ let lemon_1 = Cake :: insert ( cake. clone ( ) )
99
+ . exec ( db)
100
+ . await ?
101
+ . last_insert_id
102
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
71
103
cake. bakery_id = Set ( Some ( lake) ) ;
72
- let lemon_2 = Cake :: insert ( cake) . exec ( db) . await ?. last_insert_id ;
104
+ let lemon_2 = Cake :: insert ( cake)
105
+ . exec ( db)
106
+ . await ?
107
+ . last_insert_id
108
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
73
109
74
110
let mut cake = cake:: ActiveModel {
75
111
name : Set ( "Strawberry Cake" . to_owned ( ) ) ,
@@ -78,9 +114,17 @@ impl MigrationTrait for Migration {
78
114
bakery_id : Set ( Some ( sea) ) ,
79
115
..Default :: default ( )
80
116
} ;
81
- let straw_1 = Cake :: insert ( cake. clone ( ) ) . exec ( db) . await ?. last_insert_id ;
117
+ let straw_1 = Cake :: insert ( cake. clone ( ) )
118
+ . exec ( db)
119
+ . await ?
120
+ . last_insert_id
121
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
82
122
cake. bakery_id = Set ( Some ( lake) ) ;
83
- let straw_2 = Cake :: insert ( cake) . exec ( db) . await ?. last_insert_id ;
123
+ let straw_2 = Cake :: insert ( cake)
124
+ . exec ( db)
125
+ . await ?
126
+ . last_insert_id
127
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
84
128
85
129
let cake = cake:: ActiveModel {
86
130
name : Set ( "Orange Cake" . to_owned ( ) ) ,
@@ -89,7 +133,11 @@ impl MigrationTrait for Migration {
89
133
bakery_id : Set ( Some ( lake) ) ,
90
134
..Default :: default ( )
91
135
} ;
92
- let orange = Cake :: insert ( cake) . exec ( db) . await ?. last_insert_id ;
136
+ let orange = Cake :: insert ( cake)
137
+ . exec ( db)
138
+ . await ?
139
+ . last_insert_id
140
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
93
141
94
142
let mut cake = cake:: ActiveModel {
95
143
name : Set ( "New York Cheese" . to_owned ( ) ) ,
@@ -98,9 +146,17 @@ impl MigrationTrait for Migration {
98
146
bakery_id : Set ( Some ( sea) ) ,
99
147
..Default :: default ( )
100
148
} ;
101
- let cheese_1 = Cake :: insert ( cake. clone ( ) ) . exec ( db) . await ?. last_insert_id ;
149
+ let cheese_1 = Cake :: insert ( cake. clone ( ) )
150
+ . exec ( db)
151
+ . await ?
152
+ . last_insert_id
153
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
102
154
cake. bakery_id = Set ( Some ( lake) ) ;
103
- let cheese_2 = Cake :: insert ( cake) . exec ( db) . await ?. last_insert_id ;
155
+ let cheese_2 = Cake :: insert ( cake)
156
+ . exec ( db)
157
+ . await ?
158
+ . last_insert_id
159
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
104
160
105
161
let mut cake = cake:: ActiveModel {
106
162
name : Set ( "Blueburry Cheese" . to_owned ( ) ) ,
@@ -109,9 +165,17 @@ impl MigrationTrait for Migration {
109
165
bakery_id : Set ( Some ( sea) ) ,
110
166
..Default :: default ( )
111
167
} ;
112
- let blue_1 = Cake :: insert ( cake. clone ( ) ) . exec ( db) . await ?. last_insert_id ;
168
+ let blue_1 = Cake :: insert ( cake. clone ( ) )
169
+ . exec ( db)
170
+ . await ?
171
+ . last_insert_id
172
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
113
173
cake. bakery_id = Set ( Some ( lake) ) ;
114
- let blue_2 = Cake :: insert ( cake) . exec ( db) . await ?. last_insert_id ;
174
+ let blue_2 = Cake :: insert ( cake)
175
+ . exec ( db)
176
+ . await ?
177
+ . last_insert_id
178
+ . ok_or ( DbErr :: UnpackInsertId ) ?;
115
179
116
180
let rel = cake_baker:: ActiveModel {
117
181
cake_id : Set ( choco) ,
0 commit comments