Skip to content

Commit

Permalink
Don't add DEFAULT by :initform to CREATE TABLE.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Jun 18, 2024
1 parent 15ddf02 commit d18d7f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
18 changes: 1 addition & 17 deletions src/core/dao/column.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
#:mito.util)
(:import-from #:mito.class.column
#:table-column-class
#:table-column-type
#:table-column-info)
(:import-from #:mito.conversion
#:convert-for-driver-type)
#:table-column-type)
(:import-from #:local-time)
(:import-from #:cl-ppcre)
(:import-from #:closer-mop)
(:export #:dao-table-column-class
#:dao-table-column-inflate
#:dao-table-column-deflate
Expand Down Expand Up @@ -145,15 +141,3 @@
(deflate-for-col-type :datetime value))
(:method ((col-type (eql :timestamptz)) value)
(deflate-for-col-type :datetime value)))

(defmethod table-column-info :around ((column dao-table-column-class) driver-type)
(let ((column-info (call-next-method)))
(when (null (getf (cdr column-info) :default))
(setf (getf (cdr column-info) :default)
(and (c2mop:slot-definition-initfunction column)
(convert-for-driver-type
driver-type
(table-column-type column)
(dao-table-column-deflate column
(funcall (c2mop:slot-definition-initfunction column)))))))
column-info))
14 changes: 10 additions & 4 deletions src/migration/table.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
(:import-from #:alexandria
#:ensure-list
#:compose
#:when-let)
#:when-let
#:delete-from-plist)
(:export #:*auto-migration-mode*
#:*migration-keep-temp-tables*
#:migrate-table
Expand Down Expand Up @@ -76,8 +77,7 @@ If this variable is T they won't be deleted after migration.")
:key #'car)))

(defun column-definition-equal-p (column1 column2)
(and (first column1)
(first column2)
(and (equal (first column1) (first column2))
(plist= (cdr column1) (cdr column2))))

(defun migration-expressions-between-for-sqlite3 (class from-columns to-columns from-indices to-indices)
Expand Down Expand Up @@ -308,6 +308,12 @@ If this variable is T they won't be deleted after migration.")
nil
(list :on (sxql:make-sql-symbol table-name))))))))))))

(defun omit-default (definitions)
(mapcar (lambda (definition)
(cons (car definition)
(delete-from-plist (cdr definition) :default)))
definitions))

(defun migration-expressions-aux (class driver-type)
(let* ((table-name (table-name class))
(table-columns
Expand All @@ -318,7 +324,7 @@ If this variable is T they won't be deleted after migration.")
info))
(database-column-slots class)))
(table-indices (table-indices-info class driver-type))
(db-columns (column-definitions *connection* table-name))
(db-columns (omit-default (column-definitions *connection* table-name)))
(db-indices (table-indices *connection* table-name)))
(values
(migration-expressions-between class driver-type
Expand Down

0 comments on commit d18d7f0

Please sign in to comment.