Skip to content

Commit

Permalink
Fix table constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitem committed Dec 14, 2023
1 parent 22cb4b1 commit 1454fc6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/dsql/pg.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1158,9 +1158,11 @@
(conj "TABLE")
(cond-> not-ex (conj "IF NOT EXISTS"))
(identifier opts table-name)
(cond-> columns (conj "(" (mk-columns opts columns)))
(cond-> constraint (conj "," (mk-table-constraint constraint)))
(cond-> columns (conj ")"))
(cond-> (or columns constraint) (conj "("))
(cond-> columns (conj (mk-columns opts columns)))
(cond-> (and columns constraint) (conj ","))
(cond-> constraint (conj (mk-table-constraint constraint)))
(cond-> (or columns constraint) (conj ")"))

(cond-> partition-of (conj "partition of" (name partition-of) ))
(cond-> for (conj "for values"
Expand Down
6 changes: 6 additions & 0 deletions test/dsql/pg_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,12 @@
:columns {:a {:type "integer" }}}
["CREATE TABLE \"MyTable\" ( \"a\" integer )"])

(format=
{:ql/type :pg/create-table
:table-name "mytable"
:constraint {:primary-key [:id :partition]}}
["CREATE TABLE mytable ( PRIMARY KEY (\"id\", \"partition\") )"])

(format=
{:ql/type :pg/create-table
:table-name "mytable"
Expand Down

0 comments on commit 1454fc6

Please sign in to comment.