Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sausin/laravel-set-autoincrement
Easily set the auto increment index for your tables in a laravel project
https://github.com/sausin/laravel-set-autoincrement
auto autoincrement database database-management database-migrations increment laravel mysql php sqlite
Last synced: 2 days ago
JSON representation
Easily set the auto increment index for your tables in a laravel project
- Host: GitHub
- URL: https://github.com/sausin/laravel-set-autoincrement
- Owner: sausin
- License: mit
- Created: 2020-04-10T14:47:38.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-11T05:50:25.000Z (over 3 years ago)
- Last Synced: 2024-05-17T21:04:13.801Z (9 months ago)
- Topics: auto, autoincrement, database, database-management, database-migrations, increment, laravel, mysql, php, sqlite
- Language: PHP
- Size: 41 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel package to set custom Auto Increment in database
[](https://packagist.org/packages/sausin/laravel-set-autoincrement)
[](https://packagist.org/packages/sausin/laravel-set-autoincrement)
[](https://scrutinizer-ci.com/g/sausin/laravel-set-autoincrement)
[](https://opensource.org/licenses/MIT)Wanted to easily set the starting ID for your models? This package makes it easy as a breeze! It's also possible to change auto increment on existing databases (i.e. new entries will start from the specified number).
# Installation
Run the below command in your Laravel project root.
```sh
composer require sausin/laravel-set-autoincrement
```
This will install the latest version of the package for you. The service provider will automatically register and make available the features of the package (which work automatically).# Configuration
The default configuration will set the package such that except a few tables, the `AUTO_INCREMENT` counter will be set at `100001` (one hundred thousand and one).
To change the starting value and the tables affected by it, the configuration can be published using
```sh
php artisan vendor:publish
```
and then the option which corresponds to `Sausin\DBSetAutoIncrement\AutoIncrementServiceProvider` needs to be selected. This will add a config named `auto-increment.php` in your project's config folder.Change the values as desired.
# Usage
## Default Behavior
It will run every time migrations are finished running, whether for the first time or incremental. All tables where the `AUTO_INCREMENT` value is higher than the value in the config will be left alone. Changes will be made in all the rest.
If, however, automatic updation behaviour is not desired, the `action` key in the config file can be changed to `manual` and the package will not take automatic action.
## Command line
Using the below command
```sh
php artisan db:set-auto-increment --tables=users --value=20001
```
the auto increment value can be changed manually. Multiple tables are accepted as input.# Supported SQL Drivers
Currently `mysql` and `sqlite` are supported. Plan to have support for more drivers in future.