Skip to content

Namespaces in models #1454

@arrowd

Description

@arrowd

Many ERP systems allow its user to write applications on top of them. Applications may store their stuff in the system's database, which means that each application has its own set of entities. If we're to write such a system using Persistent, how can we handle a case when two unrelated applications create entities with same names?

In other words, if we have two Haskell modules M1 and M2, both of which containing something like

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
User
   name Text
|]

then running

import qualified M1
import qualified M2

insert $ M1.User "User1"
insert $ M2.User "User2"

will place the data into the same table.

Would it make sense to implement some sort of namespacing in Persistent? If yes, what approach should be taken?
I'm thinking about taking a fully qualified module name (like, packagename-1.2.3.Database.Persist.Foo), computing a hash based on it and appending it to the table name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions