### Run Phinx Example Web Server Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/commands.rst Demonstrates how to start a local PHP web server to run the example Phinx web application, which provides basic migration status, migrate, and rollback functionalities via HTTP endpoints. ```bash $ php -S localhost:8000 vendor/robmorgan/phinx/app/web.php ``` -------------------------------- ### Running Phinx Migrations in PHPUnit setUp Method Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/commands.rst This example illustrates how to integrate Phinx migrations into a PHPUnit test setup. By instantiating `PhinxApplication` and running the 'migrate' command within the `setUp` method, the database can be prepared or reset before each test, ensuring a consistent testing environment. `setAutoExit(false)` prevents the application from exiting after the command. ```php public function setUp () { $app = new PhinxApplication(); $app->setAutoExit(false); $app->run(new StringInput('migrate'), new NullOutput()); } ``` -------------------------------- ### Install Phinx using Composer Source: https://github.com/cakephp/phinx/blob/0.x/README.md This snippet provides the step-by-step commands to install Phinx as a project dependency using Composer. It covers downloading Composer, requiring Phinx, installing project dependencies, and executing the Phinx binary from the vendor directory. ```Shell curl -sS https://getcomposer.org/installer | php ``` ```Shell php composer.phar require robmorgan/phinx ``` ```Shell php composer.phar install ``` ```Shell php vendor/bin/phinx ``` -------------------------------- ### Initialize Docker Development Environment for Phinx Source: https://github.com/cakephp/phinx/blob/0.x/CONTRIBUTING.md For developers who prefer not to install MySQL and PostgreSQL locally, this command uses `docker-compose` to download necessary images, build, and start a Phinx development container. The `--rm` flag ensures the container is removed after it exits. ```shell docker-compose run --rm phinx ``` -------------------------------- ### Initialize Phinx Project Configuration Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/install.rst After installing Phinx, this command initializes the necessary configuration file (`phinx.php`) and sets up the default directory structure, typically `db/migrations`, where your migration files will reside. Ensure these folders have adequate write permissions. ```bash vendor/bin/phinx init ``` -------------------------------- ### Install Composer Globally Source: https://github.com/cakephp/phinx/blob/0.x/CONTRIBUTING.md This command downloads and executes the Composer installer script. Composer is a dependency manager for PHP, essential for setting up the Phinx development environment. ```shell curl -sS https://getcomposer.org/installer | php ``` -------------------------------- ### Install Phinx PHP Dependencies Source: https://github.com/cakephp/phinx/blob/0.x/CONTRIBUTING.md After cloning the Phinx repository, this command uses Composer to install all required PHP dependencies. It ensures that the project has all necessary libraries to run and develop. ```shell php composer.phar install ``` -------------------------------- ### Phinx PHP Configuration with PDO Instance Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/commands.rst An example of a Phinx configuration file in PHP, showing how to provide an existing PDO instance for the database connection, along with the database name. ```php [ "migrations" => "application/migrations" ), "environments" => [ "default_migration_table" => "phinxlog", "default_environment" => "dev", "dev" => [ "name" => "dev_db", "connection" => $pdo_instance ] ] ]; ``` -------------------------------- ### Phinx PHP Configuration with Full Database Details Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/commands.rst An example of a Phinx configuration file written in PHP, demonstrating how to define paths for migrations and environments with complete database connection parameters, including environment variables. ```php [ "migrations" => "application/migrations" ], "environments" => [ "default_migration_table" => "phinxlog", "default_environment" => "dev", "dev" => [ "adapter" => "mysql", "host" => $_ENV['DB_HOST'], "name" => $_ENV['DB_NAME'], "user" => $_ENV['DB_USER'], "pass" => $_ENV['DB_PASS'], "port" => $_ENV['DB_PORT'] ] ] ]; ``` -------------------------------- ### Phinx YAML Configuration with DSN Example Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Illustrates how to configure database environments in Phinx using a YAML file, demonstrating a DSN string for a production MySQL database connection. ```yaml environments: default_migration_table: phinxlog default_environment: development production: # Example data source name dsn: mysql://root@localhost:3306/mydb?charset=utf8 ``` -------------------------------- ### Phinx Namespaced PHP Migration File Example Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/namespaces.rst An example of a Phinx migration file with a defined namespace, matching a namespaced path configured in Phinx. ```php table('users'); $table->addColumn('name', 'string')->create(); } } ``` -------------------------------- ### Phinx CLI Migration Creation Command Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/namespaces.rst Command-line example for creating a new Phinx migration, including how to specify a target path for namespaced migrations. ```cli phinx create CreateUsersTable [--path ./src/FoorBar/db/migrations] ``` -------------------------------- ### Install Phinx via Composer Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/install.rst This command uses Composer, PHP's dependency manager, to add the `robmorgan/phinx` package to your project. Phinx requires PHP 8.1 or later to function correctly. ```bash php composer.phar require robmorgan/phinx ``` -------------------------------- ### Build Phinx as a Standalone Phar Archive Source: https://github.com/cakephp/phinx/blob/0.x/README.md This snippet outlines the process to build a standalone Phar archive for Phinx using the Box application. It involves cloning the Phinx repository, installing Composer and its dependencies, installing Box, and finally building the executable Phar file. ```Shell git clone https://github.com/cakephp/phinx.git cd phinx ``` ```Shell curl -s https://getcomposer.org/installer | php ``` ```Shell php composer.phar install ``` ```Shell curl -LSs https://box-project.github.io/box2/installer.php | php ``` ```Shell php box.phar build ``` -------------------------------- ### Phinx Non-Namespaced PHP Migration File Example Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/namespaces.rst An example of a Phinx migration file without a namespace, typically located in a non-namespaced path configured in Phinx. ```php table('users'); $table->addColumn('name', 'string')->create(); } } ``` -------------------------------- ### Configure Phinx with PDO Connection in PHP Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Demonstrates how to configure Phinx using a PHP file, returning an array. This example shows how to integrate an existing PDO instance for database connection, allowing migrations to share the application's database connection. This approach is useful for sharing the same connection with your application, but requires explicitly passing the database name as Phinx cannot infer it from PDO. ```php $app = require 'app/phinx.php'; $pdo = $app->getDatabase()->getPdo(); return [ 'environments' => [ 'default_environment' => 'development', 'development' => [ 'name' => 'devdb', 'connection' => $pdo ] ] ]; ``` -------------------------------- ### Phinx SQLite Database Configuration Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Provides examples for configuring SQLite databases in Phinx YAML, showing how to specify a file-based database with a custom suffix and how to configure an in-memory SQLite database for testing purposes. ```yaml environments: development: adapter: sqlite name: ./data/derby suffix: ".db" # Defaults to ".sqlite3" testing: adapter: sqlite memory: true # Setting memory to *any* value overrides name ``` -------------------------------- ### Truncate Table in Phinx Seed Class Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/seeding.rst Example of using the `TRUNCATE` command within a Phinx seed class to empty a database table. This snippet shows the start of a `run()` method for a `UserSeeder`. ```php 'foo', 'created' => date('Y-m-d H:i:s'), ] ``` -------------------------------- ### Configuring Phinx with PDO for In-Memory SQLite in PHPUnit Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/commands.rst This comprehensive example demonstrates how to set up Phinx within a PHPUnit `DatabaseTestCase` to work with an in-memory SQLite database using a specific PDO instance. It shows how to dynamically configure Phinx with a custom connection, then use the `Manager` class to run migrations and seed the database for testing purposes, providing fine-grained control over the database state. ```php use PDO; use Phinx\Config\Config; use Phinx\Migration\Manager; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\NullOutput; class DatabaseTestCase extends TestCase { public function setUp () { $pdo = new PDO('sqlite::memory:', null, null, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]); $configPath = __DIR__ . '/../phinx.php'; $configArray = require $configPath; $configArray['environments']['test'] = [ 'adapter' => 'sqlite', 'connection' => $pdo, 'name' => ':memory:', ]; $config = new Config( $configArray, $configPath ); $manager = new Manager($config, new StringInput(' '), new NullOutput()); $manager->migrate('test'); $manager->seed('test'); $this->pdo = $pdo; // You can change default fetch mode after the seeding $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); } } ``` -------------------------------- ### Define Phinx Seed Class Dependencies Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/seeding.rst Example of a Phinx seed class implementing `getDependencies()` to specify the order in which seeders should run, ensuring foreign key constraints are met. Dependencies are only considered when running all seed classes. ```php [ "development" => [ "adapter" => "mysql", # other adapter settings "attr_case" => \PDO::ATTR_CASE, "mysql_attr_ignore_space" => 1, ], ], ]; ``` -------------------------------- ### Creating an Annotated Git Tag for Phinx Release Source: https://github.com/cakephp/phinx/wiki/Releasing-a-new-version-of-Phinx This command demonstrates how to create an annotated Git tag for a new Phinx version. The tag includes the version number and a descriptive message, which is crucial for release management and tracking. ```Shell git tag -a 0.4.1 -m 'Tagging release 0.4.1' ``` -------------------------------- ### Phinx AbstractSeed Class API Reference Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/seeding.rst Detailed API documentation for the `Phinx\Seed\AbstractSeed` class, outlining its core methods used for database seeding. ```APIDOC Phinx\Seed\AbstractSeed: Methods: run(): void Description: Automatically invoked by Phinx when `seed:run` command is executed. Use this method to insert test data. Unlike migrations, Phinx does not track which seed classes have been run, allowing repeated execution. init(): void Description: Run by Phinx before the `run` method if it exists. Can be used to initialize properties of the Seed class. shouldExecute(): bool Description: Run by Phinx before executing the seed. Can be used to prevent the seed from being executed at this time. Returns true by default. Can be overridden in custom `AbstractSeed` implementations. getDependencies(): array Description: Returns an array of seeders that must run before the current seeder. Used to define execution order and manage foreign key dependencies. Only considered when executing all seed classes. ``` -------------------------------- ### Phinx Create Command Usage Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/commands.rst The `create` command generates a new migration file. It requires a CamelCase name for the migration and supports specifying custom templates or template-generating classes. ```bash $ phinx create MyNewMigration ``` ```bash $ phinx create MyNewMigration --template=\"\" ``` ```bash $ phinx create MyNewMigration --class=\"\" ``` -------------------------------- ### Phinx YAML Basic Path Configuration Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/namespaces.rst Illustrates the basic 'paths' configuration in a Phinx YAML configuration file, defining directories for migrations and seeds. ```yaml paths: migrations: ./database/migrations seeds: ./database/seeds ``` -------------------------------- ### Phinx PHP Basic Path Configuration Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/namespaces.rst Illustrates the basic 'paths' configuration in a Phinx PHP configuration file, defining directories for migrations and seeds. ```php 'paths' => [ 'migrations' => 'database/migrations', 'seeds' => 'database/seeds', ], ``` -------------------------------- ### Phinx JSON Basic Path Configuration Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/namespaces.rst Illustrates the basic 'paths' configuration in a Phinx JSON configuration file, defining directories for migrations and seeds. ```json { "paths": { "migrations": "database/migrations", "seeds": "database/seeds" } } ``` -------------------------------- ### Run Phinx Seed Classes Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/commands.rst Executes database seed classes. It can run all available seeders or a specific one by name. ```bash $ phinx seed:run -e development ``` ```bash $ phinx seed:run -e development -s MyNewSeeder ``` -------------------------------- ### Create New Phinx Seeder Class Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/commands.rst Generates a new database seeder class file. The class name must be provided in CamelCase. It also supports specifying an alternative template file. ```bash $ phinx seed:create MyNewSeeder ``` ```bash $ phinx seed:create MyNewSeeder --template="" ``` -------------------------------- ### Calling Phinx Migrate Command Programmatically with Symfony Console Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/commands.rst This snippet demonstrates how to programmatically execute Phinx commands, such as 'migrate', from within a PHP application using the Symfony Console component. It shows how to instantiate `PhinxApplication`, find a specific command, define arguments as an `ArrayInput`, and run the command while passing the application's `OutputInterface` for consistent output handling. ```php use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Phinx\Console\PhinxApplication; // ... protected function execute(InputInterface $input, OutputInterface $output) { $phinx = new PhinxApplication(); $command = $phinx->find('migrate'); $arguments = [ 'command' => 'migrate', '--environment' => 'production', '--configuration' => '/path/to/phinx/config/file' ]; $input = new ArrayInput($arguments); $returnCode = $command->run(new ArrayInput($arguments), $output); // ... } ``` -------------------------------- ### Phinx Abstract Seed Class Skeleton Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/seeding.rst Basic structure of a Phinx seed class, extending `AbstractSeed`. The `run()` method is where database seeding logic should be implemented. ```php registerAdapter($name, $class); ``` -------------------------------- ### Phinx Migrate Command Usage Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/commands.rst The `migrate` command executes all available database migrations, or optionally migrates up to a specified version. It also supports a dry-run mode to preview SQL queries without execution. ```bash $ phinx migrate -e development ``` ```bash $ phinx migrate -e development -t 20110103081132 ``` ```bash $ phinx migrate --dry-run ``` -------------------------------- ### Execute Phinx Unit Tests within Docker Container Source: https://github.com/cakephp/phinx/blob/0.x/CONTRIBUTING.md This command runs the Phinx unit tests using PHPUnit from within the Docker development container. It's an alternative to running tests locally, especially useful when database dependencies are managed via Docker. ```shell vendor/bin/phpunit ``` -------------------------------- ### Bash Phinx Run Multiple Seed Classes Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/seeding.rst Command-line instruction to execute several specific Phinx seed classes by repeating the `-s` parameter for each class name. ```bash $ php vendor/bin/phinx seed:run -s UserSeeder -s PermissionSeeder -s LogSeeder ``` -------------------------------- ### Generate New Phinx Seed Class Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/seeding.rst Command-line instruction to create a new Phinx seed class. If multiple seed paths are configured, the user will be prompted to select one. ```bash $ php vendor/bin/phinx seed:create UserSeeder ``` -------------------------------- ### Phinx Database Adapter Configuration Settings Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Documents the common configuration settings available for Phinx database adapters, including `adapter`, `host`, `port`, `user`, `pass`, `name`, `suffix`, and `schema`. These settings control how Phinx connects to and interacts with various database systems. ```APIDOC adapter: The name of the adapter to use, e.g. `pgsql`. host: The database server's hostname (or IP address). port: The database server's TCP port number. user: The username for the database. pass: The password for the database. name: The name of the database for this environment. For SQLite, it's recommended to use an absolute path, without the file extension. suffix: The suffix to use for the SQLite database file. Defaults to `.sqlite3`. schema: For PostgreSQL, allows specifying the schema to use for the database. Defaults to `public`. ``` -------------------------------- ### Phinx SQLite URI Scheme Configuration with Mode Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Illustrates configuring an SQLite database in Phinx using the URI scheme, specifically demonstrating the `mode` query parameter to control database opening behavior (e.g., in-memory, read-only, read-write). ```yaml environments: testing: adapter: sqlite name: my_app mode: memory # Determines if the new database is opened read-only, read-write, read-write and created if it does not exist, or that the database is a pure in-memory database that never interacts with disk, respectively. ``` -------------------------------- ### Variables Available in Phinx Bootstrap Script Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Documents the predefined variables that are automatically available within the PHP bootstrap script configured for Phinx. These variables provide access to the configuration filename, absolute file path, Symfony Console input/output objects, and the executing command context. ```APIDOC /** * @var string $filename The file name as provided by the configuration * @var string $filePath The absolute, real path to the file * @var \Symfony\Component\Console\Input\InputInterface $input The executing command's input object * @var \Symfony\Component\Console\Output\OutputInterface $output The executing command's output object * @var \Phinx\Console\Command\AbstractCommand $context the executing command object */ ``` -------------------------------- ### Specify Multiple Seed Paths in YAML Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Illustrates how to define multiple seed directories by providing an array of paths in the Phinx YAML configuration. This allows Phinx to discover seed files from various locations, supporting modular application structures for data seeding. ```yaml paths: seeds: - /your/full/path1 - /your/full/path2 ``` -------------------------------- ### PHP Phinx Data Insertion and Truncation Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/seeding.rst Demonstrates how to insert multiple rows of data into a database table using Phinx's `insert` method and then clear all records from the table using `truncate`. It notes that SQLite uses `DELETE FROM` instead of native `TRUNCATE` and recommends manual `VACUUM` for SQLite after truncation. ```php ], [ 'body' => 'bar', 'created' => date('Y-m-d H:i:s'), ] ]; $posts = $this->table('posts'); $posts->insert($data) ->saveData(); // empty the table $posts->truncate(); ``` -------------------------------- ### Phinx PHP Namespaced Path Configuration Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/namespaces.rst Demonstrates how to configure Phinx paths in PHP to support both non-namespaced and namespaced migrations and seeders using an array structure. ```php 'paths' => [ 'migrations' => [ '/path/to/migration/without/namespace', // Non-namespaced migrations 'Foo' => '/path/to/migration/Foo', // Migrations in the Foo namespace ], 'seeds' => [ '/path/to/seeds/without/namespace', // Non-namespaced seeders 'Baz' => '/path/to/seeds/Baz', // Seeders in the Baz namespace ] ], ``` -------------------------------- ### Bash Phinx Run Specific Seed Class Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/seeding.rst Command-line instruction to execute a single, named Phinx seed class by specifying its name with the `-s` parameter. ```bash $ php vendor/bin/phinx seed:run -s UserSeeder ``` -------------------------------- ### Phinx Database Source Name (DSN) Format Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Defines the standard Phinx DSN format for database connections, specifying required and optional components like adapter, user, password, host, port, database name, and additional options. ```APIDOC ://[[:]@][:]/[?] ``` -------------------------------- ### Use External Environment Variables in Phinx Configuration Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Demonstrates how Phinx can automatically use environment variables prefixed with PHINX_ as tokens in the configuration file, enabling secure storage of sensitive credentials outside version control. ```yaml environments: default_migration_table: phinxlog default_environment: development production: adapter: mysql host: '%%PHINX_DBHOST%%' name: '%%PHINX_DBNAME%%' user: '%%PHINX_DBUSER%%' pass: '%%PHINX_DBPASS%%' port: 3306 charset: utf8 ``` -------------------------------- ### Insert Data Using Phinx Table Object Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/seeding.rst Demonstrates how to insert data into a database table within a Phinx seed class using the `table()` method to retrieve a `Table` object and `insert()` followed by `saveData()` to commit the changes. ```php 'foo', 'created' => date('Y-m-d H:i:s'), ],[ 'body' => 'bar', 'created' => date('Y-m-d H:i:s'), ] ]; $posts = $this->table('posts'); $posts->insert($data) ->saveData(); } } ``` -------------------------------- ### Configure Per-Environment Phinx Migration Table Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Illustrates how to specify a unique migration table name for specific Phinx environments, allowing different tables for development and production, while falling back to the default if not specified. ```yaml environment: default_migration_table: phinxlog development: migration_table: phinxlog_dev # rest of the development settings production: # rest of the production settings ``` -------------------------------- ### Check Phinx Migration Status Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/commands.rst Displays the current status of all database migrations, indicating which have been run. It also explains the exit codes for different migration states. ```bash $ phinx status -e development ``` -------------------------------- ### Phinx YAML Configuration with Environment Variable DSN Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Shows how to use environment variables (e.g., '%%DATABASE_URL%%') within Phinx YAML configuration for DSNs, allowing for flexible deployment across different environments. It also demonstrates overriding the database name for a specific environment. ```yaml environments: default_migration_table: phinxlog default_environment: development development: dsn: '%%DATABASE_URL%%' production: dsn: '%%DATABASE_URL%%' name: production_database ``` -------------------------------- ### Configuring Phinx Migration Template Style Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Shows how to specify the template style for new migrations within the Phinx configuration file. Available styles include 'change' (default) or 'up_down', which dictates the structure of the generated migration file. This setting can be overridden via command line options. ```yaml templates: style: up_down ``` -------------------------------- ### Phinx YAML Namespaced Path Configuration Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/namespaces.rst Shows how to configure Phinx paths in YAML to support both non-namespaced and namespaced migrations, using '0' for the non-namespaced path. ```yaml paths: migrations: 0: ./db/migrations Foo\\Bar: ./src/FooBar/db/migrations ``` -------------------------------- ### Phinx JSON Namespaced Path Configuration Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/namespaces.rst Shows how to configure Phinx paths in JSON to support both non-namespaced and namespaced migrations, using '0' for the non-namespaced path. ```json { "paths": { "migrations": { "0": "./db/migrations", "Foo\\Bar": "./src/FooBar/db/migrations" } } } ``` -------------------------------- ### Specify Namespaced Migration Paths in YAML Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Demonstrates how to associate class namespaces with specific migration directories in the Phinx YAML configuration. This is useful for organizing migrations by module or application component, ensuring Phinx correctly loads namespaced migration classes from their respective paths. ```yaml paths: migrations: App\\Module1\\Migrations: application/module1/migrations App\\Module2\\Migrations: application/module2/migrations ``` -------------------------------- ### Specify Relative Migration Path with PHINX_CONFIG_DIR Token Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Shows how to define a migration path relative to the Phinx configuration file's directory using the %%PHINX_CONFIG_DIR%% token in YAML. This token is automatically replaced by Phinx with the root directory of the configuration file, providing flexibility for project structure. ```yaml paths: migrations: '%%PHINX_CONFIG_DIR%%/your/relative/path' ``` -------------------------------- ### Specify Namespaced Seed Paths in YAML Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Demonstrates how to associate class namespaces with specific seed directories in the Phinx YAML configuration. This is useful for organizing seeders by module or application component, ensuring Phinx correctly loads namespaced seed classes from their respective paths. ```yaml paths: seeds: App\\Module1\\Seeds: application/module1/seeds App\\Module2\\Seeds: application/module2/seeds ``` -------------------------------- ### Configure Default Phinx Migration Table Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Demonstrates how to set a global default migration table name for all Phinx environments. If omitted, it defaults to phinxlog. ```yaml environment: default_migration_table: phinxlog ``` -------------------------------- ### Specify Relative Seed Path with PHINX_CONFIG_DIR Token Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Shows how to define a seed path relative to the Phinx configuration file's directory using the %%PHINX_CONFIG_DIR%% token in YAML. This token is automatically replaced by Phinx with the root directory of the configuration file, providing flexibility for project structure. ```yaml paths: seeds: '%%PHINX_CONFIG_DIR%%/your/relative/path' ``` -------------------------------- ### Configure Custom Seeder Template Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Defines how to specify a custom template file path for Phinx seeders in the configuration. ```yaml templates: seedFile: src/templates/customSeederTemplate.php ``` -------------------------------- ### Configure Custom Migration Template Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Defines how to specify a custom template file path for Phinx migrations in the configuration. ```yaml templates: file: src/templates/customMigrationTemplate.php ``` -------------------------------- ### Phinx Breakpoint Command Usage Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/commands.rst The `breakpoint` command in Phinx is used to manage migration breakpoints, which limit rollback operations. It allows toggling breakpoints on the most recent or specific migrations, and removing all existing breakpoints. ```bash $ phinx breakpoint -e development ``` ```bash $ phinx breakpoint -e development -t 20120103083322 ``` ```bash $ phinx breakpoint -e development -r ``` -------------------------------- ### Defining Aliases for Phinx Migration Template Classes Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Illustrates how to alias custom migration template generator classes in the Phinx configuration. These aliases provide a shorthand for using custom template classes with the `--class` command line option. Aliased classes must implement the `Phinx\Migration\CreationInterface`. ```yaml aliases: permission: \Namespace\Migrations\PermissionMigrationTemplateGenerator view: \Namespace\Migrations\ViewMigrationTemplateGenerator ``` -------------------------------- ### Configuring Phinx Feature Flags via PHP Class Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Demonstrates how to programmatically set Phinx feature flags by modifying static properties on the `Phinx\Config\FeatureFlags` class. The flag names are converted to `camelCase` for direct property access, offering an alternative to YAML configuration. ```php Phinx\Config\FeatureFlags::$unsignedPrimaryKeys = false; ``` -------------------------------- ### Configure MySQL Socket Connection in Phinx Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Explains how to configure Phinx to use a Unix socket for MySQL connections instead of a network connection, by specifying the unix_socket path. ```yaml environments: default_migration_table: phinxlog default_environment: development production: adapter: mysql name: production_db user: root pass: '' unix_socket: /var/run/mysql/mysql.sock charset: utf8 ``` -------------------------------- ### Set Custom Seeder Base Class in YAML Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Explains how to specify a custom base class for all seeders in Phinx using the seed_base_class setting in YAML. This custom class must extend Phinx's AbstractSeed and can be used to inject shared functionality, common dependencies, or custom logic into all your seeder files. ```yaml seed_base_class: MyCustomSeeder ``` -------------------------------- ### Set Custom Migration Base Class in YAML Source: https://github.com/cakephp/phinx/blob/0.x/docs/en/configuration.rst Explains how to specify a custom base class for all migrations in Phinx using the migration_base_class setting in YAML. This custom class must extend Phinx's AbstractMigration and can be used to inject shared functionality, common dependencies, or custom logic into all your migration files. ```yaml migration_base_class: MyMagicalMigration ```