[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationExternal databases

External databases

Browse the databases a project connects to but does not own, next to its own database, and write to one only when the project allows it.

A project can read a database it does not own, such as a client's MongoDB database. The provider module, @antelopejs/mongodb, reads and writes it in external mode, and a tables module declares the tables it maps. The database console lists each such database next to the project's own, and reads and edits its rows through the same pages.

Connect a database

The console reaches an external database through two connections on its own module entry, both with the database's id: @antelopejs/interface-database-catalog describes it, and @antelopejs/interface-database reads and writes it. A database the project declares with only one of the two, or only in externalConnections, is listed in the switcher as Not registered and cannot be picked: its tooltip names the missing connection. Add it to the entry, or let the assistant repair the database connections.

The first @antelopejs/interface-database entry pins the binding a plain import reaches, so it must name the project's own database. The entries after it are the named connections.

antelope.config.ts ts
"dms-database": {
  source: { type: "package", package: "@antelopejs/dms-database", version: ">=0.7.0 <0.8.0" },
  importOverrides: [
    { interface: "@antelopejs/interface-database", source: "mongodb" },
    { interface: "@antelopejs/interface-database", source: "mongodb-erp", id: "erp" },
    { interface: "@antelopejs/interface-database-catalog", source: "mongodb-erp", id: "erp" },
  ],
  config: {
    externalConnections: {
      erp: { access: "read" },
    },
  },
},

Here mongodb is the project's own database and mongodb-erp the provider of the external one. The connection id, erp, is the one the connect flow gives the database's other consumers. The tables the console reads are those the tables module declares on the same provider. The connection exists once the project restarts.

Pick a database

The switcher at the top of the Database module's sidebar lists the project's database, then each external one with its engine and a Read only or Read & write badge, and a check mark on the one picked. Every page of the module shows the database picked there. The choice is kept per user.

FeatureOwn databaseExternal database
Overview, Schemas, Diagram, Data browseryesyes
Rows: edityesonly when its access is read-write
Query console, instances, a row's referencesyesno: the pages stay in the sidebar, locked
Migrations, schema edits, indexesnono

Large and slow databases

A customer's table can be large. The console sends a search and each column filter to the database as part of the query, so the database tests the rows and the console receives only the page. On an external database:

  • A search or a column filter runs in the database's query, on every row of the table. A match far down a large table is found.
  • The footer's row count is the database's exact count of the rows that match, with or without a filter.
  • A page, or the row count of a table, that takes more than 10 seconds answers 504 with "The external database did not answer in time: narrow the search or try again". The 504 frees the page; it does not stop the query in the database. Set statementTimeoutMs on the external database's provider (@antelopejs/mongodb sends it as maxTimeMS) so the database stops a search that runs too long, such as a contains search over a large table. Keep it above 10,000: a lower value stops the query before the console answers, and the page fails with the driver's error instead of the 504.
  • The switcher waits at most 3 seconds for each database's catalog. A database that does not answer in time is still listed, without its engine, and its write access shows as not checked. The others answer as usual.
  • When a database's catalog refuses or does not answer in time, the message names the database and says which of the two happened. Its driver's message, which can name the host, the port and the account, stays in the server log.

Only MongoDB external databases are tested. Other providers implement the same interfaces, but no test covers them.

Allow changes

Each external database has one access, set in config.externalConnections.<id>.access on the dms-database entry:

  • "read", the default when the entry is absent: the console reads the database and refuses every edit with 403.
  • "read-write": the console edits rows through the Data browser.

The project files are the only place the access is kept, so it is the same in every environment and versioned with the project.

In development, the bar at the top of the Data browser changes it, and the console writes it to antelope.config.ts through the DMS's configuration writer (@antelopejs/interface-dms-builder). Turning on Read & write asks for confirmation once: the database is the customer's live database, and the DMS cannot undo the changes made to it. Going back to Read only asks nothing. Outside development the bar shows the access and offers no toggle.

"read-write" needs an account that can write. The console reads what the connection's account may do from its catalog: the account can write when any relation the catalog lists grants it insert, update or delete. When it cannot, the toggle is locked with "This account can only read. Use an account with write access to allow changes." When the catalog does not answer, outside development for example, it is locked with "This account's write access could not be checked."

An edit names the database its page was opened on. When the user picked another database in another tab since, the edit is refused with 409 and the page asks to be reloaded.

API

Every route answers the platform owner only. <id> is own for the project's own database, or a connection id.

RouteAnswers
GET /api/database/connectionsselected, the database the user browses; accessEditable, whether the access may change here; and connections: for each database, id, kind (own or external), label, engine, access, canWrite (true, false, or null when the catalog does not answer), and the unsupported features
PUT /api/database/connections/selectedpicks the database every page of the module reads, with { "connection": "<id>" }
PUT /api/database/connections/<id>/accesswrites the access with { "access": "read" } or { "access": "read-write" }. Development only, 403 elsewhere; 409 for "read-write" when canWrite is not true; 503 when the configuration writer does not answer
GET /api/database/connections/<id>/relationsthe relations the catalog lists
GET /api/database/connections/<id>/relations/<schema>.<name>one relation in full: columns, indexes, references

Every refusal of the module's routes, these and the others, answers { "message", "params", "severity" }: message is a translation key the dashboard shows in the user's language, such as $dms_database.connections.unknown, not an English sentence, and params holds the values the sentence names, such as params.connection for the database. The query console's run and dry-run diagnostics are the exception: the console shows them as they are, beside the database's own error.

The Data browser's routes (/api/database/browse/*) read the selected database. PUT /api/database/browse/edit also takes connection=<id>, the database the edit was made on, and answers 409 when it is no longer the selected one.

A relation <schema>.<name> of the catalog is table <name> of schema <schema>. An external database's tables have no instances, so a request on one names no filter_instance.