This repo is not maintained anymore
Schema plugin for CakePHP 3.0
Save the schema into one file and then restore the database from the schema file. The schema is automatically saved when executing
cake migrations migrate.
- SQL Server
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require scherersoftware/cakephp-schema
Update your `config/bootstrap.php``:
Plugin::load('Schema', ['bootstrap' => true]);
The plugin saves the schema of the
default connection to the
config/schema.php file. The structure is similiar to the fixtures fields.
cake schema save
To load the schema back execute
cake schema load
All existing tables in the database are dropped before loading. You will be asked
Loading the schema from the file Database is not empty. 37 tables will be deleted. Do you want to continue? (y/n)
To disable the question (and answer with yes) run
cake schema load --no-interaction
The Schema plugin allows you to seed data from the
config/seed.php file. The
seed.php file should return array of tables and rows:
<?php // You can work with custom libraries here or use the Cake's ORM return [ 'articles' => [ [ 'id' => 1, 'category_id' => 1, 'label' => 'CakePHP' ], [ 'id' => 2, 'label' => 'Schema plugin', 'json_type_field' => [ 'i' => 'will convert', 'to' => 'json' ] ] ], 'categories' => [ [ 'id' => 2, 'label' => 'Frameworks' ] ] ];
The Seed commands support the CakePHP ORM's type mapping. So for example, if you're using the JsonType example from the cookbook, the seed commands will automatically convert an array to JSON.
You can use the
schema generateseed command to automatically generate a seed.php file based on your database contents.
schema seed for importing the contents of the
seed.php into your DB.
Seed commands will take the following options:
connectionDatabase connection to use.
seedPath to the seed file to generate (Defaults to "config/seed.php")
pathPath to the schema.php file (Defaults to "config/schema.php")
cake schema save --connection test cake schema save --path config/schema/schema.lock cake schema load --connection test --path config/schema/schema.lock --no-interaction
To only drop all tables in database
cake schema drop cake schema drop --connection test
cake schema seed --truncate cake schema generateseed --seed config/my_seed.php
Seeding for Migrations Plugin / phinx
This plugin provides a bake task extending the
seed bake task provided by the
cakephp/migrations plugin, but with automated inclusion of seed data from the database.
bin/cake bake migration_seed Users --records
This will write a new file into
src/config/Seeds/UsersSeed.php including all records currently present in the DB's users table.
- Auto-creation of the schema.php file after
cake migrations migrate
- Data seeding
- More options and configuration
- Refactoring and cleaning the code
- SQLite is not fully supported