diff --git a/persistent/Database/Persist/EntityDef.hs b/persistent/Database/Persist/EntityDef.hs index 4e2fe93fc..92929a6b4 100644 --- a/persistent/Database/Persist/EntityDef.hs +++ b/persistent/Database/Persist/EntityDef.hs @@ -19,6 +19,7 @@ module Database.Persist.EntityDef , getEntityKeyFields , getEntityComments , getEntityExtra + , getEntitySchema , isEntitySum , entityPrimary , entitiesPrimary @@ -27,6 +28,7 @@ module Database.Persist.EntityDef , setEntityId , setEntityIdDef , setEntityDBName + , setEntitySchema , overEntityFields -- * Related Types , EntityIdDef(..) @@ -89,6 +91,9 @@ getEntityDBName = entityDB getEntityExtra :: EntityDef -> Map Text [[Text]] getEntityExtra = entityExtra +getEntitySchema :: EntityDef -> Maybe SchemaNameDB +getEntitySchema = entitySchema + -- | -- -- @since 2.13.0.0 @@ -195,6 +200,9 @@ getEntityKeyFields = entityKeyFields setEntityFields :: [FieldDef] -> EntityDef -> EntityDef setEntityFields fd ed = ed { entityFields = fd } +setEntitySchema :: Maybe SchemaNameDB -> EntityDef -> EntityDef +setEntitySchema sn ed = ed { entitySchema = sn } + -- | Perform a mapping function over all of the entity fields, as determined by -- 'getEntityFieldsDatabase'. -- diff --git a/persistent/Database/Persist/Names.hs b/persistent/Database/Persist/Names.hs index 5616e627c..dc8b07bb0 100644 --- a/persistent/Database/Persist/Names.hs +++ b/persistent/Database/Persist/Names.hs @@ -70,3 +70,9 @@ instance DatabaseName ConstraintNameDB where -- @since 2.12.0.0 newtype ConstraintNameHS = ConstraintNameHS { unConstraintNameHS :: Text } deriving (Show, Eq, Read, Ord, Lift) + +newtype SchemaNameDB = SchemaNameDB { unSchemaNameDB :: Text } + deriving (Show, Eq, Read, Ord, Lift) + +instance DatabaseName SchemaNameDB where + escapeWith f (SchemaNameDB n) = f n diff --git a/persistent/Database/Persist/Types/Base.hs b/persistent/Database/Persist/Types/Base.hs index f978674f6..e7f88d353 100644 --- a/persistent/Database/Persist/Types/Base.hs +++ b/persistent/Database/Persist/Types/Base.hs @@ -153,7 +153,7 @@ data EntityDef = EntityDef -- ^ Whether or not this entity represents a sum type in the database. , entityComments :: !(Maybe Text) -- ^ Optional comments on the entity. - , entitySchema :: !(Maybe Text) + , entitySchema :: !(Maybe SchemaNameDB) -- ^ The schema the entity belongs to. -- -- @since 2.10.0