nf/migration

Add migration to NF Theme

2.0.3 2018-12-13 03:54 UTC

This package is auto-updated.

Last update: 2024-12-13 23:49:23 UTC


README

It's an extension for our theme https://github.com/hieu-pv/nf-theme

NF Migration

Installation

Migration package can be used in plugin also, with a plugin that is created with NF Core module

To create an empty plugin that use NF Core module, move to wp-contents/plugins

By running following command and select correct option you can create an empty plugin

vcc create-project --name="your_plugin_name"

Copy file uninstall.php from plugin/uninstall.php. So when plugin is unistalled the tables will automatically deleted

To use nf-core module in your plugin make sure you have correct configuration in config/app.php with is_plugin=true and plugin_file={your_main_plugin_file_name}

Step 1: Install Through Composer

composer require nf/migration

Step 2: Add the Service Provider

Open config/app.php and register the required service provider.

  'providers'  => [
        // .... Others providers
        \NF\Database\Providers\DatabaseServiceProvider::class,
    ],

Step 3: Update autoload rule

Add the following code to autoload section of your composer.json

    "classmap": [
        "database"
    ]

Step 4: Publish needed files

By run publis command we will see a new folder called database in your theme root directory

php command migration:publish

Step 5: Play with command

Create migration file

php command make:migration {file_name} --create="{table_name}"

Or you can create another to update existing table

php command make:migration {file_name} --table="{existing_table_name}"

Example:

// create test table
php command make:migration create_test_table --create=test

// update test table
php command make:migration add_more_column_to_test_table --table=test

Step 6: Migrate your tables

php command migrate

Rollback all migration file

php command migrate:rollback