table method

String table(
  1. String name
)

The table a model of this module's actually reads and writes.

Shared modules use the name the model declared, because that is what the parent's migration created. A schema-isolated module's tables carry its id, so a module with an Order model mounted into an application that also has orders reads its own rows rather than somebody else's -- which is what it did before, silently, because both queried orders.

A prefix rather than a real database schema: SQLite is the zero-config local default and has no schemas, so a schema would mean two naming rules that have to agree, and the day they disagree is the day the migration writes one table and the query reads another.

Implementation

String table(String name) {
  switch (dataMode) {
    case DVModuleDataMode.shared:
    case DVModuleDataMode.databaseIsolated:
      // Nothing to disambiguate from in either case: the parent's
      // migration made this table, or the module has the database to
      // itself. Prefixing an isolated database would also make the same
      // module read different tables standing alone and mounted.
      return name;
    case DVModuleDataMode.schemaIsolated:
      if (!_identifier.hasMatch(id)) {
        throw ArgumentError.value(
          id,
          'id',
          'A schema-isolated module\'s id becomes part of a table name, so '
              'it has to be a plain SQL identifier. Rename the module, or '
              'give it data mode database-isolated.',
        );
      }
      return '${id}_$name';
    case DVModuleDataMode.remote:
      throw StateError(
        'Module "$id" is mounted with data mode remote, so "$name" is not '
        'a table in this application. Its own deployment owns that data; '
        "ask it through the module's API rather than the database.",
      );
  }
}