PHPackages                             phparrot/parrot - 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. phparrot/parrot

ActiveProject

phparrot/parrot
===============

Rule-based generation of fixture databases by sampling operational databases. Forked from maple-syrup-group/dbsampler

0.0.1(5y ago)09[8 issues](https://github.com/phparrot/parrot/issues)MITPHP

Since Feb 10Pushed 5y agoCompare

[ Source](https://github.com/phparrot/parrot)[ Packagist](https://packagist.org/packages/phparrot/parrot)[ RSS](/packages/phparrot-parrot/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

PHParrot/Parrot
===============

[](#phparrotparrot)

A general tool for extracting and cleaning selected tables from a database for use as fixtures. Copies a subset of tables from one database to another under the control of a json configuration file. The latter database can then be dumped to SQL for use as a fixture file.

Why PHParrot?
-------------

[](#why-phparrot)

When we visited our nan at weekends as kids, my brother and I would wait until all the adults were out of the room and then endlessly repeat all the (admittedly very mild) swear words we knew at her pet parrot, in the hope that it would copy us.

As this tool copies (parrots) text from one place to another (and because this seemed like a perfect opportunity to give a project one of those names with 'PHP' stuffed into it), 'PHParrot' kind-of seemed appropriate.

Aside: Nan's parrot never repeated any words we tried teaching it, but it had learned to belch (my uncle's influence).

Usage
-----

[](#usage)

- Create the target database(s) you wish to fill. The tool will only output to existing databases. The content of the Destination Databases **will** be trashed.
- Create `config/credentials.json` with the DB server configuration.
- Create `config/*.db.json` files to define mappings for each required database
- Run `bin/dbsampler.php`

Configuration formats
---------------------

[](#configuration-formats)

All config files live in the `config` subdirectory. Files *cannot* contain comments as the JSON format does not support this, but as a convention, fields called "comment" will be ignored where possible.

#### credentials.json

[](#credentialsjson)

`"driver": "pdo_mysql"` is currently assumed but this may change in future.

##### MySQL

[](#mysql)

See `config/credentials.dist.json`:

```
{
  "driver": "pdo_mysql",
  "dbUser": "root",
  "dbPassword": "SOMEPASSWORD",
  "dbHost": "127.0.0.1"
}

```

If you need different source and dest servers, this becomes:

```
{
  "source": {
    "driver": "pdo_mysql",
    "dbUser": "root",
    "dbPassword": "SOMEPASSWORD",
    "dbHost": "sourceDB.example.com"
  },

  "dest" : {
    "driver": "pdo_mysql",
    "dbUser": "root",
    "dbPassword": "SOMEPASSWORD",
    "dbHost": "127.0.0.1"
  }
}

```

If you need to prepare the connections, add an initialSql stanza:

```
{
  "source": {
    "driver": "pdo_mysql",
    "dbUser": "root",
    "dbPassword": "SOMEPASSWORD",
    "dbHost": "sourceDB.example.com",
    "initialSql": [
      "SET NAMES UTF8"
    ]
  },
  "dest": {
    "driver": "pdo_mysql",
    "dbUser": "root",
    "dbPassword": "SOMEPASSWORD",
    "dbHost": "127.0.0.1",
    "initialSql": [
      "SET NAMES UTF8",
      "SET foreign_key_checks = 0"
    ]
  }
}

```

##### Sqlite

[](#sqlite)

See `config/credentials.dist.json`:

```
{
    "driver": "pdo_sqlite",
    "directory": "..\/path\/to\/sqlite-dbs"
}

```

Paths are assumed to be relative to the config file unless they start with a '/'. Sqlite databases to be migrated are assumed to be `*.sqlite` files in this directory

#### *dbname*.db.json

[](#dbnamedbjson)

```
{
  "name": "small-sqlite-test",          # Configuration name
  "sourceDb": "small-source",           # Name of the source DB
  "destDb": "small-dest",               # Name of the destination DB. This DB will get trashed
  "tables": {                           # A set of tables to be copied over. Each table is defined as "table": config
                                        # Every config stanza requires a sampler field. For now, look these up in
                                        # \PHParrot\Parrot\MigrationConfigProcessor::$samplerMap
                                        # All other fields depend on the specific sampler being used; these should
                                        # all be documented in their own class files in src/Sample
    "fruits": {
      "sampler": "matched",
      "constraints": {
        "name": [
          "apple",
          "pear"
        ]
      },
      "remember": {
        "id": "fruit_ids"               # Cross-referencing is supported by "remember" stanzas
                                        # These take the field name of which the values are to be remembered
                                        # matched to a variable name in which the values will be stored
                                        # Note: Variable declarations do not include a '$' symbol
                                        # References MUST be 'remember'ed before being used, there is no
      }                                 # dependency resolution here, so order your config appropriately
    },
    "vegetables": {
      "sampler": "NewestById",
      "idField": "id",
      "quantity": 2
    },
    "fruit_x_basket": {
      "sampler": "matched",
      "constraints": {
        "fruit_id": "$fruit_ids"        # Remembered variables, with $ sign, can be used as cross-references
                                        # This will expand to all ids of the fruits table matched above
      },
      "where" : [
        "basket_id > 1"                 # The matched sampler can also accept a list of arbitrary WHERE clauses
      ],
      "remember": {
        "basket_id": "basket_ids"
      }
    },
    "baskets": {
      "sampler": "matched",             # samplers support field cleaners that are defined in
                                        # \PHParrot\Parrot\FieldCleanerProvider::getCleanerByName
                                        # They modify or replace the content of the field that they are keyed to
      "constraints": {
        "id": "$basket_ids"
      },
      "cleanFields": {
        "name": "fakefullname"
      }
    }
  },
  "views": [                            # view support is experimental
    "some_view"                         # views are specified as name only but format may change
  ]                                     # The destination's CURRENT_USER() is used as the DEFINER for MySQL DBs
}

```

##### "Faker" cleaners

[](#faker-cleaners)

Any 'faker' ([fzaninotto/faker](https://github.com/fzaninotto/Faker)) generator that does not require parameters can be used directly in the cleanFields stanza by using `"name": "faker:GENERATOR"`, eg:

```
 "cleanFields": {
   "ip": "faker:ipv4"
 },

```

Extending the project
---------------------

[](#extending-the-project)

The tool is designed to be extended primarily by adding custom Samplers (which must implement `\PHParrot\Parrot\Sampler\Sampler`) and cleaners (which must implement `\PHParrot\Parrot\Cleaner\FieldCleaner` ànd be registered with `\PHParrot\Parrot\Cleaner\RowCleaner::registerCleaner`).

Currently, only mysql and sqlite databases are supported, but this could also be extended.

This tool does not convert between database drivers. This means that if your source database is MySQL, then the destination database must also be MySQL.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Unknown

Total

1

Last Release

1923d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1086726?v=4)[Neal Brooks](/maintainers/nealio82)[@nealio82](https://github.com/nealio82)

---

Top Contributors

[![rgeorge-msm](https://avatars.githubusercontent.com/u/26119910?v=4)](https://github.com/rgeorge-msm "rgeorge-msm (29 commits)")[![nealio82](https://avatars.githubusercontent.com/u/1086726?v=4)](https://github.com/nealio82 "nealio82 (19 commits)")[![michaeljoseph](https://avatars.githubusercontent.com/u/169933?v=4)](https://github.com/michaeljoseph "michaeljoseph (15 commits)")[![martinmca](https://avatars.githubusercontent.com/u/44459726?v=4)](https://github.com/martinmca "martinmca (13 commits)")[![nayef-quidco](https://avatars.githubusercontent.com/u/26119886?v=4)](https://github.com/nayef-quidco "nayef-quidco (1 commits)")[![parsingphase](https://avatars.githubusercontent.com/u/867994?v=4)](https://github.com/parsingphase "parsingphase (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/phparrot-parrot/health.svg)

```
[![Health](https://phpackages.com/badges/phparrot-parrot/health.svg)](https://phpackages.com/packages/phparrot-parrot)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[elgg/elgg

Elgg is an award-winning social networking engine, delivering the building blocks that enable businesses, schools, universities and associations to create their own fully-featured social networks and applications.

1.7k15.7k5](/packages/elgg-elgg)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

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