                :user *database-user*
                :password *database-password*
                :naming {:keys string/upper-case
-                        :fields string/upper-case}})
-    )
-
-
-
-
+                        :fields string/upper-case}}))
 
 
   (catch Exception e




(defn make-log-table []
  (let [coils-admin-tables      (korma.core/exec-raw
                                   [" select * from pg_tables where schemaname='public' and tablename='coils_realtime_log'" []]
                                   :results)

        coils-admin-table-exists   (pos? (count coils-admin-tables))

        sql-to-create-admin-table "
CREATE TABLE coils_realtime_log
(
  id                  serial NOT NULL,
  realtime_jvm_id     integer,
  record_timestamp    timestamp without time zone,
  record_table_name   character varying,
  record_id           character varying,
  record_operation    character varying,
  record_status       character varying
);
"
  ]

      (println "Coils admin table exists: " coils-admin-table-exists)
      (if (not coils-admin-table-exists )
                      (korma.core/exec-raw   [sql-to-create-admin-table []]   [])
                      nil
        )





  )
  )






(defn make-log-table-delete-trigger-function []
  (let [coils-trigger-fn-exists-result      (korma.core/exec-raw
                                             ["select exists(select * from pg_proc where proname = 'trigger_function_afterDelete');" []]
                                             :results)

        coils-trigger-fn-exists   (= "t"  coils-trigger-fn-exists-result)

        sql-to-create-trigger-fn "
        CREATE OR REPLACE FUNCTION trigger_function_afterDelete()
        RETURNS trigger AS
        $BODY$
        BEGIN
        INSERT INTO coils_realtime_log
        (record_timestamp,  record_table_name,  record_id,  record_operation,  record_status)
        VALUES
        ( now(),   TG_TABLE_NAME ,  OLD.id,  'DELETE',  'WAITING');
        RETURN NULL;
        END;
        $BODY$
        LANGUAGE plpgsql;
        "
        ]

    ;(println "Coils trigger function exists: " coils-trigger-fn-exists)
    (if (not coils-trigger-fn-exists )
      (korma.core/exec-raw   [sql-to-create-trigger-fn []]   [])
      nil)))












(make-todo-table)
(make-users-table)
(make-admin-table )
(make-log-table   )







