Link tables working; a few other minor fixes.
This commit is contained in:
parent
055eac8092
commit
f0ddceb19c
|
@ -336,8 +336,8 @@
|
||||||
(list
|
(list
|
||||||
"ALTER TABLE"
|
"ALTER TABLE"
|
||||||
(:name (:attrs nearside))
|
(:name (:attrs nearside))
|
||||||
"ADD CONSTRINT"
|
"ADD CONSTRAINT"
|
||||||
(str "ri_" (:name (:attrs nearside)) "_" (:name (:attrs farside)) "_" (:name (:attrs property)))
|
(str "ri_" (:name (:attrs nearside)) "_" (:name (:attrs property)))
|
||||||
"\n\tFOREIGN KEY("
|
"\n\tFOREIGN KEY("
|
||||||
(:name (:attrs property))
|
(:name (:attrs property))
|
||||||
") \n\tREFERENCES"
|
") \n\tREFERENCES"
|
||||||
|
@ -357,9 +357,10 @@
|
||||||
([entity application]
|
([entity application]
|
||||||
(map
|
(map
|
||||||
#(emit-referential-integrity-link % entity application)
|
#(emit-referential-integrity-link % entity application)
|
||||||
|
(sort-by-name
|
||||||
(filter
|
(filter
|
||||||
#(= (:type (:attrs %)) "entity")
|
#(= (:type (:attrs %)) "entity")
|
||||||
(properties entity))))
|
(properties entity)))))
|
||||||
([application]
|
([application]
|
||||||
(flatten
|
(flatten
|
||||||
(list
|
(list
|
||||||
|
@ -368,7 +369,7 @@
|
||||||
(str "--\treferential integrity links for first-class tables"))
|
(str "--\treferential integrity links for first-class tables"))
|
||||||
(map
|
(map
|
||||||
#(emit-referential-integrity-links % application)
|
#(emit-referential-integrity-links % application)
|
||||||
(children-with-tag application :entity))))))
|
(sort-by-name (children-with-tag application :entity)))))))
|
||||||
|
|
||||||
|
|
||||||
(defn emit-table
|
(defn emit-table
|
||||||
|
@ -427,7 +428,8 @@
|
||||||
:column (str (:name (:attrs entity)) "_id")
|
:column (str (:name (:attrs entity)) "_id")
|
||||||
:type "entity"
|
:type "entity"
|
||||||
:entity (:name (:attrs entity))
|
:entity (:name (:attrs entity))
|
||||||
:farkey (first (key-names entity))}})
|
:farkey (first (key-names entity))}
|
||||||
|
:content nil})
|
||||||
|
|
||||||
|
|
||||||
(defn emit-link-table
|
(defn emit-link-table
|
||||||
|
@ -450,14 +452,17 @@
|
||||||
:attrs {:name link-table-name
|
:attrs {:name link-table-name
|
||||||
:table link-table-name}
|
:table link-table-name}
|
||||||
:content
|
:content
|
||||||
(vector
|
(apply vector
|
||||||
(concat
|
(flatten
|
||||||
|
(list
|
||||||
[(construct-link-property e1)
|
[(construct-link-property e1)
|
||||||
(construct-link-property e2)]
|
(construct-link-property e2)]
|
||||||
permissions))}]
|
permissions)))}]
|
||||||
;; mark it as emitted
|
;; mark it as emitted
|
||||||
(swap! emitted-link-tables conj link-table-name)
|
(swap! emitted-link-tables conj link-table-name)
|
||||||
;; emit it
|
;; emit it
|
||||||
|
(flatten
|
||||||
|
(list
|
||||||
(emit-table
|
(emit-table
|
||||||
link-entity
|
link-entity
|
||||||
application
|
application
|
||||||
|
@ -467,17 +472,21 @@
|
||||||
" with "
|
" with "
|
||||||
(:name (:attrs e2))))
|
(:name (:attrs e2))))
|
||||||
;; and immediately emit its referential integrity links
|
;; and immediately emit its referential integrity links
|
||||||
(emit-referential-integrity-links link-entity application)))))
|
(emit-referential-integrity-links link-entity application)))))))
|
||||||
|
|
||||||
|
|
||||||
(defn emit-link-tables
|
(defn emit-link-tables
|
||||||
[entity application emitted-link-tables]
|
([entity application emitted-link-tables]
|
||||||
(map
|
(map
|
||||||
#(emit-link-table % entity application emitted-link-tables)
|
#(emit-link-table % entity application emitted-link-tables)
|
||||||
(sort-by-name
|
(sort-by-name
|
||||||
(filter
|
(filter
|
||||||
#(= (:type (:attrs %)) "link")
|
#(= (:type (:attrs %)) "link")
|
||||||
(properties entity)))))
|
(properties entity)))))
|
||||||
|
([application emitted-link-tables]
|
||||||
|
(map
|
||||||
|
#(emit-link-tables % application emitted-link-tables)
|
||||||
|
(sort-by-name (children-with-tag application :entity)))))
|
||||||
|
|
||||||
|
|
||||||
(defn emit-entity
|
(defn emit-entity
|
||||||
|
@ -530,10 +539,7 @@
|
||||||
(sort-by-name
|
(sort-by-name
|
||||||
(children-with-tag application :entity)))
|
(children-with-tag application :entity)))
|
||||||
(emit-referential-integrity-links application)
|
(emit-referential-integrity-links application)
|
||||||
(map
|
(emit-link-tables application emitted-link-tables))))))
|
||||||
#(emit-link-tables % application emitted-link-tables)
|
|
||||||
(sort-by-name
|
|
||||||
(children-with-tag application :entity))))))))
|
|
||||||
|
|
||||||
|
|
||||||
(defn to-psql
|
(defn to-psql
|
||||||
|
|
Loading…
Reference in a new issue