Skip to content

Commit 8ffb2e2

Browse files
committed
Discover migrations from all namespaces when none is configured
1 parent e9533fe commit 8ffb2e2

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

docs/type-inference.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,16 @@ This extension types the virtual properties of `CodeIgniter\Entity\Entity` subcl
190190
layers the entity's `$dates` and `$casts` (resolving custom `$castHandlers` by reflecting their `get()` method)
191191
over the type of the backing database column. That column is found through the table of the model whose
192192
`$returnType` is the entity. Properties that are neither a date, a cast, nor a known column resolve to `mixed`.
193+
194+
> [!NOTE]
195+
> **Configuration:**
196+
>
197+
> The Model and Entity column types are derived from a live schema, built by running your migrations against a
198+
> throwaway SQLite database (this requires the `sqlite3` PHP extension). By default every registered namespace
199+
> is scanned (your app plus installed packages). To restrict the schema to a single namespace, set:
200+
>
201+
> ```yml
202+
> parameters:
203+
> codeigniter:
204+
> schemaNamespace: Acme\Blog
205+
> ```

src/Database/SchemaMigrator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ private function discoverMigrations(Connection $db, ?string $namespace): array
8989
{
9090
$runner = new MigrationRunner(config(Migrations::class), $db);
9191

92-
if ($namespace !== null) {
93-
$runner->setNamespace($namespace);
94-
}
92+
// A null namespace makes the runner scan every registered namespace (the app plus installed
93+
// packages), so a library analyzed on its own and an app's vendor migrations are both found.
94+
$runner->setNamespace($namespace);
9595

9696
return array_values(array_filter(
9797
$runner->findMigrations(),

tests/Database/SchemaMigratorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,17 @@ public function testRunsMigrationsResilientlyAndReturnsFingerprint(): void
7171
// A migration pinned to another database group is skipped.
7272
self::assertNull($schema->getTable('blog_groups'));
7373
}
74+
75+
public function testNullNamespaceScansEveryRegisteredNamespace(): void
76+
{
77+
$migrator = new SchemaMigrator();
78+
$fingerprint = $migrator->fingerprint($this->db, null);
79+
$migrator->migrate($this->db, null);
80+
81+
$schema = (new SchemaIntrospector())->introspect($this->db, $fingerprint);
82+
83+
// The fixture migrations live outside the app namespace, so finding them proves a null
84+
// namespace scans all registered namespaces rather than only `App\Database\Migrations`.
85+
self::assertNotNull($schema->getTable('blog_users'));
86+
}
7487
}

0 commit comments

Comments
 (0)