Give each external module its own schema
- Comparing
- v1 to v2
- Current
- Read the document
Context
PostgreSQL is the panel's only database, as ADR-0023 decides. Its
schemas give a set of tables A
PostgreSQL schema is a namespace of its own for tables inside one database, and a schema can be created or dropped, with
everything with everything
in it, inside a transaction.
Bundled modulesmodule s ship inside the binary, per
ADR-0009, and are written, reviewed and upgraded
together. External modulesmodule s are installed, updated and removed one at a time, time through
Composer Composer, per ADR-0012, by authors who do not coordinate
not
coordinate with each other or with the panel. Two external modules, or an external module and the panel's ownpanel itself, can choose pick
the same
same table name, and removing an external module means finding everything it created.
Decision
We I will give each external module a PostgreSQL schema of its own, named from its
module identifier, and create its tables, and the objects that belong to them, in
that schema. Bundled modulesmodule s will share the default schema. An external module's schema
will be created inside the transaction that first migrates the module.
Alternatives
A schema for every module, bundled modules included. Each bundled module would have
get
a schema of its own as well. We I rejected this because bundled modules ship, upgrade and are reviewed together as one
binary, so separating them from each other buys nothing: a schema exists to separate what is installed separately.
Consequences
Easier:
The names of anAn external module'sown tablestable names will not conflict with another module's, or withthose ofthe bundledmodulesmodules'.- Removing an external module's own tables will
be a matter ofmean dropping its schema. Anything it changed outsideitsthat schema,suchsuch as a column it added to another module's table, will have to be reversed separately. - The bundled modules' tables will keep unqualified names in the default schema.
Harder:
- Bundled modules will have to avoid
conflictingtable names that conflict with eachotherother's by convention, checked in review. - Nothing in the database will record which bundled module owns which table in the default schema.
- A reference from one external module to another's table will have to name that module's schema.
Constrained:
- An external module's schema name will
be derivedcome from its module identifier,so theso the identifier will have to make a usable schema name: not the default schema'ss name, not one PostgreSQL reserves, such as a name beginningpg_, and no longer thanitsPostgreSQL's 63-byte limit on names.
Source adr/0024-external-module-schemas.md · commit 9444a99 · published