Download the PHP package aaronheath/laravel-model-copy without Composer

On this page you can find all versions of the php package aaronheath/laravel-model-copy. 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-model-copy

Laravel Model Copy

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Laravel model copy helps you copy, move records from one database table to another. This solution is designed for moving un-needed records to another table in a safe manner which can then be backed-up and, if need, truncated.

The package is also able to assist in performing batch model deletions over using the same conditions as are made available when copying models.

Installation

You can install the package via composer:

Usage

The package can be used in one of three ways:

Copy or move individual model

Copying an individual model is as easy as...

Copying an individual model and deleting the original record is a easy as including ->deleteOriginal().

We may not want to copy or move the model if it's after a certain time. This can be achieved by including ->processBefore(now()->addHour())

Batch copy or move many models from a query

Most likely you won't be wanting to move just one record, this is where batch copying or moving comes into play.

Here's a simple batch copy which will make a copy of all model ExampleA records where they were handled_at more than three years ago.

If we want to instead delete the original model, all we need to do is include ->deleteOriginal().

If we want limit on how many records we want to copy / move in one go, we can use ->limit(1000).

By default queries will be chunked into 100 record batches. If you wish to use your own chunking value, this can be achieved by ->chunk(500).

To use a custom (not 'id') column to chunk by use ->chunkColumn().

Up until now, all actions happen in one syncronious stream. In real world situation it's better to process individual copy / move model actions by pushing them to the queue. This can be achieved by including ->copyModelsAsJobs().

If a queue besides the default wants to be used, then include ->onQueue('queue-name').

When moving large sets of data it may take quite some time. In these cases you may want to group your moving batches into blocks of time. Let's say we want to run the script nightly at 23:00 and want to make sure we stop moving copying models at 05:00 the next day. This can be achieved by using ->processBefore(now()->addDay()->setTime(5, 0, 0).

We may also want to limit how many records are copied / moved in any given minute. To do this a rate per minute (rpm) can be defined. If we're wanting to ensure that we only copy 20 records per minute then we can use ->rpm(20). Using this feature requires ->copyModelsAsJobs() to be used.

Real world example

Let's say we want to move all records that were handled_at over three years ago to another table. We want to only have the run until 06:00 the next day. We also want to limit load on the database, so we'll only move 100 records per minute. To achieve this we'd use the following...

Delete individual model

Deleting an individual model is as easy as...

Batch deleting models from a query

Most likely you won't be wanting to delete just one record, this is where batch deleting comes into play.

Here's a simple batch delete which will delete all model ExampleA records where they were handled_at more than three years ago.

If we want limit on how many records we want to delete in one go, we can use ->limit(1000).

By default queries will be chunked into 100 record batches. If you wish to use your own chunking value, this can be achieved by ->chunk(500).

To use a custom (not 'id') column to chunk by use ->chunkColumn().

Up until now, all actions happen in one syncronious stream. In real world situation it's better to process individual model deletion actions by pushing them to the queue. This can be achieved by including ->copyModelsAsJobs().

If a queue besides the default wants to be used, then include ->onQueue('queue-name').

When deleting large sets of data it may take quite some time. In these cases you may want to group your deleting batches into blocks of time. Let's say we want to run the script nightly at 23:00 and want to make sure we stop moving deleting models at 05:00 the next day. This can be achieved by using ->processBefore(now()->addDay()->setTime(5, 0, 0).

We may also want to limit how many records are deleted in any given minute. To do this a rate per minute (rpm) can be defined. If we're wanting to ensure that we only delete 20 records per minute then we can use ->rpm(20). Using this feature requires ->copyModelsAsJobs() to be used.

Testing

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-model-copy with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
illuminate/support Version ^8.61|^9.0
aaronheath/class-logger Version ^1.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 aaronheath/laravel-model-copy contains the following files

Loading the files please wait ....