Compare commits

...

5 Commits

Author SHA1 Message Date
Josha von Gizycki 8d45578e5f Merge branch 'master' into triology
5 years ago
Josha von Gizycki 73a8e5f2b9 change how links work
5 years ago
Josha von Gizycki 6f18bfe7f8 Merge branch 'master' of https://gitea.heevyis.ninja/josha/wanijo
5 years ago
Josha von Gizycki 913653780c ancient
5 years ago
Josha von Gizycki b69471fd98 fix migrations
5 years ago

@ -1,10 +1,9 @@
(ns wanijo.infrastructure.repl (ns wanijo.infrastructure.repl
(:require [buddy.hashers :as hashers] (:require [buddy.hashers :as hashers]
[neo4j-clj.core :as db]
[wanijo.infrastructure.neo4j :as neo4j] [wanijo.infrastructure.neo4j :as neo4j]
[wanijo.main :as main])) [wanijo.main :as main]))
(db/defquery create-user (neo4j/defquery create-user
"CREATE (n:user) "CREATE (n:user)
SET n.ident = {ident} SET n.ident = {ident}
SET n.pw = {pw} SET n.pw = {pw}
@ -17,7 +16,7 @@
:pw (hashers/derive pw) :pw (hashers/derive pw)
:uuid (neo4j/uuid)})) :uuid (neo4j/uuid)}))
(db/defquery merge-config (neo4j/defquery merge-config
"MERGE (c:dbconfig) "MERGE (c:dbconfig)
ON CREATE SET ON CREATE SET
c.installed_at = {now}, c.installed_at = {now},
@ -27,38 +26,38 @@
c.last_migration = {now}, c.last_migration = {now},
c.db_version = {version}") c.db_version = {version}")
(db/defquery config (neo4j/defquery config
"MATCH (c:dbconfig) RETURN c") "MATCH (c:dbconfig) RETURN c")
(db/defquery ver-0-schema-uuid (neo4j/defquery ver-0-schema-uuid
"CREATE CONSTRAINT ON (n:schema) "CREATE CONSTRAINT ON (n:schema)
ASSERT n.uuid IS UNIQUE") ASSERT n.uuid IS UNIQUE")
(db/defquery ver-0-attribute-uuid (neo4j/defquery ver-0-attribute-uuid
"CREATE CONSTRAINT ON (n:attribute) "CREATE CONSTRAINT ON (n:attribute)
ASSERT n.uuid IS UNIQUE") ASSERT n.uuid IS UNIQUE")
(db/defquery ver-0-instance-uuid (neo4j/defquery ver-0-instance-uuid
"CREATE CONSTRAINT ON (n:instance) "CREATE CONSTRAINT ON (n:instance)
ASSERT n.uuid IS UNIQUE") ASSERT n.uuid IS UNIQUE")
(db/defquery ver-0-property-uuid (neo4j/defquery ver-0-property-uuid
"CREATE CONSTRAINT ON (n:property) "CREATE CONSTRAINT ON (n:property)
ASSERT n.uuid IS UNIQUE") ASSERT n.uuid IS UNIQUE")
(db/defquery ver-0-user-uuid (neo4j/defquery ver-0-user-uuid
"CREATE CONSTRAINT ON (n:user) "CREATE CONSTRAINT ON (n:user)
ASSERT n.uuid IS UNIQUE") ASSERT n.uuid IS UNIQUE")
(db/defquery ver-0-link-uuid (neo4j/defquery ver-0-link-uuid
"CREATE CONSTRAINT ON (n:link) "CREATE CONSTRAINT ON (n:link)
ASSERT n.uuid IS UNIQUE") ASSERT n.uuid IS UNIQUE")
(db/defquery ver-1-tag-name (neo4j/defquery ver-1-tag-name
"CREATE CONSTRAINT ON (n:tag) "CREATE CONSTRAINT ON (n:tag)
ASSERT n.name IS UNIQUE") ASSERT n.name IS UNIQUE")
(db/defquery ver-1-tag-uuid (neo4j/defquery ver-1-tag-uuid
"CREATE CONSTRAINT ON (n:tag) "CREATE CONSTRAINT ON (n:tag)
ASSERT n.uuid IS UNIQUE") ASSERT n.uuid IS UNIQUE")
@ -74,9 +73,23 @@
(neo4j/exec-query! ver-1-tag-name {}) (neo4j/exec-query! ver-1-tag-name {})
(neo4j/exec-query! ver-1-tag-uuid {})) (neo4j/exec-query! ver-1-tag-uuid {}))
(neo4j/defquery migrate-links
"MATCH (i1:instance)-[:link_from]-(l:link)-[:link_to]-(i2:instance),
(l)-[cb:created_by]->(:user)
MERGE (i1)-[newl:link]->(i2)
ON CREATE SET
newl.name = l.name,
newl.created_at = l.created_at,
newl.uuid = l.uuid
DELETE cb, lf, lt, l")
(defn init-version-2 []
(neo4j/exec-query! migrate-links {}))
(def migrations (def migrations
[init-version-0 [init-version-0
init-version-1]) init-version-1
init-version-2])
(defn run-migrations! [] (defn run-migrations! []
(neo4j/exec-query! merge-config {:now (neo4j/now-str) (neo4j/exec-query! merge-config {:now (neo4j/now-str)

@ -141,18 +141,12 @@
OPTIONAL MATCH OPTIONAL MATCH
(p:property)-[pc:of]->(i), (p:property)-[pc:of]->(i),
(p)-[pac:of]->(a:attribute) (p)-[pac:of]->(a:attribute)
OPTIONAL MATCH
(i)<-[lt1:link_to]-(ltn:link)-[lt2:link_from]->(),
(ltn)-[ltcb:created_by]->()
OPTIONAL MATCH
(i)<-[lf1:link_from]-(lfn:link)-[lf2:link_to]->(),
(lfn)-[lfcb:created_by]->()
OPTIONAL MATCH OPTIONAL MATCH
(i)-[tw:tagged_with]->() (i)-[tw:tagged_with]->()
OPTIONAL MATCH
(i)-[l:link]-()
DELETE pac, pc, cb, ic, p, DELETE pac, pc, cb, ic, p,
lt1, lt2, ltn, ltcb, l, tw, i")
lf1, lf2, lfn, lfcb,
tw, i")
(defn delete! [uuid] (defn delete! [uuid]
(neo4j/exec-query! delete {:uuid uuid})) (neo4j/exec-query! delete {:uuid uuid}))
@ -171,8 +165,7 @@
(neo4j/defquery outgoing-links (neo4j/defquery outgoing-links
"MATCH (inst:instance {uuid:{uuid}}), "MATCH (inst:instance {uuid:{uuid}}),
(inst)<-[:link_from]-(link:link), (inst)-[link:link]->(target:instance),
(link)-[:link_to]->(target:instance),
(target)-[:of]->(schema:schema) (target)-[:of]->(schema:schema)
OPTIONAL MATCH OPTIONAL MATCH
(target)-[:tagged_with]->(tag:tag) (target)-[:tagged_with]->(tag:tag)
@ -183,8 +176,7 @@
(neo4j/defquery incoming-links (neo4j/defquery incoming-links
"MATCH (inst:instance {uuid:{uuid}}), "MATCH (inst:instance {uuid:{uuid}}),
(inst)<-[:link_to]-(link:link), (inst)<-[link:link]-(source:instance),
(link)-[:link_from]->(source:instance),
(source)-[:of]->(schema:schema) (source)-[:of]->(schema:schema)
OPTIONAL MATCH OPTIONAL MATCH
(source)-[:tagged_with]->(tag:tag) (source)-[:tagged_with]->(tag:tag)

@ -10,30 +10,28 @@
(neo4j/defquery create (neo4j/defquery create
"MATCH (i:instance {uuid:{from}}), "MATCH (i:instance {uuid:{from}}),
(u:user {uuid:{by}}),
(t:instance {uuid:{target}}) (t:instance {uuid:{target}})
CREATE CREATE (i)-[l:link]->(t)
(l:link {uuid:{uuid}})-[:created_by]->(u)
SET l.created_at = {created_at}, SET l.created_at = {created_at},
l.name = {name} l.name = {name},
CREATE l.created_by = {by},
(i)<-[:link_from]-(l)-[:link_to]->(t)") l.uuid = {uuid}")
(defn create! [link] (defn create! [{:keys [from name to by]}]
(let [tuples (map (fn [target-uuid] (let [tuples (map (fn [target-uuid]
[create [create
{:from (:from link) {:from from
:by (:by link) :by by
:target target-uuid :target target-uuid
:uuid (neo4j/uuid) :uuid (neo4j/uuid)
:created_at (neo4j/now-str) :created_at (neo4j/now-str)
:name (:name link)}]) :name name}])
(:to link))] to)]
(apply neo4j/exec-queries! tuples))) (apply neo4j/exec-queries! tuples)))
(neo4j/defquery delete (neo4j/defquery delete
"MATCH (l:link {uuid:{uuid}}), "MATCH (:instance)-[l:link]-(:instance)
(l)-[r]-() WHERE l.uuid = {uuid}
DELETE r, l") DELETE l")
(defn delete! [uuid] (defn delete! [uuid]
(neo4j/exec-query! delete (neo4j/exec-query! delete
{:uuid uuid})) {:uuid uuid}))

@ -36,11 +36,11 @@
"MATCH (coc:instance {uuid:{coc_uuid}}), "MATCH (coc:instance {uuid:{coc_uuid}}),
(rschema:schema {uuid:{roleschema_uuid}}), (rschema:schema {uuid:{roleschema_uuid}}),
(role:instance)-[:of]->(rschema), (role:instance)-[:of]->(rschema),
(coc)--(:link)--(role) (coc)-[:link]->(role)
OPTIONAL MATCH OPTIONAL MATCH
(lschema:schema {uuid:{levelschema_uuid}}), (lschema:schema {uuid:{levelschema_uuid}}),
(level:instance)-[:of]->(lschema), (level:instance)-[:of]->(lschema),
(role)--(:link)-->(level) (role)-[:link]->(level)
RETURN role, level") RETURN role, level")
(defn roles-with-levels-of-coc! [coc-key] (defn roles-with-levels-of-coc! [coc-key]
(->> (neo4j/exec-query! roles-with-levels-of-coc (->> (neo4j/exec-query! roles-with-levels-of-coc
@ -102,11 +102,11 @@
"MATCH (level:instance {uuid:{level_uuid}}), "MATCH (level:instance {uuid:{level_uuid}}),
(mschema:schema {uuid:{moduleschema_uuid}}), (mschema:schema {uuid:{moduleschema_uuid}}),
(module:instance)-[:of]->(mschema), (module:instance)-[:of]->(mschema),
(level)--(:link)--(module) (level)-[:link]->(module)
OPTIONAL MATCH OPTIONAL MATCH
(cschema:schema {uuid:{compschema_uuid}}), (cschema:schema {uuid:{compschema_uuid}}),
(comp:instance)-[:of]->(cschema), (comp:instance)-[:of]->(cschema),
(module)--(:link)--(comp) (module)-[:link]-(comp)
RETURN module, comp") RETURN module, comp")
(defn modules-with-comps! [level-uuid] (defn modules-with-comps! [level-uuid]
(->> (neo4j/exec-query! modules-with-comps (->> (neo4j/exec-query! modules-with-comps
@ -132,10 +132,10 @@
"MATCH (role:instance {uuid:{role_uuid}}), "MATCH (role:instance {uuid:{role_uuid}}),
(lschema:schema {uuid:{levelschema_uuid}}), (lschema:schema {uuid:{levelschema_uuid}}),
(level:instance)-[:of]->(lschema), (level:instance)-[:of]->(lschema),
(role)--(:link)--(level), (role)-[:link]->(level),
(mschema:schema {uuid:{moduleschema_uuid}}), (mschema:schema {uuid:{moduleschema_uuid}}),
(module:instance)-[:of]->(mschema), (module:instance)-[:of]->(mschema),
(level)--(:link)--(module) (level)-[:link]->(module)
RETURN module, level RETURN module, level
ORDER BY CASE ORDER BY CASE
WHEN level.name =~ \".*Foundation.*\" THEN WHEN level.name =~ \".*Foundation.*\" THEN
@ -165,7 +165,7 @@
"MATCH (module:instance {uuid:{uuid}}), "MATCH (module:instance {uuid:{uuid}}),
(cschema:schema {uuid:{compschema_uuid}}), (cschema:schema {uuid:{compschema_uuid}}),
(comp:instance)-[:of]->(cschema), (comp:instance)-[:of]->(cschema),
(module)--(:link)--(comp) (module)-[:link]->(comp)
RETURN comp RETURN comp
ORDER BY comp.name") ORDER BY comp.name")
(defn module! [uuid] (defn module! [uuid]

@ -19,7 +19,7 @@
"MATCH "MATCH
(source:instance)-[:of]->(schema:schema) (source:instance)-[:of]->(schema:schema)
OPTIONAL MATCH OPTIONAL MATCH
(source)<-[:link_from]-(link:link)-[:link_to]->(target:instance), (source)-[link:link]->(target:instance),
(target)-[:of]->(target_schema:schema) (target)-[:of]->(target_schema:schema)
RETURN source, schema, link, target, target_schema") RETURN source, schema, link, target, target_schema")
(defn all-instance-connections! [] (defn all-instance-connections! []

Loading…
Cancel
Save