---
title: "Publish-only migrations — Testing for Laravel | Roundly"
description: "Pin that a package publishes its migrations timestamped and never also auto-loads them — the duplicate-table bug as a test."
url: https://roundly-consulting.com/open-source/docs/testing-for-laravel/publish-only-migrations
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Testing for Laravel](https://roundly-consulting.com/open-source/docs/testing-for-laravel.md)

# Publish-only migrations

A package that publishes its migrations with a timestamp must not also auto-load them — doing both runs both copies and fails on a duplicate table, a bug that hit three of our packages. Two package-only expectations pin the publish-only policy against a service provider:

```php
expect($providerClass)->toNotAutoLoadMigrations(?string $migrationsDir = null);
expect($providerClass)->toPublishMigrationsTimestamped(string $tag, int $count);
```

```php
it('publishes its migrations instead of auto-loading them', function (): void {
    expect(PasskeysServiceProvider::class)->toNotAutoLoadMigrations();
    expect(PasskeysServiceProvider::class)->toPublishMigrationsTimestamped('passkeys-migrations', 3);
});
```

- toNotAutoLoadMigrations — the package’s migrations directory (resolved from the provider by reflection, or passed explicitly) must not be registered with the migrator.
- toPublishMigrationsTimestamped — the tag must publish exactly $count sources, each to a database\_path('migrations/<Y\_m\_d\_His>\_<name>.php') destination.

Both only make sense against a package service provider, so they are package-only — an app has no provider to point them at. The provider must be registered in the test’s app through packageProviders(): toNotAutoLoadMigrations fails on a provider that never booted, since it could not have registered anything and would pass for free. Static mirrors: Assert::doesNotAutoLoadMigrations() and Assert::publishesMigrationsTimestamped().

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/testing-for-laravel.md)
