packages feed

persistent-audit 0.1.0.0 → 0.1.0.1

raw patch · 6 files changed

+68/−13 lines, 6 files

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for persistent-audit-script -## 0.0.0.0  -- YYYY-mm-dd+## 0.1.0.1  -- 2016-05-03 -* First version. Released on an unsuspecting world.+* Fix Haddock documentation.++## 0.1.0.0  -- 2016-05-02++* First version.
+ README.md view
@@ -0,0 +1,38 @@+# persistent-audit++This package includes an executable that takes a Persistent models (tables) file and returns a Persistent models file with audit models (tables) for each individual table in the original file. It can optionally return a file with an implementation of the `ToAudit` class for each pair of model and its audit model. The automatically produced audit model files and `ToAudit` instances are a best attempt and will not necessarily compile without editing. If you are interested in having different styles of Audit models supported or find any bugs, please inform me. It currently supports Persistent >= 2.2 && <= 2.5.++The executable can be run like this:++```+cabal run -- -m models -a auditModels+```++It can also parse Haskell files that have Persist model QuasiQuoters `[persistLowerCase||]` and `[persistUpperCase||]`:++```+cabal run -- -m Models.hs -a auditModels+```++And if you want the optional `ToAudit` implementation:++```+cabal run -- -m models -a auditModels -i ToAuditInstances.hs+```++It can also help you build Audit Models that will be used in a separate database (MongoDB to SQL or SQL to MongoDB) by converting MongoDB keys to Bytestring or SQL keys to Int64.++```+cabal run -- -m models -a auditModels -i ToAuditInstances.hs -c mongoDbToSql+cabal run -- -m models -a auditModels -i ToAuditInstances.hs -c sqlToMongoDb+```++You can also use this as a library for the following purporses:++ * To parse Persistent model files+ * To generate Audit Models from other Models+ * To generate `ToAudit` instances + * Use query functions from `Database.Persist.Audit.Queries`:`insertAndAudit`, `insertWhereAndAudit`,`deleteAndAudit`,`deleteWhereAndAudit`,`updateAndAudit`,`updateWhereAndAudit`+ +This package is originally based on this article [Maintaining a Log of Database Changes](http://www.4guysfromrolla.com/webtech/041807-1.shtml). Specifically, the first example: 'A Separate "History" Table for Each Table Being Audited'.+
persistent-audit.cabal view
@@ -1,5 +1,5 @@ name:                persistent-audit-version:             0.1.0.0+version:             0.1.0.1 synopsis:            Parses a Persist Model file and produces Audit Models description:         Simplify database audits license:             BSD3@@ -9,7 +9,7 @@ category:            Database, Yesod, Persistent stability:           Beta build-type:          Simple-extra-source-files:  ChangeLog.md+extra-source-files:  ChangeLog.md README.md cabal-version:       >=1.10  executable persistent-audit@@ -74,3 +74,8 @@                    , text                      , time                      , transformers+++source-repository head+  type:     git+  location: https://github.com/mchaver/persistent-audit
src/Database/Persist/Audit/Generator.hs view
@@ -26,9 +26,13 @@ -- | can be deleted without affecting the audit models. This is a work around in case the  -- | original models and the audit models are stored in different databases. -- | Persist cannot handle keys across SQL and Mongo.-data ForeignKeyType = OriginalKey   -- | Default setting. Link the ids as the original type with a "noreference" tag.-                    | MongoKeyInSQL -- | Store Mongo Key as a ByteString in SQL.-                    | SQLKeyInMongo -- | Store SQL Key as an Int64 in Mongo.+data ForeignKeyType +  -- | Default setting. Link the ids as the original type with a "noreference" tag.+  = OriginalKey  +  -- | Store Mongo Key as a ByteString in SQL.+  | MongoKeyInSQL +  -- | Store SQL Key as an Int64 in Mongo.   +  | SQLKeyInMongo   deriving (Eq,Read,Show)  -- | Settings that the author assumed would be most common.
src/Database/Persist/Audit/Parser/Types.hs view
@@ -5,7 +5,9 @@  import Data.Text (Text) -data MigrationOnlyAndSafeToRemoveOption = MigrationOnly | SafeToRemove deriving (Eq,Read,Show)+data MigrationOnlyAndSafeToRemoveOption = MigrationOnly +                                        | SafeToRemove +  deriving (Eq,Read,Show)  data EntityFieldLastItem = FieldDefault Text                          | FieldSqlRow  Text 
src/Database/Persist/Audit/Types.hs view
@@ -53,12 +53,14 @@   -- | Table rows can be strict or lazy-data Strictness = Strict -- | Persist Model types are strict without any notation -  | ExplicitStrict       -- | "!" can be used to reemphasize that a type is strict-  | Lazy                 -- | "~" means that a type is Laxy+data Strictness+  -- | Persist Model types are strict without any notation+  = Strict   +  -- | "!" can be used to reemphasize that a type is strict    +  | ExplicitStrict +  -- | "~" means that a type is Lazy+  | Lazy    deriving (Eq,Show,Read)-- -- | An entity data row's type. If '_isEntityFieldTypeList' is 'True' than this type is a list. data EntityFieldType = EntityFieldType {   _getEntityFieldTypeText   :: Text