2016-02-06 13:36:35 +00:00
|
|
|
{- This file is part of Vervis.
|
|
|
|
-
|
|
|
|
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
|
|
|
-
|
|
|
|
- ♡ Copying is an act of love. Please copy, reuse and share.
|
|
|
|
-
|
|
|
|
- The author(s) have dedicated all copyright and related and neighboring
|
|
|
|
- rights to this software to the public domain worldwide. This software is
|
|
|
|
- distributed without any warranty.
|
|
|
|
-
|
|
|
|
- You should have received a copy of the CC0 Public Domain Dedication along
|
|
|
|
- with this software. If not, see
|
|
|
|
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE EmptyDataDecls #-}
|
|
|
|
{-# LANGUAGE FlexibleContexts #-}
|
|
|
|
{-# LANGUAGE GADTs #-}
|
|
|
|
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
|
|
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
|
|
|
|
|
|
module Vervis.Persist
|
|
|
|
--(
|
|
|
|
--)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Control.Monad.IO.Class (liftIO)
|
2016-02-09 21:07:01 +00:00
|
|
|
import Data.Text (Text)
|
2016-02-11 20:58:40 +00:00
|
|
|
import Database.Esqueleto ((^.), (&&.), (==.))
|
2016-02-11 22:19:31 +00:00
|
|
|
import Database.Persist hiding ((==.))
|
2016-02-11 20:58:40 +00:00
|
|
|
import Database.Persist.Sqlite hiding ((==.))
|
2016-02-06 13:36:35 +00:00
|
|
|
import Database.Persist.TH
|
|
|
|
|
2016-02-11 20:58:40 +00:00
|
|
|
import qualified Database.Esqueleto as E
|
|
|
|
|
2016-02-06 13:36:35 +00:00
|
|
|
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
|
2016-02-09 21:07:01 +00:00
|
|
|
|
|
|
|
IrcChannel
|
|
|
|
network Text
|
|
|
|
name Text
|
2016-02-11 09:36:24 +00:00
|
|
|
|
|
|
|
Sharer
|
2016-02-09 21:07:01 +00:00
|
|
|
ident Text --CI
|
|
|
|
name Text Maybe
|
2016-02-11 09:36:24 +00:00
|
|
|
|
|
|
|
UniqueIdent ident
|
|
|
|
|
|
|
|
Person
|
|
|
|
ident SharerId
|
|
|
|
hash Text Maybe
|
|
|
|
email Text Maybe
|
|
|
|
|
|
|
|
UniquePersonIdent ident
|
|
|
|
|
2016-02-09 21:07:01 +00:00
|
|
|
Group
|
2016-02-11 09:36:24 +00:00
|
|
|
ident SharerId
|
|
|
|
|
|
|
|
UniqueGroupIdent ident
|
|
|
|
|
2016-02-09 21:07:01 +00:00
|
|
|
Project
|
2016-02-11 09:36:24 +00:00
|
|
|
ident Text --CI
|
|
|
|
sharer SharerId
|
|
|
|
name Text Maybe
|
|
|
|
desc Text Maybe
|
2016-02-09 21:07:01 +00:00
|
|
|
|
2016-02-11 09:36:24 +00:00
|
|
|
UniqueProject ident sharer
|
2016-02-09 21:07:01 +00:00
|
|
|
|
2016-02-11 09:36:24 +00:00
|
|
|
Repo
|
2016-02-11 20:58:40 +00:00
|
|
|
ident Text --CI
|
2016-02-09 21:07:01 +00:00
|
|
|
project ProjectId
|
2016-02-11 09:36:24 +00:00
|
|
|
irc IrcChannelId Maybe
|
|
|
|
ml Text Maybe
|
|
|
|
|
2016-02-11 20:58:40 +00:00
|
|
|
UniqueRepo ident project
|
2016-02-11 09:36:24 +00:00
|
|
|
|
|
|
|
PersonInGroup
|
|
|
|
person PersonId
|
|
|
|
group GroupId
|
|
|
|
|
|
|
|
UniquePersonInGroup person group
|
|
|
|
|
2016-02-06 13:36:35 +00:00
|
|
|
|]
|
2016-02-11 09:36:24 +00:00
|
|
|
|
2016-02-11 20:58:40 +00:00
|
|
|
mainViewQuery :: IO ()
|
|
|
|
mainViewQuery = runSqlite ":memory:" $ do
|
|
|
|
runMigration migrateAll
|
2016-02-11 22:19:31 +00:00
|
|
|
|
|
|
|
--create some sharers
|
|
|
|
cindyId <- insert $ Sharer "cindy" Nothing
|
|
|
|
bobId <- insert $ Sharer "bob" Nothing
|
|
|
|
aliceId <- insert $ Sharer "alice" Nothing
|
|
|
|
|
|
|
|
--create some projects
|
|
|
|
proj4Id <- insert $ Project "proj4" cindyId Nothing Nothing
|
|
|
|
proj2Id <- insert $ Project "proj2" aliceId Nothing Nothing
|
|
|
|
proj6Id <- insert $ Project "proj6" cindyId Nothing Nothing
|
|
|
|
proj3Id <- insert $ Project "proj3" bobId Nothing Nothing
|
|
|
|
proj5Id <- insert $ Project "proj5" cindyId Nothing Nothing
|
|
|
|
proj1Id <- insert $ Project "proj1" aliceId Nothing Nothing
|
|
|
|
|
|
|
|
--create some repos
|
|
|
|
insert_ $ Repo "repo8" proj5Id Nothing Nothing
|
|
|
|
insert_ $ Repo "repo1" proj1Id Nothing Nothing
|
|
|
|
insert_ $ Repo "repo6" proj4Id Nothing Nothing
|
|
|
|
insert_ $ Repo "repo3" proj3Id Nothing Nothing
|
|
|
|
insert_ $ Repo "repo4" proj3Id Nothing Nothing
|
|
|
|
insert_ $ Repo "repo10" proj6Id Nothing Nothing
|
|
|
|
insert_ $ Repo "repo5" proj4Id Nothing Nothing
|
|
|
|
insert_ $ Repo "repo7" proj5Id Nothing Nothing
|
|
|
|
insert_ $ Repo "repo2" proj2Id Nothing Nothing
|
|
|
|
insert_ $ Repo "repo9" proj5Id Nothing Nothing
|
|
|
|
insert_ $ Repo "repo11" proj6Id Nothing Nothing
|
|
|
|
insert_ $ Repo "repo12" proj6Id Nothing Nothing
|
|
|
|
|
2016-02-11 20:58:40 +00:00
|
|
|
rows <- E.select $ E.from $ \ (sharer, project, repo) -> do
|
|
|
|
E.where_ $
|
|
|
|
project ^. ProjectSharer ==. sharer ^. SharerId &&.
|
|
|
|
repo ^. RepoProject ==. project ^. ProjectId
|
|
|
|
E.orderBy
|
|
|
|
[ E.asc $ sharer ^. SharerIdent
|
|
|
|
, E.asc $ project ^. ProjectIdent
|
|
|
|
, E.asc $ repo ^. RepoIdent
|
|
|
|
]
|
|
|
|
return
|
|
|
|
( sharer ^. SharerIdent
|
|
|
|
, project ^. ProjectIdent
|
|
|
|
, repo ^. RepoIdent
|
|
|
|
)
|
|
|
|
liftIO $ mapM_ print rows
|