PHPackages                             bakkahit/sql-migration - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. bakkahit/sql-migration

ActiveLibrary[Database &amp; ORM](/categories/database)

bakkahit/sql-migration
======================

SqlMigration is a Laravel package that allows you to execute custom SQL migrations directly within your Laravel application. Instead of writing SQL queries manually or relying only on Laravel's built-in migrations, this package enables you to create and run .php migration files containing custom SQL commands like INSERT, DELETE, UPDATE, CREATE TABLE, and more.

v1.4.0(1y ago)162MITPHPPHP ^8.1

Since Nov 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/BakkahIT/sql-migration)[ Packagist](https://packagist.org/packages/bakkahit/sql-migration)[ RSS](/packages/bakkahit-sql-migration/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

SqlMigration Package
====================

[](#sqlmigration-package)

`SqlMigration` is a Laravel package designed for executing custom SQL migrations seamlessly within your Laravel application. This package bridges the gap between Laravel's migrations and raw SQL execution, allowing you to write powerful SQL commands directly in your migration files.

Why Use SqlMigration?
---------------------

[](#why-use-sqlmigration)

When working with complex database operations, Laravel's schema builder may not suffice. `SqlMigration` empowers developers to:

- Run raw SQL queries directly in migration files.
- Handle advanced database operations that require custom SQL commands.
- Integrate these capabilities seamlessly into Laravel's migration system.

Features
--------

[](#features)

- **SQL Command Support**: Write `INSERT`, `UPDATE`, `DELETE`, `CREATE TABLE`, and other SQL queries.
- **Laravel Integration**: Fully compatible with Laravel's migration commands.
- **Custom SQL Logic**: Define any SQL query your application needs.
- **Private Use**: Built for internal projects and teams.

Installation
------------

[](#installation)

Install the package in your Laravel project with:

```
composer require bakkahit/sql-migration
```

Open the `config/app.php` file in your Laravel project and add the `SqlMigrationServiceProvider` class to the list of providers, like this

```
    'providers' => [
        // Other service providers...
        BakkahIT\SqlMigration\SqlMigrationServiceProvider::class,
    ]
```

Usage
-----

[](#usage)

### Step 1: Create a SQL Migration File

[](#step-1-create-a-sql-migration-file)

You can create a new SQL migration file by using the following Artisan command:

```
php artisan make:sql-migration create_test_table_sql
```

This command will generate a migration file inside the `database/migrations` directory, with a name following this format: `YYYY_MM_DD_HHMMSS_create_test_table_sql.php`. The `create_test_table_sql` part of the file name is the name you provide when running the command, and it will be used in the generated migration class as well.

### Step 2: Write SQL Queries in the Migration File

[](#step-2-write-sql-queries-in-the-migration-file)

Once the migration file is created, you will see a class with `up()` and `down()` methods. You can define your SQL queries inside the `up()` method to apply changes to the database, and in the `down()` method to reverse them.

Example of a migration file with raw SQL to create a table:

```
