PHPackages                             callcocam/tall-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. callcocam/tall-migration

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

callcocam/tall-migration
========================

Generate migrations from existing database structures

08PHP

Since Oct 20Pushed 2y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Migration Generator
===========================

[](#laravel-migration-generator)

Installation
============

[](#installation)

```
composer require --dev callcocam/tall-migration
```

```
php artisan vendor:publish --provider="Tall\Migration\TallMigratioProvider"
```

Lumen Installation
==================

[](#lumen-installation)

```
composer require --dev callcocam/tall-migration
```

Copy config file from `vendor/callcocam/tall-migration/config` to your Lumen config folder

Register service provider in bootstrap/app.php

```
$app->register(\Tall\Migration\TallMigratioProvider::class);
```

Usage
=====

[](#usage)

Whenever you have database changes or are ready to squash your database structure down to migrations, run:

```
php artisan generate:migrations
```

By default, the migrations will be created in `tests/database/migrations`. You can specify a different path with the `--path` option:

```
php artisan generate:migrations --path=database/migrations
```

You can specify the connection to use as the database with the `--connection` option:

```
php artisan generate:migrations --connection=mysql2
```

You can also clear the directory with the `--empty-path` option:

```
php artisan generate:migrations --empty-path
```

This command can also be run by setting the `TALL_RUN_AFTER_MIGRATIONS` environment variable to `true` and running your migrations as normal. This will latch into the `MigrationsEnded` event and run this command using the default options specified via your environment variables. Note: it will only run when your app environment is set to `local`.

Configuration
=============

[](#configuration)

Want to customize the migration stubs? Make sure you've published the vendor assets with the artisan command to publish vendor files above.

Environment Variables
---------------------

[](#environment-variables)

KeyDefault ValueAllowed ValuesDescriptionTALL\_RUN\_AFTER\_MIGRATIONSfalsebooleanWhether or not the migration generator should run after migrations have completed.TALL\_CLEAR\_OUTPUT\_PATHfalsebooleanWhether or not to clear out the output path before creating new files. Same as specifying `--empty-path` on the commandTALL\_TABLE\_NAMING\_SCHEME`[Timestamp]_create_[TableName]_table.php`stringThe string to be used to name table migration filesTALL\_VIEW\_NAMING\_SCHEME`[Timestamp]_create_[ViewName]_view.php`stringThe string to be used to name view migration filesTALL\_OUTPUT\_PATHtests/database/migrationsstringThe path (relative to the root of your project) to where the files will be output to. Same as specifying `--path=` on the commandTALL\_SKIPPABLE\_TABLESmigrationscomma delimited stringThe tables to be skippedTALL\_SKIP\_VIEWSfalsebooleanWhen true, skip all viewsTALL\_SKIPPABLE\_VIEWS''comma delimited stringThe views to be skippedTALL\_SORT\_MODE'foreign\_key'stringThe sorting mode to be used. Options: `foreign_key`TALL\_PREFER\_UNSIGNED\_PREFIXtruebooleanWhen true, uses `unsigned` variant methods instead of the `->unsigned()` modifier.TALL\_USE\_DEFINED\_INDEX\_NAMEStruebooleanWhen true, uses index names defined by the database as the name parameter for index methodsTALL\_USE\_DEFINED\_FOREIGN\_KEY\_INDEX\_NAMEStruebooleanWhen true, uses foreign key index names defined by the database as the name parameter for foreign key methodsTALL\_USE\_DEFINED\_UNIQUE\_KEY\_INDEX\_NAMEStruebooleanWhen true, uses unique key index names defined by the database as the name parameter for the `unique` methodsTALL\_USE\_DEFINED\_PRIMARY\_KEY\_INDEX\_NAMEStruebooleanWhen true, uses primary key index name defined by the database as the name parameter for the `primary` methodTALL\_WITH\_COMMENTStruebooleanWhen true, export comment using `->comment()` method.TALL\_USE\_DEFINED\_DATATYPE\_ON\_TIMESTAMPfalsebooleanWhen false, uses `->timestamps()` by mashing up `created_at` and `updated_at` regardless of datatype defined by the databaseTALL\_MYSQL\_TABLE\_NAMING\_SCHEMEnull?booleanWhen not null, this setting will override TALL\_TABLE\_NAMING\_SCHEME when the database driver is `mysql`.TALL\_MYSQL\_VIEW\_NAMING\_SCHEMEnull?booleanWhen not null, this setting will override TALL\_VIEW\_NAMING\_SCHEME when the database driver is `mysql`.TALL\_MYSQL\_OUTPUT\_PATHnull?booleanWhen not null, this setting will override TALL\_OUTPUT\_PATH when the database driver is `mysql`.TALL\_MYSQL\_SKIPPABLE\_TABLESnull?booleanWhen not null, this setting will override TALL\_SKIPPABLE\_TABLES when the database driver is `mysql`.TALL\_MYSQL\_SKIPPABLE\_VIEWSnullcomma delimited stringThe views to be skipped when driver is `mysql`TALL\_SQLITE\_TABLE\_NAMING\_SCHEMEnull?booleanWhen not null, this setting will override TALL\_TABLE\_NAMING\_SCHEME when the database driver is `sqlite`.TALL\_SQLITE\_VIEW\_NAMING\_SCHEMEnull?booleanWhen not null, this setting will override TALL\_VIEW\_NAMING\_SCHEME when the database driver is `sqlite`.TALL\_SQLITE\_OUTPUT\_PATHnull?booleanWhen not null, this setting will override TALL\_OUTPUT\_PATH when the database driver is `sqlite`.TALL\_SQLITE\_SKIPPABLE\_TABLESnull?booleanWhen not null, this setting will override TALL\_SKIPPABLE\_TABLES when the database driver is `sqlite`.TALL\_SQLITE\_SKIPPABLE\_VIEWSnullcomma delimited stringThe views to be skipped when driver is `sqlite`TALL\_PGSQL\_TABLE\_NAMING\_SCHEMEnull?booleanWhen not null, this setting will override TALL\_TABLE\_NAMING\_SCHEME when the database driver is `pgsql`.TALL\_PGSQL\_VIEW\_NAMING\_SCHEMEnull?booleanWhen not null, this setting will override TALL\_VIEW\_NAMING\_SCHEME when the database driver is `pgsql`.TALL\_PGSQL\_OUTPUT\_PATHnull?booleanWhen not null, this setting will override TALL\_OUTPUT\_PATH when the database driver is `pgsql`.TALL\_PGSQL\_SKIPPABLE\_TABLESnull?booleanWhen not null, this setting will override TALL\_SKIPPABLE\_TABLES when the database driver is `pgsql`.TALL\_PGSQL\_SKIPPABLE\_VIEWSnullcomma delimited stringThe views to be skipped when driver is `pgsql`TALL\_SQLSRV\_TABLE\_NAMING\_SCHEMEnull?booleanWhen not null, this setting will override TALL\_TABLE\_NAMING\_SCHEME when the database driver is `sqlsrc`.TALL\_SQLSRV\_VIEW\_NAMING\_SCHEMEnull?booleanWhen not null, this setting will override TALL\_VIEW\_NAMING\_SCHEME when the database driver is `sqlsrv`.TALL\_SQLSRV\_OUTPUT\_PATHnull?booleanWhen not null, this setting will override TALL\_OUTPUT\_PATH when the database driver is `sqlsrv`.TALL\_SQLSRV\_SKIPPABLE\_TABLESnull?booleanWhen not null, this setting will override TALL\_SKIPPABLE\_TABLES when the database driver is `sqlsrv`.TALL\_SQLSRV\_SKIPPABLE\_VIEWSnullcomma delimited stringThe views to be skipped when driver is `sqlsrv`Stubs
-----

[](#stubs)

There is a default stub for tables and views, found in `resources/stubs/vendor/tall-migration/`. Each database driver can be assigned a specific migration stub by creating a new stub file in `resources/stubs/vendor/tall-migration/` with a `driver`-prefix, e.g. `mysql-table.stub` for a MySQL specific table stub.

Stub Naming
-----------

[](#stub-naming)

Table and view stubs can be named using the `TALL_(TABLE|VIEW)_NAMING_SCHEME` environment variables. Optionally, driver-specific naming schemes can be used as well by specifying `TALL_{driver}_TABLE_NAMING_SCHEME` environment vars using the same tokens. See below for available tokens that can be replaced.

### Table Name Stub Tokens

[](#table-name-stub-tokens)

Table stubs have the following tokens available for the naming scheme:

TokenExampleDescription`[TableName]`usersTable's name, same as what is defined in the database`[TableName:Studly]`UsersTable's name with `Str::studly()` applied to it (useful for standardizing table names if they are inconsistent)`[TableName:Lowercase]`usersTable's name with `strtolower` applied to it (useful for standardizing table names if they are inconsistent)`[Timestamp]`2021\_04\_25\_110000The standard migration timestamp format, at the time of calling the command: `Y_m_d_His``[Index]`0The key of the migration in the sorted order, for use with enforcing a sort order`[IndexedEmptyTimestamp]`0000\_00\_00\_000041The standard migration timestamp format, but filled with 0s and incremented by `[Index]` seconds`[IndexedTimestamp]`2021\_04\_25\_110003The standard migration timestamp format, at the time of calling the command: `Y_m_d_His` incremented by `[Index]` seconds### Table Schema Stub Tokens

[](#table-schema-stub-tokens)

Table schema stubs have the following tokens available:

TokenDescription`[TableName]`Table's name, same as what is defined in the database`[TableName:Studly]`Table's name with `Str::studly()` applied to it, for use with the class name`[TableUp]`Table's `up()` function`[TableDown]`Table's `down()` function`[Schema]`The table's generated schema### View Name Stub Tokens

[](#view-name-stub-tokens)

View stubs have the following tokens available for the naming scheme:

TokenExampleDescription`[ViewName]`user\_earningsView's name, same as what is defined in the database`[ViewName:Studly]`UserEarningsView's name with `Str::studly()` applied to it (useful for standardizing view names if they are inconsistent)`[ViewName:Lowercase]`user\_earningsView's name with `strtolower` applied to it (useful for standardizing view names if they are inconsistent)`[Timestamp]`2021\_04\_25\_110000The standard migration timestamp format, at the time of calling the command: `Y_m_d_His``[Index]`0The key of the migration in the sorted order, for use with enforcing a sort order`[IndexedEmptyTimestamp]`0000\_00\_00\_000041The standard migration timestamp format, but filled with 0s and incremented by `[Index]` seconds`[IndexedTimestamp]`2021\_04\_25\_110003The standard migration timestamp format, at the time of calling the command: `Y_m_d_His` incremented by `[Index]` seconds### View Schema Stub Tokens

[](#view-schema-stub-tokens)

View schema stubs have the following tokens available:

TokenDescription`[ViewName]`View's name, same as what is defined in the database`[ViewName:Studly]`View's name with `Str::studly()` applied to it, for use with the class name`[Schema]`The view's schemaExample Usage
=============

[](#example-usage)

Given a database structure for a `users` table of:

```
CREATE TABLE `users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `first_name` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `last_name` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `timezone` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'America/New_York',
  `location_id` int(10) unsigned NOT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `remember_token` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `users_username_index` (`username`),
  KEY `users_first_name_index` (`first_name`),
  KEY `users_last_name_index` (`last_name`),
  KEY `users_email_index` (`email`),
  KEY `fk_users_location_id_index` (`location_id`)
  CONSTRAINT `users_location_id_foreign` FOREIGN KEY (`location_id`) REFERENCES `locations` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
```

A `tests/database/migrations/[TIMESTAMP]_create_users_table.php` with the following Blueprint would be created:

```
