dcSchema ; 
 ; ----------------------------------------------------------------------------
 ; #
 ; #  DivConq
 ; #
 ; #  http://divconq.com/
 ; #
 ; #  Copyright:
 ; #    Copyright 2012 eTimeline, LLC. All rights reserved.
 ; #
 ; #  License:
 ; #    See the dcLicense.txt file in the project's top-level directory for details.
 ; #
 ; #  Authors:
 ; #    * Andy White
 ; #
 ; ----------------------------------------------------------------------------
 ;
 ; Java utility uploads repository to M.  This function processes values from
 ; the repository that need to be shared by M. 
 ;
update k ^Proc,^Filter1,^Filter2,^Locale,^Schema,^Composer1,^Composer2,^Composer3,^Collector
 ;
 d minSchema^dcInstall		; in case something fails below, we still support min features
 ;
 n i,t,name
 f  s i=$o(^Params(Pid,"Procs",i))  q:i=""  d
 . s ^Proc(^Params(Pid,"Procs",i,"Name"))=^Params(Pid,"Procs",i,"Execute")
 ;
 f  s i=$o(^Params(Pid,"RecordFilters",i))  q:i=""  d
 . s ^Filter1(^Params(Pid,"RecordFilters",i,"Name"))=^Params(Pid,"RecordFilters",i,"Execute")
 ;
 f  s i=$o(^Params(Pid,"WhereFilters",i))  q:i=""  d
 . s ^Filter2(^Params(Pid,"WhereFilters",i,"Name"))=^Params(Pid,"WhereFilters",i,"Execute")
 ;
 f  s i=$o(^Params(Pid,"RecordComposers",i))  q:i=""  d
 . s ^Composer1(^Params(Pid,"RecordComposers",i,"Name"))=^Params(Pid,"RecordComposers",i,"Execute")
 ;
 f  s i=$o(^Params(Pid,"SelectComposers",i))  q:i=""  d
 . s ^Composer2(^Params(Pid,"SelectComposers",i,"Name"))=^Params(Pid,"SelectComposers",i,"Execute")
 ;
 f  s i=$o(^Params(Pid,"WhereComposers",i))  q:i=""  d
 . s ^Composer3(^Params(Pid,"WhereComposers",i,"Name"))=^Params(Pid,"WhereComposers",i,"Execute")
 ;
 f  s i=$o(^Params(Pid,"Collectors",i))  q:i=""  d
 . s ^Collector(^Params(Pid,"Collectors",i,"Name"))=^Params(Pid,"Collectors",i,"Execute")
 ;
 f  s i=$o(^Params(Pid,"Tables",i))  q:i=""  d addTable
 ;
 f  s i=$o(^Params(Pid,"Locales",i))  q:i=""  d
 . s name=^Params(Pid,"Locales",i,"Name")
 . f  s t=$o(^Params(Pid,"Locales",i,"Tokens",t))  q:t=""  d
 . . s ^Locale(name,^Params(Pid,"Locales",i,"Tokens",t,"Key"))=^Params(Pid,"Locales",i,"Tokens",t,"Value")
 ;
 quit
 ;
 ;
addTable n table,fi,field,fk
 s table=^Params(Pid,"Tables",i,"Name")
 ;
 ; all tables have the following...
 s ^Schema(table,"Fields","Retired","Name")="Retired"
 s ^Schema(table,"Fields","Retired","Type")="Boolean"
 ;
 s ^Schema(table,"Fields","From","Name")="From"
 s ^Schema(table,"Fields","From","Type")="BigDateTime"
 s ^Schema(table,"Fields","From","Indexed")=1
 ;
 s ^Schema(table,"Fields","To","Name")="To"
 s ^Schema(table,"Fields","To","Type")="BigDateTime"
 s ^Schema(table,"Fields","To","Indexed")=1
 ;
 s ^Schema(table,"Fields","Tags","Name")="Tags"
 s ^Schema(table,"Fields","Tags","Type")="String"
 s ^Schema(table,"Fields","Tags","TypeId")="dcTinyString"
 s ^Schema(table,"Fields","Tags","List")="True"
 ;
 f  s fi=$o(^Params(Pid,"Tables",i,"Fields",fi))  q:fi=""  d 
 . s field=^Params(Pid,"Tables",i,"Fields",fi,"Name")
 . m ^Schema(table,"Fields",field)=^Params(Pid,"Tables",i,"Fields",fi)
 . ;
 . s fk=^Params(Pid,"Tables",i,"Fields",fi,"ForeignKey")
 . s:fk'="" ^Schema(fk,"ForeignKey",table,field)=1
 ;
 ; TODO add support for triggers
 ; s ^Schema(table,"Triggers","Insert",name)=routine
 ; s ^Schema(table,"Triggers","Retire",name)=routine
 ; s ^Schema(table,"Triggers","Delete",name)=routine
 ;
 quit 
 ;
 ;
 ;

