Search by

k-kinzal / sql-fixture

kinzal

FakerPHP provider that generates fixture rows from MySQL, PostgreSQL, and SQLite table definitions

Package info

github.com/k-kinzal/sql-fixture

Documentation

pkg:composer/k-kinzal/sql-fixture

Statistics

Installs: 75

Dependents: 3

Suggesters: 0

Stars: 0

v0.1.1 2026-03-06 16:09 UTC

This package is auto-updated.

Last update: 2026-09-28 02:33:11 UTC


README

Packagist Downloads PHP Version License: MIT Docs Ask DeepWiki

SQL Fixture is a FakerPHP provider that generates fixture rows from table definitions for MySQL, PostgreSQL, and SQLite. It reads the schema from CREATE TABLE statements (FixtureProvider), a live PDO connection (DatabaseFixtureProvider), or a directory of DDL files (FileFixtureProvider), and generates values that match each column's type, length, and constraints. Generated rows can be returned as arrays or hydrated into PHP objects, and related rows can be generated together from a fixture plan.

Requirements

Support Syntax

The following database versions are supported. Pass the dialect and, optionally, the version tag to FixtureProvider or FileFixtureProvider; omitting the version tag uses the default for that database. DatabaseFixtureProvider reads both from the connection.

MySQL

Version Version tag Default
5.6.51 mysql-5.6.51
5.7.44 mysql-5.7.44
8.0.44 mysql-8.0.44
8.1.0 mysql-8.1.0
8.2.0 mysql-8.2.0
8.3.0 mysql-8.3.0
8.4.7 mysql-8.4.7 Yes
9.0.1 mysql-9.0.1
9.1.0 mysql-9.1.0

PostgreSQL

Version Version tag Default
16.6 pg-16.6
17.2 pg-17.2 Yes

SQLite

Version Version tag Default
3.47.2 sqlite-3.47.2 Yes

Installation

composer require --dev k-kinzal/sql-fixture

Usage

use Faker\Factory;
use SqlFixture\Provider\FixtureProvider;

$faker = Factory::create();
$faker->addProvider(new FixtureProvider($faker));

$user = $faker->fixture(
    'CREATE TABLE users (
        id INT PRIMARY KEY AUTO_INCREMENT,
        name VARCHAR(255) NOT NULL,
        status ENUM("active", "inactive") NOT NULL
    )',
    ['name' => 'Alice'],
);
// For example: ['name' => 'Alice', 'status' => 'active']

To read the statements as another release does, pass the dialect and the version tag:

$provider = new FixtureProvider($faker, dialect: 'mysql', version: 'mysql-8.0.44');
$provider->getVersion(); // 'mysql-8.0.44'

DatabaseFixtureProvider detects the release of the connected server:

use SqlFixture\Provider\DatabaseFixtureProvider;

$provider = new DatabaseFixtureProvider($faker, $pdo);
$provider->getVersion(); // For example: 'mysql-8.0.44' for a MySQL 8.0 server

License

MIT License. See LICENSE for details.