Link tables working; a few other minor fixes.

This commit is contained in:
Simon Brooke 2018-06-14 11:56:47 +01:00
parent 055eac8092
commit f0ddceb19c

View file

@ -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)
(filter (sort-by-name
(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,34 +452,41 @@
: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
[(construct-link-property e1) (list
[(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
(emit-table (flatten
link-entity (list
application (emit-table
(str link-entity
"link table joining " application
(:name (:attrs e1)) (str
" with " "link table joining "
(:name (:attrs e2)))) (:name (:attrs e1))
;; and immediately emit its referential integrity links " with "
(emit-referential-integrity-links link-entity application))))) (:name (:attrs e2))))
;; and immediately emit its referential integrity links
(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