table_col

Get Started

Welcome to the documentation for the Laravel Migration Enhancement Package. This Composer package is designed to simplify and enhance the migration process in Laravel, providing developers with more efficient tools for managing database schema changes.

Installation

              
                $  composer require helloarman/dumptable
              
            
              
                $  php artisan storage:link
              
            

Requirement

Options Version
PHP v8.0+
Laravel v7+

Features

Here are all of the feature list of the package.


Update Table with Dumptable Command:

Command:
              
                $  php artisan table:dump {table_name}
              
          
Description:

This command updates a table with its corresponding migration file. It is particularly useful during the development phase when you need to update a specific column in a single table without affecting other tables. Unlike php artisan migrate:fresh or php artisan migrate:refresh, this command only affects the specified table.

Flags:
Flag Workings
-s or --seed Migrate and run the seeder file after updating the migration file.
-r or --restore Update the columns without removing existing data from the table.
Command:
            
              $  php artisan table:dump {table_name} --restore
            
          
Command:
            
              $  php artisan table:dump {table_name} --seed
            
          
Flags:
Flag Workings
--class To use a different seeder file name
Command:
            
              $  php artisan table:dump {table_name} --seed --class={seeder_class_name}
            
          

Backup Table Data:

Command:
              
                $  php artisan table:backup {table_name}
              
          
Description:

This command creates a backup SQL file of the specified table in the storage/backups folder.


Restore Table Data:

Command:
              
                $  php artisan table:restore {table_name}
              
          
Description:

This command restores the SQL file data to the specified table.

Flags:
Flag Workings
-d or --delete Delete the SQL file after restoring the data.
Command:
            
              $  php artisan table:restore {table_name} --delete
            
          

Fresh and Seed Data:

Command:
              
                $  php artisan table:fresh-seed {table_name}
              
          
Description:

This command seeds data into the specified table, deleting previous data. It is useful for resetting table data during development.

Flags:
Flag Workings
--class To use a different seeder file name
Command:
            
              $  php artisan table:fresh-seed {table_name} --class={seeder_class_name}
            
          

Align Additional Migration File:

Command:
              
                $  php artisan table:col {type} {column_name} {table}
              
          
Description:

This command simplifies the process of updating a migration file in a production environment. Instead of creating a new migration file with the current date, it aligns the new file immediately after the main migration file for the table. This makes it easier to find and manage migration files, keeping the structure well-organized.

Screenshot:
table_col
Command and Output File Naming Examples:
Command Migration File Name
$ php artisan table:col add type services 2023_04_28_205611_add_type_to_users_table.php
$ php artisan table:col update type services 2023_04_28_205612_update_type_to_users_table.php
$ php artisan table:col remove short_description services 2023_04_28_205613_remove_short_description_to_users_table.php
and so on...
Command:
            
              $  php artisan table:fresh-seed {table_name} --class={seeder_class_name}
            
          

FAQ:

This command updates a specific table's migration file without affecting other tables, ideal for development phase updates.

Adding -s or --seed runs migrations and seeds the database after updating the migration file.

This command creates a backup SQL file for the specified table in the storage/backups folder.

Use this command to restore a SQL file backup back into the specified database table.

Adding -d or --delete removes the SQL backup file after successfully restoring its data into the table.

This command seeds data into a table, replacing previous data, offering a clean slate for development or testing.

Use --class=YourSeederFileName to specify a different seeder file structure than the default ModelnameSeeder.

This command simplifies adding new migration files after the main table migration, ensuring a structured approach.

It facilitates easy management of migration files after a project goes live, maintaining a clear and organized file structure.

By appending new migration files in sequence after the main table migration, keeping related migrations together for easy reference.

Error Handling:

# After running dump:table {table_name} --restore:

As restore flag is in beta version. so there are some limitations. We are working on it. In-sha-Allah we will resolve it.

Solution:

This is not actually an issue. It is just a warning that if your data was not restored. Please check backup file for that.

Main reason for not restoring data:
  • Storage file is not linked properly. run command php artisan storage:link
  • Having foreign keys in your table
  • adding new row without adding nullable() values

Contributors: