PHP code example of zaeem2396 / schema-lens
1. Go to this page and download the library: Download zaeem2396/schema-lens library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zaeem2396 / schema-lens example snippets
return [
'export' => [
'row_limit' => env('SCHEMA_LENS_EXPORT_ROW_LIMIT', 1000),
'storage_path' => 'app/schema-lens/exports',
'compress' => env('SCHEMA_LENS_COMPRESS_EXPORTS', true),
],
'output' => [
'format' => env('SCHEMA_LENS_OUTPUT_FORMAT', 'cli'),
'show_line_numbers' => env('SCHEMA_LENS_SHOW_LINE_NUMBERS', true),
],
'sql' => [
'engine' => env('SCHEMA_LENS_SQL_ENGINE'), // e.g. InnoDB, MyISAM; falls back to DB connection engine
],
'backup' => [
'auto' => env('SCHEMA_LENS_BACKUP_AUTO', false),
'driver' => env('SCHEMA_LENS_BACKUP_DRIVER', 'mysqldump'),
'directory' => env('SCHEMA_LENS_BACKUP_DIRECTORY', 'app/schema-lens/backups'),
'retention_days' => (int) env('SCHEMA_LENS_BACKUP_RETENTION_DAYS', 7),
'mysqldump_binary' => env('SCHEMA_LENS_MYSQLDUMP_PATH'),
],
];
bash
composer schema:preview database/migrations/your_migration.php
# Compare two MySQL connections (optional): php artisan schema:diff mysql mysql_staging
# Optional full SQL backup before safe migrate (MySQL client tools bash
php artisan vendor:publish --tag=schema-lens-config
bash
php artisan schema:preview database/migrations/2024_01_01_000000_create_users_table.php
bash
php artisan schema:preview 2024_01_01_000000_create_users_table.php
bash
# Display SQL in terminal
php artisan schema:preview database/migrations/2024_01_01_000000_create_users_table.php --sql
# Save SQL to file
php artisan schema:preview database/migrations/2024_01_01_000000_create_users_table.php --sql --output=migration.sql
# Or use format option
php artisan schema:preview database/migrations/2024_01_01_000000_create_users_table.php --format=sql
bash
# Default: ASCII tree (uses database/migrations)
php artisan schema:graph
# Custom path
php artisan schema:graph --path=database/migrations
# JSON output
php artisan schema:graph --format=json
bash
php artisan schema:diff mysql mysql_staging
# Named options (same as positional arguments)
php artisan schema:diff --from=mysql --to=mysql_staging
# Machine-readable output
php artisan schema:diff mysql mysql_staging --format=json
# Suggested migration-style hints for gaps (review before using)
php artisan schema:diff mysql mysql_staging --stubs
bash
php artisan schema:preview database/migrations/2024_01_01_000000_create_users_table.php --format=json
bash
php artisan schema:preview database/migrations/2024_01_01_000000_create_users_table.php --no-export
bash
php artisan migrate:safe
bash
# Using relative path
php artisan migrate:safe database/migrations/2024_01_15_drop_column.php
# Using absolute path
php artisan migrate:safe /var/www/app/database/migrations/2024_01_15_drop_column.php
bash
# Single file with interactive mode
php artisan migrate:safe database/migrations/2024_01_15_drop_column.php --interactive
# Single file without backup
php artisan migrate:safe database/migrations/2024_01_15_drop_column.php --no-backup
# Single file with pretend mode (just show SQL)
php artisan migrate:safe database/migrations/2024_01_15_drop_column.php --pretend
bash
php artisan migrate:safe --interactive
bash
php artisan migrate:safe --backup
php artisan migrate:safe --backup --backup-path=/var/backups/app-pre-migrate.sql
bash
php artisan schema:restore /path/to/dump.sql
php artisan schema:restore storage/app/schema-lens/backups/schema-lens-db-2026-04-02_120000.sql --connection=mysql
storage/app/schema-lens/exports/
└── 2024_01_01_000000_create_users_table_2024-01-15_10-30-45_v0001/
├── users.json
├── users.csv
├── users.zip (if compression enabled)
└── restore_metadata.json
yaml
- name: Preview Migration
run: |
php artisan schema:preview database/migrations/2024_01_01_000000_create_users_table.php --format=json
cat storage/app/schema-lens/report.json | jq '.destructive_changes'
yaml
migration-preview:
script:
- php artisan schema:preview database/migrations/2024_01_01_000000_create_users_table.php --format=json
- |
if [ $(cat storage/app/schema-lens/report.json | jq '.summary.has_destructive_changes') = "true" ]; then
echo "⚠️ Destructive changes detected!"
exit 1
fi