|
| 1 | +{:duct.profile/base |
| 2 | + {:duct.core/project-ns etlp-mapper |
| 3 | + |
| 4 | + :duct.router/ataraxy |
| 5 | + {:routes {[:get "/"] [:etlp-mapper.handler/index] |
| 6 | + [:get "/mappings"] [:etlp-mapper.handler.mappings/list] |
| 7 | + [:post "/mappings" {{:keys [title content]} :body-params}] |
| 8 | + [:etlp-mapper.handler.mappings/create title content] |
| 9 | + |
| 10 | + [:put "/mappings/" id {{:keys [content]} :body-params}] |
| 11 | + [:etlp-mapper.handler.mappings/update ^int id content] |
| 12 | + |
| 13 | + [:post "/mappings/" id "/apply" {{:keys [data]} :body-params}] |
| 14 | + [:etlp-mapper.handler/apply-mappings ^int id data] |
| 15 | + |
| 16 | + [:post "/mappings/test"] |
| 17 | + [:etlp-mapper.handler/mappings] |
| 18 | + |
| 19 | + [:post "/mappings/opai"] |
| 20 | + [:etlp-mapper.handler/openai] |
| 21 | + |
| 22 | + |
| 23 | + [:get "/mappings/" id] [:etlp-mapper.handler.mappings/find ^int id] |
| 24 | + [:get "/mappings/" id "/_history"] [:etlp-mapper.handler.mappings/history ^int id] |
| 25 | + [:get "/mappings/" id "/_history/" version] [:etlp-mapper.handler.mappings/traverse-history ^int id version] |
| 26 | + [:delete "/mappings/" id] [:etlp-mapper.handler.mappings/destroy ^int id]}} |
| 27 | + |
| 28 | + :duct.migrator/ragtime |
| 29 | + {:migrations [#ig/ref :etlp-mapper.migration/create-mappings |
| 30 | + #ig/ref :etlp-mapper.migration/create-mappings-history |
| 31 | + #ig/ref :etlp-mapper.migration/insert-mapping-history |
| 32 | + #ig/ref :etlp-mapper.migration/insert_mapping_history_trigger |
| 33 | + #ig/ref :etlp-mapper.migration/updated-at-trigger |
| 34 | + #ig/ref :etlp-mapper.migration/updated-mapping-trigger]} |
| 35 | + |
| 36 | + ; Mapper specific tables |
| 37 | + [:duct.migrator.ragtime/sql :etlp-mapper.migration/create-mappings] |
| 38 | + {:up ["CREATE TABLE mappings (id SERIAL PRIMARY KEY, title TEXT NOT NULL, content JSONB, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP)"] |
| 39 | + :down ["DROP TABLE mappings"]} |
| 40 | + [:duct.migrator.ragtime/sql :etlp-mapper.migration/create-mappings-history] |
| 41 | + {:up ["CREATE TABLE mappings_history (id SERIAL PRIMARY KEY, original_id INT, txnid TEXT, title TEXT NOT NULL, content JSONB, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE)"] |
| 42 | + :down ["DROP TABLE mappings_history"]} |
| 43 | + |
| 44 | +;DB procedure and triggers for cross cutting concerns |
| 45 | + [:duct.migrator.ragtime/sql :etlp-mapper.migration/insert-mapping-history] |
| 46 | + {:up ["CREATE OR REPLACE FUNCTION insert_mapping_history() |
| 47 | +RETURNS TRIGGER AS $$ |
| 48 | +DECLARE |
| 49 | + txnid TEXT; |
| 50 | +BEGIN |
| 51 | + txnid := txid_current(); |
| 52 | + INSERT INTO mappings_history ( |
| 53 | + title, |
| 54 | + content, |
| 55 | + created_at, |
| 56 | + updated_at, |
| 57 | + original_id, |
| 58 | + txnid |
| 59 | + ) |
| 60 | + VALUES ( |
| 61 | + OLD.title, |
| 62 | + OLD.content, |
| 63 | + OLD.created_at, |
| 64 | + OLD.updated_at, |
| 65 | + OLD.id, |
| 66 | + txnid |
| 67 | + ); |
| 68 | + RETURN NEW; |
| 69 | +END; |
| 70 | +$$ LANGUAGE plpgsql;"] |
| 71 | + :down ["DROP FUNCTION insert_mapping_history"]} |
| 72 | + [:duct.migrator.ragtime/sql :etlp-mapper.migration/insert_mapping_history_trigger] |
| 73 | + {:up ["CREATE TRIGGER insert_mapping_history_trigger BEFORE UPDATE ON mappings FOR EACH ROW EXECUTE FUNCTION insert_mapping_history();"] |
| 74 | + :down ["DROP TRIGGER insert_mapping_history_trigger"]} |
| 75 | + [:duct.migrator.ragtime/sql :etlp-mapper.migration/updated-at-trigger] |
| 76 | + {:up ["CREATE OR REPLACE FUNCTION update_changetimestamp_column() RETURNS TRIGGER AS $$ BEGIN NEW.updated_at = now(); RETURN NEW; END; $$ language 'plpgsql';"] |
| 77 | + :down ["DROP FUNCTION update_changetimestamp_column"]} |
| 78 | + [:duct.migrator.ragtime/sql :etlp-mapper.migration/updated-mapping-trigger] |
| 79 | + {:up ["CREATE TRIGGER update_mapping_changetimestamp BEFORE UPDATE ON mappings FOR EACH ROW EXECUTE PROCEDURE update_changetimestamp_column();"] |
| 80 | + :down ["DROP TRIGGER update_mapping_changetimestamp"]} |
| 81 | + |
| 82 | +;Query handlers for Rest Endpoints |
| 83 | + [:duct.handler.sql/query :etlp-mapper.handler.mappings/list] |
| 84 | + {:sql ["SELECT * FROM mappings"] |
| 85 | + :hrefs {:href "/mappings/{id}"}} |
| 86 | + |
| 87 | + :etlp-mapper.handler/index |
| 88 | + {:db #ig/ref :duct.database/sql} |
| 89 | + |
| 90 | + :etlp-mapper.handler/mappings |
| 91 | + {:db #ig/ref :duct.database/sql} |
| 92 | + |
| 93 | + :etlp-mapper.handler/openai |
| 94 | + {:db #ig/ref :duct.database/sql} |
| 95 | + |
| 96 | + :etlp-mapper.handler/apply-mappings |
| 97 | + {:db #ig/ref :duct.database/sql |
| 98 | + :request {[_ id data] :ataraxy/result}} |
| 99 | + |
| 100 | + [:duct.handler.sql/insert :etlp-mapper.handler.mappings/create] |
| 101 | + {:request {[_ title content] :ataraxy/result} |
| 102 | + :sql ["INSERT INTO mappings (title, content) VALUES (?, ?)" title content] |
| 103 | + :location "mappings/{id}" |
| 104 | + :hrefs {:href "/mappings/{id}"}} |
| 105 | + |
| 106 | + [:duct.handler.sql/query-one :etlp-mapper.handler.mappings/find] |
| 107 | + {:request {[_ id] :ataraxy/result} |
| 108 | + :sql ["SELECT * FROM mappings WHERE id = ?" id] |
| 109 | + :hrefs {:href "/mappings/{id}"}} |
| 110 | + |
| 111 | + [:duct.handler.sql/execute :etlp-mapper.handler.mappings/destroy] |
| 112 | + {:request {[_ id] :ataraxy/result} |
| 113 | + :sql ["DELETE FROM mappings WHERE id = ?" id]} |
| 114 | + |
| 115 | + [:duct.handler.sql/execute :etlp-mapper.handler.mappings/update] |
| 116 | + {:request {[_ id content] :ataraxy/result} |
| 117 | + :sql ["UPDATE mappings SET content = ? WHERE id = ?" content id]} |
| 118 | + |
| 119 | + [:duct.handler.sql/query :etlp-mapper.handler.mappings/history] |
| 120 | + {:request {[_ id] :ataraxy/result} |
| 121 | + :sql ["SELECT mh.title, mh.content, mh.created_at, mh.updated_at, mh.txnid FROM mappings m JOIN mappings_history mh ON m.id = mh.original_id WHERE m.id = ?" id] |
| 122 | + :hrefs {:href "/mappings/{id}/_history/{txnid}"}} |
| 123 | + |
| 124 | + [:duct.handler.sql/query-one :etlp-mapper.handler.mappings/traverse-history] |
| 125 | + {:request {[_ id version] :ataraxy/result} |
| 126 | + :sql ["SELECT mh.title, mh.content, mh.created_at, mh.updated_at, mh.txnid FROM mappings m JOIN mappings_history mh ON m.id = mh.original_id WHERE m.id = ? AND mh.txnid = ?" id version]}} |
| 127 | + |
| 128 | + :duct.profile/dev #duct/include "dev" |
| 129 | +; :duct.profile/local #duct/include "local" |
| 130 | + :duct.profile/prod #duct/include "prod.edn" |
| 131 | + |
| 132 | + :duct.module/logging {} |
| 133 | + :duct.module.web/api |
| 134 | + {} |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + :duct.module/sql |
| 139 | + {}} |
| 140 | + |
1 | 141 | {:duct.profile/base
|
2 | 142 | {:duct.core/project-ns etlp-mapper
|
3 | 143 |
|
|
0 commit comments