I'm writing an accounting app that uses MySQL, but I'm thinking about switching to PostgreSQL. My app has a meta
database that stores users, document types, a list of companies, etc. Each company (a book-keeping entity) has its own database. Each company's documents
table might look like this, along with other columns, of course:
documentID | createdByUserID | documentTypeID |
---|---|---|
1 | 1 | 1 |
2 | 1 | 1 |
3 | 2 | 5 |
4 | 1 | 3 |
createdByUserID
and documentTypeID
have foreign keys to meta.users.userID
and meta.documentTypes.documentTypeID
, respectively. MySQL doesn't mind foreign keys going to other databases. I want to have one users
table for my app (along with documentTypes
and other things), and I want to have each company's data in separate databases.
I see here that PostgresSQL doesn't handle cross-database foreign keys. How could I implement this sort of functionality in PostgreSQL? How is this sort of situation typically handled?