NAME
dbic-mockdata - Generate mock test data for a DBIx::Class schema
VERSION
Version 0.05
SYNOPSIS
dbic-mockdata --schema-dir /path/to/lib \
--namespace MyApp::Schema \
--dsn "dbi:SQLite:dbname=test.db" [options]
DESCRIPTION
Connects the given DBIx::Class schema and hands it to DBIx::Class::MockData to generate and insert mock rows.
OPTIONS
--schema-dir Directory containing the schema classes (required)
--namespace Top-level schema package name, e.g. MyApp::Schema (required)
--dsn DBI DSN string, e.g. "dbi:Pg:dbname=mydb" (required)
--user Database username
--password Database password
--rows Rows to insert per table (default: 5)
--rows-per-table JSON string for per-table row counts, e.g. '{"Author":10,"Book":3}'
--generators JSON string for custom generators, e.g. '{"email":"user{row}@example.com"}'
--seed Random seed for reproducible output
--deploy Create tables that do not yet exist
--truncate Empty all tables while preserving structure (fast, recommended)
--wipe Drop and recreate all tables before inserting (destructive, slow)
--dry-run Print generated values without inserting
--only Comma-separated list of tables to populate (e.g. Author,Book)
--exclude Comma-separated list of tables to skip
--quiet Suppress non-fatal warnings (e.g., wipe destruction warning)
--verbose Print debug output
--help Show this help
DATA MANAGEMENT METHODS
The script provides three ways to prepare your database:
- --truncate (Recommended)
-
Quickly empties all tables while preserving table structures, indexes, foreign keys, and sequences. Ideal for test suites that need fresh data between runs without the overhead of schema recreation.
- --wipe (Use with caution)
-
Drops and recreates all tables from scratch. This is destructive and slower than truncate, but useful when testing schema deployment or when you need to guarantee a completely clean state.
- --deploy
-
Creates any missing tables without affecting existing data. Safe to call multiple times.
For most testing scenarios, --truncate combined with --generate provides the best balance of speed and safety.
ADVANCED OPTIONS
Rows Per Table
--rows-per-table '{"Author":10,"Book":3}'
Allows different row counts for specific tables. Tables not specified use the global --rows value.
Custom Generators
--generators '{"email":"user{row}@example.com","status":"active"}'
Provides custom value generation for specific columns. The syntax supports:
* Static values: "active", "pending"
* Row number interpolation: "user{row}@example.com" becomes user1@example.com
* Perl code evaluation: "sub { return 'prefix_' . int(rand(1000)) }"
For complex generators, use Perl code syntax:
--generators '{"email":"sub { my ($col,$info,$n,$mock)=@_; return \"user$n\@example.com\"; }"}'