2017 © Pedro Peláez
 

cakephp-plugin cakephp-schema

Schema saving and loading from file for CakePHP 3.0

image

scherersoftware/cakephp-schema

Schema saving and loading from file for CakePHP 3.0

  • Friday, January 12, 2018
  • by cleptric
  • Repository
  • 7 Watchers
  • 1 Stars
  • 6,764 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 5 Versions
  • 7 % Grown

The README.md

This repo is not maintained anymore

For current versions please try the original https://github.com/Laykou/cakephp-schema or a successor of this one: https://github.com/raul338/cakephp-schema, (*1)

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., (*2)

Supported datasources

  • Postgres
  • MySQL
  • SQL Server
  • ~~SQLite~~ not yet

Installation

You can install this plugin into your CakePHP application using composer., (*3)

The recommended way to install composer packages is:, (*4)

composer require scherersoftware/cakephp-schema

Update your `config/bootstrap.php``:, (*5)

Plugin::load('Schema', ['bootstrap' => true]);

Usage

The plugin saves the schema of the default connection to the config/schema.php file. The structure is similiar to the fixtures fields., (*6)

cake schema save

To load the schema back execute, (*7)

cake schema load

All existing tables in the database are dropped before loading. You will be asked, (*8)

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, (*9)

cake schema load --no-interaction

Seed

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:, (*10)

<?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., (*11)

You can use the schema generateseed command to automatically generate a seed.php file based on your database contents., (*12)

Use schema seed for importing the contents of the seed.php into your DB., (*13)

Seed commands will take the following options:, (*14)

  • connection Database connection to use.
  • seed Path to the seed file to generate (Defaults to "config/seed.php")
  • path Path to the schema.php file (Defaults to "config/schema.php")

Other examples

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

Seeding Examples

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., (*15)

Example usage:, (*16)

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., (*17)

TODO

  • [x] Auto-creation of the schema.php file after cake migrations migrate
  • [x] Data seeding
  • [ ] Tests
  • [ ] More options and configuration
  • [ ] Refactoring and cleaning the code

Known issues

  • SQLite is not fully supported

The Versions

12/01 2018

dev-master

9999999-dev https://github.com/scherersoftware/cakephp-schema

Schema saving and loading from file for CakePHP 3.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ladislav Gallay
by Robert Scherer

orm database migrations schema cakephp

20/10 2017

v1.1

1.1.0.0 https://github.com/scherersoftware/cakephp-schema

Schema saving and loading from file for CakePHP 3.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ladislav Gallay
by Robert Scherer

orm database migrations schema cakephp

18/05 2016

v1.0.1

1.0.1.0 https://github.com/scherersoftware/cakephp-schema

Schema saving and loading from file for CakePHP 3.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ladislav Gallay
by Robert Scherer

orm database migrations schema cakephp

08/10 2015

v1.0.0

1.0.0.0 https://github.com/scherersoftware/cakephp-schema

Schema saving and loading from file for CakePHP 3.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ladislav Gallay
by Robert Scherer

orm database migrations schema cakephp

07/10 2015

v0.1

0.1.0.0 https://github.com/scherersoftware/cakephp-schema

Schema saving and loading from file for CakePHP 3.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ladislav Gallay
by Robert Scherer

orm database migrations schema cakephp