Giter Club home page Giter Club logo

lohm's Introduction

Laravel overhauled migrations

Latest Stable Version Total Downloads License Support

This packages overhaul laravel's migration with a table absolute state approach instead of a change state approach. What this means? This means that you tell the migration how you want your tables, and it will take care of syncing it with your database, you do not need to tell it how. So you don't have to keep dozens of files that describes changes, just one for your table. Order is not important, because foreign keys and such, are organized to be placed at the end of the migration, so you can be sure all tables were created before it runs.

Installation

This is a typical installation Laravel package installation, you can run as follows:

composer require aposoftworks/lohm

Add our provider to the config/app.php to enable it:

    'providers' => [
        [...]
        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        \Aposoftworks\LOHM\Providers\LohmServiceProvider::class,
    ],

Usage

New table

Since the migrations are table based and not change based, you can create only one migration per table. You can also customize it's classname in the configuration file (don't forget to publish it). You can also change the directory that they are placed, so you don't overlap it with laravel's default migration.

php artisan make:table Core\User

Running migrations

If you want to run the migrations, simply run migrate:sync, this will get the latest version of your migrations and run them. Since we keep in cache what is currently in the database, we compare the missing fields and make the changes accordingly. But beware that some operations can break the database, such as removing fields that are required for foreign keys, or adding values to foreign keys that don't match.

Publish files

If you would like to change any configuration regarding the package, you can publish it using:

php artisan vendor:publish --tag=lohm-config

You can see that everything is pretty much configurable, file/directory names, cache options, so you can keep it to your taste.

You can also customize the stub used to create the migration using:

php artisan vendor:publish --tag=lohm-stub

It will be placed inside resources/stubs/lohm.php

Commands

  • make:table {classname} {name?} {--T|template=default}

Creates a table migration

  • migrate:sync

Will compare the migrations with the database and apply the differences

  • analyze {database?} {table?} {column?}

Will analyze the migrations data

  • analyze:current

Will analyze the current database

  • analyze:diff {database?} {table?}

Will show the differences between database and migrations without applying it

  • migrate:clear

Will clear the database using our custom migrations

Custom stubs

With LOHM you can write custom migrations to use as templates when creating new ones, after publishing the default one (using: php artisan vendor:publish --tag=lohm-stub), you change "default" with the name you want to use and you are good to go. For example, you can use php artisan make:table User --template=user to use the lohm.user.php stub.

TODO

[ ] Add support for multiple indexes

[x] Add diff command

[x] Add support for removing fields that are not necessary anymore

[x] Add sync functionality

[x] Add support for indexes

[x] Add support for foreign keys

[x] Add analyze command

lohm's People

Contributors

darklight9811 avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.