Commit 898dca82 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[DB.Schema.Node] hash_id column added to Node only

parent a891c1f5
...@@ -19,7 +19,6 @@ import Data.Map (Map) ...@@ -19,7 +19,6 @@ import Data.Map (Map)
import Data.Maybe (Maybe) import Data.Maybe (Maybe)
-- import Control.Applicative -- import Control.Applicative
import Gargantext.Core.Text (HasText(..)) import Gargantext.Core.Text (HasText(..))
import Gargantext.Core.Types.Main (HashId)
import Gargantext.Database.Admin.Types.Hyperdata import Gargantext.Database.Admin.Types.Hyperdata
import Gargantext.Database.Admin.Types.Node import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Schema.Ngrams (Ngrams, NgramsType) import Gargantext.Database.Schema.Ngrams (Ngrams, NgramsType)
......
...@@ -49,8 +49,6 @@ instance ToSchema NodeTree where ...@@ -49,8 +49,6 @@ instance ToSchema NodeTree where
--data Classification = Favorites | MyClassifcation --data Classification = Favorites | MyClassifcation
type HashId = Text
type TypeId = Int type TypeId = Int
-- TODO multiple ListType declaration, remove it -- TODO multiple ListType declaration, remove it
data ListType = StopTerm | CandidateTerm | MapTerm data ListType = StopTerm | CandidateTerm | MapTerm
......
...@@ -49,7 +49,7 @@ toMaps :: Hyperdata a ...@@ -49,7 +49,7 @@ toMaps :: Hyperdata a
-> Map (NgramsT Ngrams) (Map NodeId Int) -> Map (NgramsT Ngrams) (Map NodeId Int)
toMaps fun ns = mapNodeIdNgrams $ documentIdWithNgrams fun ns' toMaps fun ns = mapNodeIdNgrams $ documentIdWithNgrams fun ns'
where where
ns' = map (\(Node nId _ _ _ _ _ json) -> DocumentWithId nId json) ns ns' = map (\(Node nId _ _ _ _ _ _ json) -> DocumentWithId nId json) ns
mapNodeIdNgrams :: Hyperdata a mapNodeIdNgrams :: Hyperdata a
=> [DocumentIdWithNgrams a] => [DocumentIdWithNgrams a]
......
...@@ -51,10 +51,10 @@ import Gargantext.Prelude ...@@ -51,10 +51,10 @@ import Gargantext.Prelude
type UserId = Int type UserId = Int
type MasterUserId = UserId type MasterUserId = UserId
type HashId = Text
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | NodePoly indicates that Node has a Polymorphism Type -- | NodePoly indicates that Node has a Polymorphism Type
type Node json = NodePoly NodeId NodeTypeId UserId (Maybe ParentId) NodeName UTCTime json type Node json = NodePoly NodeId HashId NodeTypeId UserId (Maybe ParentId) NodeName UTCTime json
-- | NodeSearch (queries) -- | NodeSearch (queries)
-- type NodeSearch json = NodePolySearch NodeId NodeTypeId UserId (Maybe ParentId) NodeName UTCTime json (Maybe TSVector) -- type NodeSearch json = NodePolySearch NodeId NodeTypeId UserId (Maybe ParentId) NodeName UTCTime json (Maybe TSVector)
...@@ -62,7 +62,7 @@ type Node json = NodePoly NodeId NodeTypeId UserId (Maybe ParentId) NodeName U ...@@ -62,7 +62,7 @@ type Node json = NodePoly NodeId NodeTypeId UserId (Maybe ParentId) NodeName U
------------------------------------------------------------------------ ------------------------------------------------------------------------
instance (Typeable hyperdata, ToSchema hyperdata) => instance (Typeable hyperdata, ToSchema hyperdata) =>
ToSchema (NodePoly NodeId NodeTypeId ToSchema (NodePoly NodeId HashId NodeTypeId
(Maybe UserId) (Maybe UserId)
ParentId NodeName ParentId NodeName
UTCTime hyperdata UTCTime hyperdata
...@@ -70,7 +70,7 @@ instance (Typeable hyperdata, ToSchema hyperdata) => ...@@ -70,7 +70,7 @@ instance (Typeable hyperdata, ToSchema hyperdata) =>
declareNamedSchema = wellNamedSchema "_node_" declareNamedSchema = wellNamedSchema "_node_"
instance (Typeable hyperdata, ToSchema hyperdata) => instance (Typeable hyperdata, ToSchema hyperdata) =>
ToSchema (NodePoly NodeId NodeTypeId ToSchema (NodePoly NodeId HashId NodeTypeId
UserId UserId
(Maybe ParentId) NodeName (Maybe ParentId) NodeName
UTCTime hyperdata UTCTime hyperdata
...@@ -95,15 +95,16 @@ instance (Typeable hyperdata, ToSchema hyperdata) => ...@@ -95,15 +95,16 @@ instance (Typeable hyperdata, ToSchema hyperdata) =>
instance (Arbitrary hyperdata instance (Arbitrary hyperdata
,Arbitrary nodeId ,Arbitrary nodeId
,Arbitrary hashId
,Arbitrary nodeTypeId ,Arbitrary nodeTypeId
,Arbitrary userId ,Arbitrary userId
,Arbitrary nodeParentId ,Arbitrary nodeParentId
) => Arbitrary (NodePoly nodeId nodeTypeId userId nodeParentId ) => Arbitrary (NodePoly nodeId hashId nodeTypeId userId nodeParentId
NodeName UTCTime hyperdata) where NodeName UTCTime hyperdata) where
--arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (arbitrary) (Just "") --arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (arbitrary) (Just "")
arbitrary = Node <$> arbitrary <*> arbitrary <*> arbitrary arbitrary = Node <$> arbitrary <*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary <*> arbitrary
instance (Arbitrary hyperdata instance (Arbitrary hyperdata
,Arbitrary nodeId ,Arbitrary nodeId
......
...@@ -73,7 +73,7 @@ selectNodesWith parentId maybeNodeType maybeOffset maybeLimit = ...@@ -73,7 +73,7 @@ selectNodesWith parentId maybeNodeType maybeOffset maybeLimit =
selectNodesWith' :: ParentId -> Maybe NodeType -> Query NodeRead selectNodesWith' :: ParentId -> Maybe NodeType -> Query NodeRead
selectNodesWith' parentId maybeNodeType = proc () -> do selectNodesWith' parentId maybeNodeType = proc () -> do
node <- (proc () -> do node <- (proc () -> do
row@(Node _ typeId _ parentId' _ _ _) <- queryNodeTable -< () row@(Node _ _ typeId _ parentId' _ _ _) <- queryNodeTable -< ()
restrict -< parentId' .== (pgNodeId parentId) restrict -< parentId' .== (pgNodeId parentId)
let typeId' = maybe 0 nodeTypeId maybeNodeType let typeId' = maybe 0 nodeTypeId maybeNodeType
...@@ -87,12 +87,12 @@ selectNodesWith' parentId maybeNodeType = proc () -> do ...@@ -87,12 +87,12 @@ selectNodesWith' parentId maybeNodeType = proc () -> do
deleteNode :: NodeId -> Cmd err Int deleteNode :: NodeId -> Cmd err Int
deleteNode n = mkCmd $ \conn -> deleteNode n = mkCmd $ \conn ->
fromIntegral <$> runDelete conn nodeTable fromIntegral <$> runDelete conn nodeTable
(\(Node n_id _ _ _ _ _ _) -> n_id .== pgNodeId n) (\(Node n_id _ _ _ _ _ _ _) -> n_id .== pgNodeId n)
deleteNodes :: [NodeId] -> Cmd err Int deleteNodes :: [NodeId] -> Cmd err Int
deleteNodes ns = mkCmd $ \conn -> deleteNodes ns = mkCmd $ \conn ->
fromIntegral <$> runDelete conn nodeTable fromIntegral <$> runDelete conn nodeTable
(\(Node n_id _ _ _ _ _ _) -> in_ ((map pgNodeId ns)) n_id) (\(Node n_id _ _ _ _ _ _ _) -> in_ ((map pgNodeId ns)) n_id)
-- TODO: NodeType should match with `a' -- TODO: NodeType should match with `a'
getNodesWith :: JSONB a => NodeId -> proxy a -> Maybe NodeType getNodesWith :: JSONB a => NodeId -> proxy a -> Maybe NodeType
...@@ -153,13 +153,13 @@ getCorporaWithParentId n = runOpaQuery $ selectNodesWith' n (Just NodeCorpus) ...@@ -153,13 +153,13 @@ getCorporaWithParentId n = runOpaQuery $ selectNodesWith' n (Just NodeCorpus)
------------------------------------------------------------------------ ------------------------------------------------------------------------
selectNodesWithParentID :: NodeId -> Query NodeRead selectNodesWithParentID :: NodeId -> Query NodeRead
selectNodesWithParentID n = proc () -> do selectNodesWithParentID n = proc () -> do
row@(Node _ _ _ parent_id _ _ _) <- queryNodeTable -< () row@(Node _ _ _ _ parent_id _ _ _) <- queryNodeTable -< ()
restrict -< parent_id .== (pgNodeId n) restrict -< parent_id .== (pgNodeId n)
returnA -< row returnA -< row
selectNodesWithType :: Column PGInt4 -> Query NodeRead selectNodesWithType :: Column PGInt4 -> Query NodeRead
selectNodesWithType type_id = proc () -> do selectNodesWithType type_id = proc () -> do
row@(Node _ tn _ _ _ _ _) <- queryNodeTable -< () row@(Node _ _ tn _ _ _ _ _) <- queryNodeTable -< ()
restrict -< tn .== type_id restrict -< tn .== type_id
returnA -< row returnA -< row
...@@ -205,7 +205,7 @@ node :: (ToJSON a, Hyperdata a) ...@@ -205,7 +205,7 @@ node :: (ToJSON a, Hyperdata a)
-> UserId -> UserId
-> NodeWrite -> NodeWrite
node nodeType name hyperData parentId userId = node nodeType name hyperData parentId userId =
Node Nothing Node Nothing Nothing
(pgInt4 typeId) (pgInt4 typeId)
(pgInt4 userId) (pgInt4 userId)
(pgNodeId <$> parentId) (pgNodeId <$> parentId)
...@@ -238,7 +238,7 @@ insertNodes' ns = mkCmd $ \conn -> runInsert_ conn ...@@ -238,7 +238,7 @@ insertNodes' ns = mkCmd $ \conn -> runInsert_ conn
insertNodesR :: [NodeWrite] -> Cmd err [NodeId] insertNodesR :: [NodeWrite] -> Cmd err [NodeId]
insertNodesR ns = mkCmd $ \conn -> insertNodesR ns = mkCmd $ \conn ->
runInsert_ conn (Insert nodeTable ns (rReturning (\(Node i _ _ _ _ _ _) -> i)) Nothing) runInsert_ conn (Insert nodeTable ns (rReturning (\(Node i _ _ _ _ _ _ _) -> i)) Nothing)
insertNodesWithParent :: Maybe ParentId -> [NodeWrite] -> Cmd err Int64 insertNodesWithParent :: Maybe ParentId -> [NodeWrite] -> Cmd err Int64
insertNodesWithParent pid ns = insertNodes (set node_parentId (pgNodeId <$> pid) <$> ns) insertNodesWithParent pid ns = insertNodes (set node_parentId (pgNodeId <$> pid) <$> ns)
...@@ -251,7 +251,7 @@ insertNodesWithParentR pid ns = insertNodesR (set node_parentId (pgNodeId <$> pi ...@@ -251,7 +251,7 @@ insertNodesWithParentR pid ns = insertNodesR (set node_parentId (pgNodeId <$> pi
-- needs a Temporary type between Node' and NodeWriteT -- needs a Temporary type between Node' and NodeWriteT
node2table :: UserId -> Maybe ParentId -> Node' -> NodeWrite node2table :: UserId -> Maybe ParentId -> Node' -> NodeWrite
node2table uid pid (Node' nt txt v []) = Node Nothing (pgInt4 $ nodeTypeId nt) (pgInt4 uid) (fmap pgNodeId pid) (pgStrictText txt) Nothing (pgStrictJSONB $ cs $ encode v) node2table uid pid (Node' nt txt v []) = Node Nothing Nothing (pgInt4 $ nodeTypeId nt) (pgInt4 uid) (fmap pgNodeId pid) (pgStrictText txt) Nothing (pgStrictJSONB $ cs $ encode v)
node2table _ _ (Node' _ _ _ _) = panic "node2table: should not happen, Tree insert not implemented yet" node2table _ _ (Node' _ _ _ _) = panic "node2table: should not happen, Tree insert not implemented yet"
......
...@@ -72,7 +72,7 @@ selectChildren :: ParentId ...@@ -72,7 +72,7 @@ selectChildren :: ParentId
-> Maybe NodeType -> Maybe NodeType
-> Query NodeRead -> Query NodeRead
selectChildren parentId maybeNodeType = proc () -> do selectChildren parentId maybeNodeType = proc () -> do
row@(Node nId typeName _ parent_id _ _ _) <- queryNodeTable -< () row@(Node nId _ typeName _ parent_id _ _ _) <- queryNodeTable -< ()
(NodeNode n1id n2id _ _) <- queryNodeNodeTable -< () (NodeNode n1id n2id _ _) <- queryNodeNodeTable -< ()
let nodeType = maybe 0 nodeTypeId maybeNodeType let nodeType = maybe 0 nodeTypeId maybeNodeType
......
...@@ -30,8 +30,8 @@ updateHyperdata i h = mkCmd $ \c -> runUpdate_ c (updateHyperdataQuery i h) ...@@ -30,8 +30,8 @@ updateHyperdata i h = mkCmd $ \c -> runUpdate_ c (updateHyperdataQuery i h)
updateHyperdataQuery :: ToJSON a => NodeId -> a -> Update Int64 updateHyperdataQuery :: ToJSON a => NodeId -> a -> Update Int64
updateHyperdataQuery i h = Update updateHyperdataQuery i h = Update
{ uTable = nodeTable { uTable = nodeTable
, uUpdateWith = updateEasy (\ (Node _ni _nt _nu _np _nn _nd _h) , uUpdateWith = updateEasy (\ (Node _ni _nh _nt _nu _np _nn _nd _h)
-> Node _ni _nt _nu _np _nn _nd h' -> Node _ni _nh _nt _nu _np _nn _nd h'
) )
, uWhere = (\row -> _node_id row .== pgNodeId i ) , uWhere = (\row -> _node_id row .== pgNodeId i )
, uReturning = rCount , uReturning = rCount
......
...@@ -26,6 +26,7 @@ import Prelude hiding (null, id, map, sum) ...@@ -26,6 +26,7 @@ import Prelude hiding (null, id, map, sum)
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- Main polymorphic Node definition -- Main polymorphic Node definition
data NodePoly id data NodePoly id
hash_id
typename typename
userId userId
parentId parentId
...@@ -33,6 +34,7 @@ data NodePoly id ...@@ -33,6 +34,7 @@ data NodePoly id
date date
hyperdata = hyperdata =
Node { _node_id :: !id Node { _node_id :: !id
, _node_hash_id :: !hash_id
, _node_typename :: !typename , _node_typename :: !typename
, _node_userId :: !userId , _node_userId :: !userId
...@@ -54,6 +56,7 @@ $(makeLensesWith abbreviatedFields ''NodePoly) ...@@ -54,6 +56,7 @@ $(makeLensesWith abbreviatedFields ''NodePoly)
nodeTable :: Table NodeWrite NodeRead nodeTable :: Table NodeWrite NodeRead
nodeTable = Table "nodes" (pNode Node { _node_id = optional "id" nodeTable = Table "nodes" (pNode Node { _node_id = optional "id"
, _node_hash_id = optional "hash_id"
, _node_typename = required "typename" , _node_typename = required "typename"
, _node_userId = required "user_id" , _node_userId = required "user_id"
...@@ -70,6 +73,7 @@ queryNodeTable :: Query NodeRead ...@@ -70,6 +73,7 @@ queryNodeTable :: Query NodeRead
queryNodeTable = queryTable nodeTable queryNodeTable = queryTable nodeTable
------------------------------------------------------------------------ ------------------------------------------------------------------------
type NodeWrite = NodePoly (Maybe (Column PGInt4) ) type NodeWrite = NodePoly (Maybe (Column PGInt4) )
(Maybe (Column PGText) )
(Column PGInt4) (Column PGInt4)
(Column PGInt4) (Column PGInt4)
(Maybe (Column PGInt4) ) (Maybe (Column PGInt4) )
...@@ -78,6 +82,7 @@ type NodeWrite = NodePoly (Maybe (Column PGInt4) ) ...@@ -78,6 +82,7 @@ type NodeWrite = NodePoly (Maybe (Column PGInt4) )
(Column PGJsonb) (Column PGJsonb)
type NodeRead = NodePoly (Column PGInt4 ) type NodeRead = NodePoly (Column PGInt4 )
(Column PGText )
(Column PGInt4 ) (Column PGInt4 )
(Column PGInt4 ) (Column PGInt4 )
(Column PGInt4 ) (Column PGInt4 )
...@@ -86,6 +91,7 @@ type NodeRead = NodePoly (Column PGInt4 ) ...@@ -86,6 +91,7 @@ type NodeRead = NodePoly (Column PGInt4 )
(Column PGJsonb ) (Column PGJsonb )
type NodeReadNull = NodePoly (Column (Nullable PGInt4)) type NodeReadNull = NodePoly (Column (Nullable PGInt4))
(Column (Nullable PGText))
(Column (Nullable PGInt4)) (Column (Nullable PGInt4))
(Column (Nullable PGInt4)) (Column (Nullable PGInt4))
(Column (Nullable PGInt4)) (Column (Nullable PGInt4))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment