|
98 | 98 | '(nil nil nil nil nil))
|
99 | 99 | "No migration after migrating"))
|
100 | 100 |
|
101 |
| - (testing "redefinition" |
| 101 | + (testing "redefinition of primary key" |
102 | 102 | (defclass tweets ()
|
103 |
| - ((tweet-id :col-type :serial |
| 103 | + ((tweet-id :col-type :bigserial |
104 | 104 | :primary-key t
|
105 | 105 | :reader tweet-id)
|
106 |
| - (user :col-type (:varchar 64) |
107 |
| - :accessor tweet-user) |
108 |
| - (created-at :col-type (:char 8))) |
| 106 | + (status :col-type :text |
| 107 | + :accessor tweet-status) |
| 108 | + (user :col-type (:varchar 128) |
| 109 | + :accessor tweet-user)) |
109 | 110 | (:metaclass dao-table-class)
|
110 | 111 | (:record-timestamps nil))
|
111 | 112 |
|
|
115 | 116 | add-indices
|
116 | 117 | drop-indices)
|
117 | 118 | (mito.migration.table::migration-expressions-aux (find-class 'tweets) :mysql)
|
118 |
| - (ok (equal (mapcar #'sxql:yield add-columns) |
119 |
| - '("ALTER TABLE tweets ADD COLUMN created_at char(8) NOT NULL"))) |
120 |
| - (ok (equal (mapcar #'sxql:yield drop-columns) '("ALTER TABLE tweets DROP COLUMN status"))) |
| 119 | + (ok (null add-columns)) |
| 120 | + (ok (null drop-columns)) |
121 | 121 | (ok (equal (format nil "~{~A~^~%~}"
|
122 | 122 | (mapcar #'sxql:yield change-columns))
|
123 |
| - "ALTER TABLE tweets MODIFY COLUMN user varchar(64) NOT NULL")) |
| 123 | + "ALTER TABLE tweets MODIFY COLUMN tweet_id bigint unsigned NOT NULL AUTO_INCREMENT")) |
124 | 124 | (ok (null add-indices))
|
125 | 125 | (ok (null drop-indices)))
|
126 | 126 |
|
|
130 | 130 | '(nil nil nil nil nil))
|
131 | 131 | "No migration after migrating"))
|
132 | 132 |
|
133 |
| - (testing "redefinition (modifying the column type)" |
| 133 | + (testing "Change to the serial primary key again" |
134 | 134 | (defclass tweets ()
|
135 |
| - ((tweet-id :col-type :serial |
136 |
| - :primary-key t |
| 135 | + ((tweet-id :col-type :bigint |
137 | 136 | :reader tweet-id)
|
| 137 | + (status :col-type :text |
| 138 | + :accessor tweet-status) |
138 | 139 | (user :col-type (:varchar 128)
|
| 140 | + :accessor tweet-user)) |
| 141 | + (:metaclass dao-table-class) |
| 142 | + (:record-timestamps nil) |
| 143 | + (:unique-keys (tweet-id))) |
| 144 | + |
| 145 | + (destructuring-bind (add-columns |
| 146 | + drop-columns |
| 147 | + change-columns |
| 148 | + add-indices |
| 149 | + drop-indices) |
| 150 | + (mito.migration.table::migration-expressions-aux (find-class 'tweets) :mysql) |
| 151 | + (ok (equal (mapcar #'sxql:yield add-columns) |
| 152 | + '("ALTER TABLE tweets ADD COLUMN id bigint unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY")) |
| 153 | + "Add id") |
| 154 | + (ok (null drop-columns) |
| 155 | + "No columns to drop") |
| 156 | + (ok (equal (mapcar #'sxql:yield change-columns) |
| 157 | + '("ALTER TABLE tweets MODIFY COLUMN tweet_id bigint NOT NULL")) |
| 158 | + "Change the type of tweet_id") |
| 159 | + (ok (equal (mapcar #'sxql:yield add-indices) |
| 160 | + '("CREATE UNIQUE INDEX unique_tweets_tweet_id ON tweets (tweet_id)")) |
| 161 | + "Add a unique index") |
| 162 | + (ok (equal (mapcar #'sxql:yield drop-indices) |
| 163 | + '("ALTER TABLE tweets MODIFY COLUMN tweet_id bigint unsigned NOT NULL" |
| 164 | + "DROP INDEX PRIMARY ON tweets")) |
| 165 | + "Drop the primary key")) |
| 166 | + |
| 167 | + (migrate-table (find-class 'tweets)) |
| 168 | + |
| 169 | + (ok (equal (mito.migration.table::migration-expressions-aux (find-class 'tweets) :mysql) |
| 170 | + '(nil nil nil nil nil)) |
| 171 | + "No migration after migrating")) |
| 172 | + |
| 173 | + (testing "redefinition" |
| 174 | + (defclass tweets () |
| 175 | + ((tweet-id :col-type :bigint |
| 176 | + :reader tweet-id) |
| 177 | + (user :col-type (:varchar 64) |
139 | 178 | :accessor tweet-user)
|
140 | 179 | (created-at :col-type (:char 8)))
|
141 | 180 | (:metaclass dao-table-class)
|
142 |
| - (:record-timestamps nil)) |
| 181 | + (:record-timestamps nil) |
| 182 | + (:unique-keys (tweet-id))) |
143 | 183 |
|
144 | 184 | (destructuring-bind (add-columns
|
145 | 185 | drop-columns
|
146 | 186 | change-columns
|
147 | 187 | add-indices
|
148 | 188 | drop-indices)
|
149 | 189 | (mito.migration.table::migration-expressions-aux (find-class 'tweets) :mysql)
|
150 |
| - (ok (null add-columns)) |
151 |
| - (ok (null drop-columns)) |
| 190 | + (ok (equal (mapcar #'sxql:yield add-columns) |
| 191 | + '("ALTER TABLE tweets ADD COLUMN created_at char(8) NOT NULL"))) |
| 192 | + (ok (equal (mapcar #'sxql:yield drop-columns) '("ALTER TABLE tweets DROP COLUMN status"))) |
152 | 193 | (ok (equal (format nil "~{~A~^~%~}"
|
153 | 194 | (mapcar #'sxql:yield change-columns))
|
154 |
| - "ALTER TABLE tweets MODIFY COLUMN user varchar(128) NOT NULL")) |
| 195 | + "ALTER TABLE tweets MODIFY COLUMN user varchar(64) NOT NULL")) |
155 | 196 | (ok (null add-indices))
|
156 | 197 | (ok (null drop-indices)))
|
157 | 198 |
|
|
161 | 202 | '(nil nil nil nil nil))
|
162 | 203 | "No migration after migrating"))
|
163 | 204 |
|
164 |
| - (testing "redefinition of primary key" |
| 205 | + (testing "redefinition (modifying the column type)" |
165 | 206 | (defclass tweets ()
|
166 |
| - ((tweet-id :col-type :bigserial |
167 |
| - :primary-key t |
| 207 | + ((tweet-id :col-type :bigint |
168 | 208 | :reader tweet-id)
|
169 | 209 | (user :col-type (:varchar 128)
|
170 | 210 | :accessor tweet-user)
|
171 | 211 | (created-at :col-type (:char 8)))
|
172 | 212 | (:metaclass dao-table-class)
|
173 |
| - (:record-timestamps nil)) |
| 213 | + (:record-timestamps nil) |
| 214 | + (:unique-keys (tweet-id))) |
174 | 215 |
|
175 | 216 | (destructuring-bind (add-columns
|
176 | 217 | drop-columns
|
|
182 | 223 | (ok (null drop-columns))
|
183 | 224 | (ok (equal (format nil "~{~A~^~%~}"
|
184 | 225 | (mapcar #'sxql:yield change-columns))
|
185 |
| - "ALTER TABLE tweets MODIFY COLUMN tweet_id bigint unsigned NOT NULL AUTO_INCREMENT")) |
| 226 | + "ALTER TABLE tweets MODIFY COLUMN user varchar(128) NOT NULL")) |
186 | 227 | (ok (null add-indices))
|
187 | 228 | (ok (null drop-indices)))
|
188 | 229 |
|
|
194 | 235 |
|
195 | 236 | (testing "add :unique-keys"
|
196 | 237 | (defclass tweets ()
|
197 |
| - ((tweet-id :col-type :bigserial |
198 |
| - :primary-key t |
| 238 | + ((tweet-id :col-type :bigint |
199 | 239 | :reader tweet-id)
|
200 | 240 | (user :col-type (:varchar 128)
|
201 | 241 | :accessor tweet-user)
|
202 | 242 | (created-at :col-type (:char 8)))
|
203 | 243 | (:metaclass dao-table-class)
|
204 |
| - (:unique-keys (user created-at)) |
205 |
| - (:record-timestamps nil)) |
| 244 | + (:record-timestamps nil) |
| 245 | + (:unique-keys (tweet-id) (user created-at))) |
206 | 246 |
|
207 | 247 | (destructuring-bind (add-columns
|
208 | 248 | drop-columns
|
|
226 | 266 |
|
227 | 267 | (testing "modify :unique-keys"
|
228 | 268 | (defclass tweets ()
|
229 |
| - ((tweet-id :col-type :bigserial |
230 |
| - :primary-key t |
| 269 | + ((tweet-id :col-type :bigint |
231 | 270 | :reader tweet-id)
|
232 | 271 | (user :col-type (:varchar 128)
|
233 | 272 | :accessor tweet-user)
|
234 | 273 | (created-at :col-type (:char 8)))
|
235 | 274 | (:metaclass dao-table-class)
|
236 |
| - (:unique-keys (tweet-id user created-at)) |
237 |
| - (:record-timestamps nil)) |
| 275 | + (:record-timestamps nil) |
| 276 | + (:unique-keys (tweet-id) |
| 277 | + (tweet-id user created-at))) |
238 | 278 |
|
239 | 279 | (destructuring-bind (add-columns
|
240 | 280 | drop-columns
|
|
259 | 299 |
|
260 | 300 | (testing "delete :unique-keys and add :keys"
|
261 | 301 | (defclass tweets ()
|
262 |
| - ((tweet-id :col-type :bigserial |
263 |
| - :primary-key t |
| 302 | + ((tweet-id :col-type :bigint |
264 | 303 | :reader tweet-id)
|
265 | 304 | (user :col-type (:varchar 128)
|
266 | 305 | :accessor tweet-user)
|
267 | 306 | (created-at :col-type (:char 8)))
|
268 | 307 | (:metaclass dao-table-class)
|
269 |
| - (:keys (user created-at)) |
270 |
| - (:record-timestamps nil)) |
| 308 | + (:record-timestamps nil) |
| 309 | + (:unique-keys (tweet-id)) |
| 310 | + (:keys (user created-at))) |
271 | 311 |
|
272 | 312 | (destructuring-bind (add-columns
|
273 | 313 | drop-columns
|
|
0 commit comments