fix #354
This commit is contained in:
parent
915857754d
commit
66fc3a68ee
3 changed files with 22 additions and 2 deletions
|
|
@ -3,6 +3,8 @@
|
||||||
* 2.1.next in progress
|
* 2.1.next in progress
|
||||||
* Fix #371 by treating the operand of `NOT` as a nested expression (so it is parenthesized unless it is a simple value).
|
* Fix #371 by treating the operand of `NOT` as a nested expression (so it is parenthesized unless it is a simple value).
|
||||||
* Fix #370 by **always** parenthesizing the operand of `:nest`.
|
* Fix #370 by **always** parenthesizing the operand of `:nest`.
|
||||||
|
* Fix #354 by supporting `DROP COLUMN IF EXISTS` / `ADD COLUMN IF NOT EXISTS`.
|
||||||
|
* Update `build-clj` to v0.5.5.
|
||||||
|
|
||||||
* 2.1.818 -- 2021-10-04
|
* 2.1.818 -- 2021-10-04
|
||||||
* Fix #367 by supporting parameters in subexpressions around `IS NULL` / `IS NOT NULL` tests.
|
* Fix #367 by supporting parameters in subexpressions around `IS NULL` / `IS NOT NULL` tests.
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,15 @@ If a single table name is provided, a single column
|
||||||
user=> (sql/format {:alter-table :fruit
|
user=> (sql/format {:alter-table :fruit
|
||||||
:add-column [:id :int [:not nil]]})
|
:add-column [:id :int [:not nil]]})
|
||||||
["ALTER TABLE fruit ADD COLUMN id INT NOT NULL"]
|
["ALTER TABLE fruit ADD COLUMN id INT NOT NULL"]
|
||||||
|
user=> (sql/format {:alter-table :fruit
|
||||||
|
:add-column [:id :int [:not nil] :if-not-exists]})
|
||||||
|
["ALTER TABLE fruit ADD COLUMN IF NOT EXISTS id INT NOT NULL"]
|
||||||
user=> (sql/format {:alter-table :fruit
|
user=> (sql/format {:alter-table :fruit
|
||||||
:drop-column :ident})
|
:drop-column :ident})
|
||||||
["ALTER TABLE fruit DROP COLUMN ident"]
|
["ALTER TABLE fruit DROP COLUMN ident"]
|
||||||
|
user=> (sql/format {:alter-table :fruit
|
||||||
|
:drop-column [:if-exists :ident]})
|
||||||
|
["ALTER TABLE fruit DROP COLUMN IF EXISTS ident"]
|
||||||
user=> (sql/format {:alter-table :fruit
|
user=> (sql/format {:alter-table :fruit
|
||||||
:modify-column [:id :int :unsigned nil]})
|
:modify-column [:id :int :unsigned nil]})
|
||||||
["ALTER TABLE fruit MODIFY COLUMN id INT UNSIGNED NULL"]
|
["ALTER TABLE fruit MODIFY COLUMN id INT UNSIGNED NULL"]
|
||||||
|
|
@ -63,6 +69,16 @@ user=> (sql/format {:alter-table [:fruit
|
||||||
{:add-column [:id :int [:not nil]]}
|
{:add-column [:id :int [:not nil]]}
|
||||||
{:drop-column :ident}]})
|
{:drop-column :ident}]})
|
||||||
["ALTER TABLE fruit ADD COLUMN id INT NOT NULL, DROP COLUMN ident"]
|
["ALTER TABLE fruit ADD COLUMN id INT NOT NULL, DROP COLUMN ident"]
|
||||||
|
user=> (sql/format {:alter-table [:fruit
|
||||||
|
{:add-column [:id :int [:not nil]]}
|
||||||
|
{:add-column [:name [:varchar 32]]}
|
||||||
|
{:drop-column :ident}
|
||||||
|
{:modify-column [:appearance :text]}]})
|
||||||
|
["ALTER TABLE fruit ADD COLUMN id INT NOT NULL, ADD COLUMN name VARCHAR(32), DROP COLUMN ident, MODIFY COLUMN appearance TEXT"]
|
||||||
|
user=> (sql/format {:alter-table [:fruit
|
||||||
|
{:add-column [:id :int [:not nil] :if-not-exists]}
|
||||||
|
{:drop-column [:if-exists :ident]}]})
|
||||||
|
["ALTER TABLE fruit ADD COLUMN IF NOT EXISTS id INT NOT NULL, DROP COLUMN IF EXISTS ident"]
|
||||||
```
|
```
|
||||||
|
|
||||||
As can be seen above, `:add-column` and `:modify-column`
|
As can be seen above, `:add-column` and `:modify-column`
|
||||||
|
|
|
||||||
|
|
@ -813,7 +813,9 @@
|
||||||
")")])
|
")")])
|
||||||
|
|
||||||
(defn- format-add-item [k spec]
|
(defn- format-add-item [k spec]
|
||||||
[(str (sql-kw k) " " (format-single-column spec))])
|
(if (contains? #{:if-not-exists 'if-not-exists} (last spec))
|
||||||
|
[(str (sql-kw k) " " (sql-kw :if-not-exists) " " (format-single-column (butlast spec)))]
|
||||||
|
[(str (sql-kw k) " " (format-single-column spec))]))
|
||||||
|
|
||||||
(defn- format-rename-item [k [x y]]
|
(defn- format-rename-item [k [x y]]
|
||||||
[(str (sql-kw k) " " (format-entity x) " TO " (format-entity y))])
|
[(str (sql-kw k) " " (format-entity x) " TO " (format-entity y))])
|
||||||
|
|
@ -849,7 +851,7 @@
|
||||||
and removed."
|
and removed."
|
||||||
(atom {:alter-table #'format-alter-table
|
(atom {:alter-table #'format-alter-table
|
||||||
:add-column #'format-add-item
|
:add-column #'format-add-item
|
||||||
:drop-column #'format-selector
|
:drop-column #'format-drop-items
|
||||||
:modify-column #'format-add-item
|
:modify-column #'format-add-item
|
||||||
:rename-column #'format-rename-item
|
:rename-column #'format-rename-item
|
||||||
;; so :add-index works with both [:index] and [:unique]
|
;; so :add-index works with both [:index] and [:unique]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue