Download the PHP package kerroldj/laravel-migrate-fresh-table without Composer

On this page you can find all versions of the php package kerroldj/laravel-migrate-fresh-table. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-migrate-fresh-table

Laravel Migrate Fresh Table

Latest Version on Packagist Total Downloads PHP Version Laravel

migrate:fresh-table, but scoped to one table (or a chosen, ordered set) instead of wiping the whole database.

Sometimes you need to rebuild a single table from scratch — reset a corrupted pivot, reapply a changed schema during development, or re-provision one table per tenant — without nuking everything else. This package does exactly that, safely:

Works across MySQL/MariaDB, PostgreSQL, SQLite and SQL Server on Laravel 12+ and PHP 8.2+.

Example — a --with-related --data-only --dry-run preview showing the foreign-key impact report and the resolved plan before anything is touched:


Installation

The service provider is auto-discovered. Publish the config file:

This creates config/migrate-fresh-table.php.


Quick start


How it works

For each target table the command:

  1. Inspects the live schema on the resolved connection to find every foreign key that touches the table — both the parents it references and the children that reference it.
  2. Prints a foreign-key impact report (always).
  3. Asks what to do (unless --force, --dry-run, or --pretend) — when dependents exist you can fresh only the target, or cascade to its dependents.
  4. Drops the target table(s) — children first — detaching any foreign keys that block the drop, then recreates them — parents first — using the selected strategy, and restores constraints. On PostgreSQL and SQL Server the whole drop/recreate runs in a transaction, so a failure rolls everything back instead of leaving the database half-dropped.
  5. Optionally re-seeds.

Drop/recreate ordering is dependency-safe: tables are dropped children-first and recreated parents-first. (With --tables=a,b,c you supply the order yourself — a is a parent of b is a parent of c.)

The foreign-key impact report & prompt


Freshing dependent tables (--with-related)

By default only the table(s) you name are freshed; tables that reference them keep their rows, which then point at records that no longer exist. Pass --with-related to also fresh every table that (transitively) references the target, in dependency-safe order:

The command resolves the full dependency closure, drops children-first and recreates parents-first, detaching and restoring foreign keys as needed — including circular references. On PostgreSQL and SQL Server the whole run is wrapped in a transaction, so any failure rolls everything back rather than leaving the database half-dropped.

A cascade can touch a lot of tables and wipes their data. Preview with --dry-run first and take a backup.

If one migration file creates several tables (e.g. users + password_reset_tokens + sessions), the command treats the migration as the unit: it drops those sibling tables together and re-runs the file once, so recreation never collides with a leftover table.


Clearing data only (--data-only)

Sometimes you don't want to rebuild structure at all — you just want to empty the tables. --data-only deletes rows instead of dropping/recreating, leaving every table, column, index and constraint exactly in place:

Rows are deleted children-first (so no foreign key is violated) inside a transaction. Because it never drops a table or re-runs a migration, --data-only works cleanly even on schemas with bundled migrations, circular foreign keys, or columns added by later ALTER migrations — cases where a structural drop/recreate is hard or impossible.

drop/recreate (default) --data-only
Table structure rebuilt from its migration left untouched
Re-runs migrations yes never
Clears data yes yes
Use when you need to rebuild the schema you just want to wipe the data

Strategies (customizable rebuild logic)

How a table is recreated after it's dropped is decided by a strategy. Two ship out of the box, and you can register your own.

1. migration strategy (default)

Re-runs the migration(s) that build the table. It auto-detects the owning migration by scanning your migration paths for Schema::create('<table>', …). If auto-detection isn't reliable for a table, add a manual override:

2. schema strategy

Recreates the table from an explicit Blueprint callback — handy when no single migration cleanly owns a table:

Select it per run or per table:

3. Your own strategy

Implement the contract and register it:

Custom strategies are resolved through the container, so you may type-hint dependencies. You can also swap the migration resolver itself by binding Kerroldj\MigrateFreshTable\Contracts\TableResolver.


Multi-connection & multitenancy

--all-connections iterates the static list plus anything returned by a dynamic tenant resolver:

The resolved connection is always used explicitly — the package never assumes the default connection — and the foreign-key report runs independently per connection.

PostgreSQL schema awareness

The search_path is set for the duration of the run and restored afterward, so the same table name in different schemas can be freshed independently.


Command reference


Events & hooks

Listen to lifecycle events (each carries connection, table, schema):

Event Fired
TableFreshing before a table is freshed
TableDropping / TableDropped around the drop
TableRecreating / TableRecreated around the recreate
TableFreshed after a table is freshed

Or use global callbacks, fired once per connection:


Safety notes


Testing

The suite defaults to an in-memory SQLite database. Because every developer has a different local setup, it also reads a .env from the package root — copy the example and point it at your database:

DB_CONNECTION accepts sqlite, mysql, mariadb, pgsql, or sqlsrv (postgres/postgresql and mssql/sqlserver work as aliases). Real environment variables override .env, so a one-off run is also fine:


License

The MIT License (MIT). See LICENSE.


All versions of laravel-migrate-fresh-table with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/console Version ^12.0|^13.0
illuminate/container Version ^12.0|^13.0
illuminate/contracts Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/filesystem Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kerroldj/laravel-migrate-fresh-table contains the following files

Loading the files please wait ...