From e0a7d2737e6b6bfc92588925b5f32b8a266e46d1 Mon Sep 17 00:00:00 2001 From: Curran McConnell Date: Tue, 1 Oct 2024 16:22:38 -0400 Subject: [PATCH 1/3] create newtype for schema name --- persistent/Database/Persist/Names.hs | 3 +++ persistent/Database/Persist/Types/Base.hs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/persistent/Database/Persist/Names.hs b/persistent/Database/Persist/Names.hs index 5616e627c..b75f81301 100644 --- a/persistent/Database/Persist/Names.hs +++ b/persistent/Database/Persist/Names.hs @@ -70,3 +70,6 @@ instance DatabaseName ConstraintNameDB where -- @since 2.12.0.0 newtype ConstraintNameHS = ConstraintNameHS { unConstraintNameHS :: Text } deriving (Show, Eq, Read, Ord, Lift) + +newtype SchemaName = SchemaName { unSchemaName :: Text } + deriving (Show, Eq, Read, Ord, Lift) diff --git a/persistent/Database/Persist/Types/Base.hs b/persistent/Database/Persist/Types/Base.hs index f978674f6..0dba9ea35 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 SchemaName) -- ^ The schema the entity belongs to. -- -- @since 2.10.0 From ea96742268b55ecdb35fc2b179317fd6b2ca1ae2 Mon Sep 17 00:00:00 2001 From: Curran McConnell Date: Tue, 1 Oct 2024 16:36:13 -0400 Subject: [PATCH 2/3] add setters and getters --- persistent/Database/Persist/EntityDef.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/persistent/Database/Persist/EntityDef.hs b/persistent/Database/Persist/EntityDef.hs index 4e2fe93fc..d939c0b23 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 SchemaName +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 SchemaName -> EntityDef -> EntityDef +setEntitySchema sn ed = ed { entitySchema = sn } + -- | Perform a mapping function over all of the entity fields, as determined by -- 'getEntityFieldsDatabase'. -- From 27e4ee7be27c9f1f1f81bcd7f54a6764b85a57f8 Mon Sep 17 00:00:00 2001 From: Curran McConnell Date: Tue, 1 Oct 2024 16:46:18 -0400 Subject: [PATCH 3/3] suffix with DB --- persistent/Database/Persist/EntityDef.hs | 6 ++++++ persistent/Database/Persist/Names.hs | 5 ++++- persistent/Database/Persist/Types/Base.hs | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/persistent/Database/Persist/EntityDef.hs b/persistent/Database/Persist/EntityDef.hs index 4e2fe93fc..4bf80e7e9 100644 --- a/persistent/Database/Persist/EntityDef.hs +++ b/persistent/Database/Persist/EntityDef.hs @@ -89,6 +89,9 @@ getEntityDBName = entityDB getEntityExtra :: EntityDef -> Map Text [[Text]] getEntityExtra = entityExtra +getEntitySchema :: EntityDef -> Maybe SchemaNameDB +getEntitySchema = entitySchema + -- | -- -- @since 2.13.0.0 @@ -195,6 +198,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 b75f81301..dc8b07bb0 100644 --- a/persistent/Database/Persist/Names.hs +++ b/persistent/Database/Persist/Names.hs @@ -71,5 +71,8 @@ instance DatabaseName ConstraintNameDB where newtype ConstraintNameHS = ConstraintNameHS { unConstraintNameHS :: Text } deriving (Show, Eq, Read, Ord, Lift) -newtype SchemaName = SchemaName { unSchemaName :: Text } +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 0dba9ea35..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 SchemaName) + , entitySchema :: !(Maybe SchemaNameDB) -- ^ The schema the entity belongs to. -- -- @since 2.10.0