Download the PHP package panytsch/elastic-migrations-laravel without Composer
On this page you can find all versions of the php package panytsch/elastic-migrations-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download panytsch/elastic-migrations-laravel
More information about panytsch/elastic-migrations-laravel
Files in panytsch/elastic-migrations-laravel
Package elastic-migrations-laravel
Short Description Elasticsearch migrations for Laravel
License MIT
Informations about the package elastic-migrations-laravel
Elastic Migrations
Elasticsearch migrations for Laravel allow you to easily modify and share indices schema across the application's environments.
Contents
- Compatibility
- Fork changes
- Installation
- Configuration
- Writing Migrations
- Running Migrations
- Reverting Migrations
- Starting Over
- Migration Status
- Troubleshooting
Compatibility
The current version of Elastic Migrations has been tested with the following configuration:
- PHP 7.2-7.4
- Elasticsearch 7.x
- Laravel 6.x-8.x
Fork changes
This specific forked version doesn't need MySQL to save migrations results. You may use Elasticsearch only. To do this you just need: Set environment variables
OR
change this configs in file
After this you have to create this elastic index (will be automated in future versions) with mapping:
Installation
The library can be installed via Composer:
If you want to use Elastic Migrations with Lumen framework check this guide.
Configuration
Elastic Migrations uses babenkoivan/elastic-client as a dependency. If you want to change the default client settings (and I'm pretty sure you do), then you need to create the configuration file first:
You can change Elasticsearch host and other client settings in the config/elastic.client.php
file. Please refer to
babenkoivan/elastic-client for more details.
If you want to change the migration default table name, the migrations directory or set an index name prefix, publish Elastic Migrations settings as well:
The published configuration can be found in the config/elastic.migrations.php
file.
Finally, don't forget to run Laravel database migrations to create Elastic Migrations table:
Writing Migrations
You can effortlessly create a new migration file using an Artisan console command:
This command creates a migration class in the elastic/migrations
directory.
Every migration includes two methods: up
and down
. up
is used to alternate the index schema and down
is used to revert that action.
You can use ElasticMigrations\Facades\Index
facade to perform basic operations over Elasticsearch indices:
Create Index
Create an index with the default settings:
or use a modifier to configure mapping and settings:
There is also an option to create an index only if it doesn't exist:
Update Mapping
Use the modifier to adjust the mapping:
Update Settings
Use the modifier to change the index configuration:
You can update analysis settings only on closed indices. The putSettingsHard
method closes the index, updates the configuration and
opens the index again:
Drop Index
You can unconditionally delete the index:
or delete it only if it exists:
More
Finally, you are free to inject Elasticsearch\Client
in the migration constructor and execute any supported by client actions.
Running Migrations
You can either run all migrations:
or run a specific one:
Use the --force
option if you want to execute migrations on production environment:
Reverting Migrations
You can either revert the last executed migrations:
or rollback a specific one:
Use the elastic:migrate:reset
command if you want to revert all previously migrated files:
Starting Over
Sometimes you just want to start over and rollback all the changes to migrate them again immediately:
Migration Status
You can always check which files have been already migrated and what can be reverted by the elastic:migrate:rollback
command (the last batch):
Troubleshooting
If you see one of the messages below, please execute the mentioned action:
Migration table is not yet created
- run thephp artisan migrate
commandMigration directory is not yet created
- create a migration file using theelastic:make:migration
command or create a the migrations directory manually
All versions of elastic-migrations-laravel with dependencies
babenkoivan/elastic-client Version ^1.0
babenkoivan/elastic-adapter Version ^1.8