PHPackages                             dvrtech/schema-tools - 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. dvrtech/schema-tools

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

dvrtech/schema-tools
====================

Laravel package for JSON/CSV schema analysis and database structure generation

v1.0.1(10mo ago)14.3k↓36.1%MITPHPPHP ^8.1

Since Jul 13Pushed 10mo agoCompare

[ Source](https://github.com/dvrtech-us/laravel-schema-tools)[ Packagist](https://packagist.org/packages/dvrtech/schema-tools)[ RSS](/packages/dvrtech-schema-tools/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (3)Used By (0)

Schema Tools for Laravel
========================

[](#schema-tools-for-laravel)

[![Latest Stable Version](https://camo.githubusercontent.com/7692dd0685ab99da54c36ae2cccc02c4ab819e3860742f41d5a56ec2d59f76a1/68747470733a2f2f706f7365722e707567782e6f72672f647672746563682f736368656d612d746f6f6c732f762f737461626c65)](https://packagist.org/packages/dvrtech/schema-tools)[![Total Downloads](https://camo.githubusercontent.com/666c521c15b329320e4d3b59e927766dc582e204c52644e3cac0163426be89ae/68747470733a2f2f706f7365722e707567782e6f72672f647672746563682f736368656d612d746f6f6c732f646f776e6c6f616473)](https://packagist.org/packages/dvrtech/schema-tools)[![License](https://camo.githubusercontent.com/16b223117d4ee70ff97dd05c5627359a18f20f5253b30624e0edc813c2d7ed2f/68747470733a2f2f706f7365722e707567782e6f72672f647672746563682f736368656d612d746f6f6c732f6c6963656e7365)](https://packagist.org/packages/dvrtech/schema-tools)

A comprehensive Laravel package for analyzing JSON/CSV data structures and automatically generating database schemas, migrations, and Eloquent models. Streamline your development workflow by converting raw data into production-ready Laravel components.

🚀 Features
----------

[](#-features)

- **Intelligent Data Analysis**: Automatically analyze JSON and CSV data to determine optimal database column types
- **Smart Type Detection**: Context-aware type inference with intelligent type hierarchy (`json` &gt; `text` &gt; `varchar` &gt; `date` &gt; `decimal` &gt; `float` &gt; `int`)
- **Database Structure Generation**: Generate CREATE TABLE statements for MySQL and SQL Server
- **Laravel Integration**: Generate Laravel migrations and Eloquent models from raw data
- **Type Compatibility**: Intelligent type promotion and compatibility checking
- **Azure Environment Support**: Bidirectional conversion between Azure settings JSON and .env files
- **Flexible Output**: Support for various database types and output formats
- **Production Ready**: Comprehensive test coverage and static analysis

📋 Requirements
--------------

[](#-requirements)

- PHP 8.1 or higher
- Laravel 9.0, 10.0, 11.0, or 12.0

📦 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require dvrtech/schema-tools
```

The package will automatically register its service provider through Laravel's package auto-discovery.

🎯 Quick Start
-------------

[](#-quick-start)

### Basic Usage

[](#basic-usage)

```
# Analyze data structure
php artisan schema-tools:analyze data.json

# Generate complete Laravel resources (migration + model)
php artisan schema-tools:generate data.json users User
```

### Artisan Commands

[](#artisan-commands)

The package provides several Artisan commands for different use cases:

#### Schema Analysis

[](#schema-analysis)

```
# Analyze JSON file and display structure
php artisan schema-tools:analyze data.json

# Analyze CSV file with headers
php artisan schema-tools:analyze customers.csv
```

#### Migration Generation

[](#migration-generation)

```
# Generate migration from JSON data
php artisan schema-tools:migration data.json users

# Generate migration from CSV data
php artisan schema-tools:migration customers.csv customers
```

#### Model Generation

[](#model-generation)

```
# Generate Eloquent model from JSON
php artisan schema-tools:model data.json User

# Generate model with custom table name
php artisan schema-tools:model data.json User --table=custom_users
```

#### Complete Resource Generation

[](#complete-resource-generation)

```
# Generate both migration and model
php artisan schema-tools:generate data.json users User

# Generate with custom namespace
php artisan schema-tools:generate data.json users User --namespace=App\\Models\\Custom
```

### Azure Environment Conversion

[](#azure-environment-conversion)

Convert between Azure settings JSON and Laravel .env files:

```
# Convert Azure settings JSON to .env file
php artisan azure-env:convert azure-to-env --azure-file=azure-settings.json --env-file=.env

# Convert .env file to Azure settings JSON
php artisan azure-env:convert env-to-azure --env-file=.env --azure-file=azure-settings.json
```

⚙️ Configuration
----------------

[](#️-configuration)

Publish the configuration file to customize default settings:

```
php artisan vendor:publish --provider="DVRTech\SchemaTools\SchemaToolsServiceProvider"
```

The configuration file (`config/schema-tools.php`) allows you to customize:

- **Export Paths**: Default locations for generated migrations and models
- **Type Mappings**: Custom database type mappings
- **Naming Conventions**: File and class naming patterns

### Default Configuration

[](#default-configuration)

```
return [
    'export_paths' => [
        'migrations' => 'database/migrations',
        'models' => 'app/Models',
    ],
];
```

🧪 Testing
---------

[](#-testing)

Run the test suite:

```
# Run all tests
composer test

# Run tests with coverage
./vendor/bin/phpunit --coverage-html coverage-report

# Run static analysis
./vendor/bin/phpstan
```

🔧 Advanced Usage
----------------

[](#-advanced-usage)

### Programmatic API

[](#programmatic-api)

#### Basic Schema Analysis

[](#basic-schema-analysis)

```
use DVRTech\SchemaTools\Services\SchemaAnalyzer;

$analyzer = new SchemaAnalyzer();

// Analyze JSON data
$jsonData = json_decode(file_get_contents('data.json'), true);
$structure = $analyzer->analyzeDataStructure($jsonData);

// Inspect column information
foreach ($structure as $columnName => $columnDto) {
    echo "Column: {$columnName}\n";
    echo "Type: {$columnDto->type}\n";
    echo "SQL Definition: {$columnDto->getSqlDefinition()}\n";
    echo "Laravel Definition: {$columnDto->getLaravelMigrationDefinition()}\n\n";
}
```

#### Generate Raw SQL Schema

[](#generate-raw-sql-schema)

```
use DVRTech\SchemaTools\Services\DatabaseSchemaGenerator;

$generator = new DatabaseSchemaGenerator();

// Generate CREATE TABLE SQL
$createSQL = $generator->generateCreateTableSQL('users', $structure);
echo $createSQL;

// Output example:
// CREATE TABLE users (
//     id INT AUTO_INCREMENT PRIMARY KEY,
//     name VARCHAR(255) NOT NULL,
//     email VARCHAR(255) NOT NULL,
//     age INT,
//     created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
// );
```

#### Generate Laravel Migration

[](#generate-laravel-migration)

```
use DVRTech\SchemaTools\Generators\MigrationGenerator;

$migrationGenerator = new MigrationGenerator();
$migration = $migrationGenerator->generateMigration('users', $structure);

// Save to migration file
$filename = date('Y_m_d_His') . '_create_users_table.php';
file_put_contents(
    database_path('migrations/' . $filename),
    $migration
);
```

#### Generate Eloquent Model

[](#generate-eloquent-model)

```
use DVRTech\SchemaTools\Generators\ModelGenerator;

$modelGenerator = new ModelGenerator();
$model = $modelGenerator->generateModel('User', 'users', $structure);

// Save to model file
file_put_contents(app_path('Models/User.php'), $model);
```

### Type Detection Logic

[](#type-detection-logic)

The package uses intelligent type detection with the following hierarchy:

1. **JSON/Arrays**: Complex data structures → `json` column type
2. **Text**: Long strings (&gt;255 chars) → `text` column type
3. **VARCHAR**: Short strings with dynamic length calculation → `varchar(n)`
4. **Dates**: Pattern-matched date strings → `date`/`datetime`
5. **Decimal**: Context-aware numeric detection (price, amount) → `decimal(8,2)`
6. **Float**: Decimal numbers → `float`
7. **Integer**: Whole numbers → `int`

### Context-Aware Type Detection

[](#context-aware-type-detection)

The analyzer uses column name context to make intelligent type decisions:

```
// These column names will automatically use decimal type
$priceColumns = ['price', 'amount', 'cost', 'fee', 'total', 'subtotal'];

// These will use appropriate string lengths
$emailColumns = ['email']; // varchar(255)
$nameColumns = ['name', 'title']; // varchar(255)
```

📊 Data Format Support
---------------------

[](#-data-format-support)

### JSON Files

[](#json-files)

Supports both single objects and arrays:

```
// Single object
{
    "name": "John Doe",
    "email": "john@example.com",
    "age": 30
}

// Array of objects
[
    {"name": "John", "email": "john@example.com", "age": 30},
    {"name": "Jane", "email": "jane@example.com", "age": 25}
]
```

### CSV Files

[](#csv-files)

Automatically detects headers and analyzes data types:

```
name,email,age,registration_date
John Doe,john@example.com,30,2024-01-15
Jane Smith,jane@example.com,25,2024-01-16
```

🔄 Azure Integration
-------------------

[](#-azure-integration)

### Environment File Conversion

[](#environment-file-conversion)

Convert between Azure App Service configuration and Laravel .env files:

```
# Azure settings JSON format
{
    "DATABASE_URL": "mysql://user:pass@host:3306/db",
    "APP_ENV": "production",
    "APP_DEBUG": "false"
}

# Converts to .env format
DATABASE_URL=mysql://user:pass@host:3306/db
APP_ENV=production
APP_DEBUG=false
```

🏗️ Architecture Overview
------------------------

[](#️-architecture-overview)

The package follows a clean architecture pattern:

- **Services Layer**: Core business logic (`SchemaAnalyzer`, `DatabaseSchemaGenerator`)
- **Generators Layer**: Code generation (`MigrationGenerator`, `ModelGenerator`)
- **DTO Pattern**: Structured data representation (`ColumnStructureDTO`)
- **Console Commands**: Artisan command interface
- **Template System**: File-based code generation templates

🤝 Contributing
--------------

[](#-contributing)

We welcome contributions! Please follow these guidelines:

1. **Fork the repository**
2. **Create a feature branch**: `git checkout -b feature/amazing-feature`
3. **Follow coding standards**: Use PSR-12 coding standards
4. **Add tests**: Ensure your changes are covered by tests
5. **Run quality checks**: ```
    ./vendor/bin/phpunit
    ./vendor/bin/phpstan
    ```
6. **Commit your changes**: Use conventional commit messages
7. **Push to the branch**: `git push origin feature/amazing-feature`
8. **Open a Pull Request**

### Development Setup

[](#development-setup)

```
# Clone the repository
git clone https://github.com/dvrtech-us/laravel-schema-tools.git
cd laravel-schema-tools

# Install dependencies
composer install

# Run tests
./vendor/bin/phpunit

# Run static analysis
./vendor/bin/phpstan
```

📝 Changelog
-----------

[](#-changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

🛡️ Security
-----------

[](#️-security)

If you discover any security-related issues, please email  instead of using the issue tracker.

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

💼 About DVRTech
---------------

[](#-about-dvrtech)

This package is developed and maintained by [DVRTech LLC](https://dvrtech.us).

🙏 Credits
---------

[](#-credits)

- **DVRTech LLC** - Initial development and maintenance
- **Laravel Community** - Inspiration and framework
- **All Contributors** - Thank you for your contributions!

---

 **Made with ❤️ by DVRTech**

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance54

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

310d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/69176615?v=4)[dvrtech](/maintainers/dvrtech)[@dvrtech](https://github.com/dvrtech)

---

Top Contributors

[![dvrtech-us](https://avatars.githubusercontent.com/u/8093238?v=4)](https://github.com/dvrtech-us "dvrtech-us (4 commits)")

---

Tags

jsonlaravelschemamigrationdatabaseeloquent

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

### Embed Badge

![Health badge](/badges/dvrtech-schema-tools/health.svg)

```
[![Health](https://phpackages.com/badges/dvrtech-schema-tools/health.svg)](https://phpackages.com/packages/dvrtech-schema-tools)
```

###  Alternatives

[cybercog/laravel-clickhouse

ClickHouse migrations for Laravel

163166.8k](/packages/cybercog-laravel-clickhouse)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[dragon-code/laravel-data-dumper

Adding data from certain tables when executing the `php artisan schema:dump` console command

3418.6k](/packages/dragon-code-laravel-data-dumper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
