2017 © Pedro Peláez
 

library rad-development-bundle

Development Bundle includes Seeders and Sql sync tools.

image

windwalker/rad-development-bundle

Development Bundle includes Seeders and Sql sync tools.

  • Monday, January 22, 2018
  • by asika32764
  • Repository
  • 2 Watchers
  • 0 Stars
  • 37 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Windwalker Joomla RAD Development Bundle

Some helpful command line tools to operate database for development., (*1)

Table of Content

Installation via Composer

``` bash cd /to/your/joomla, (*2)

composer create-project windwalker/rad-development-bundle libraries/windwalker-bundles/DevelopmentBundle 1.*, (*3)


## Commands ``` bash Windwalker Console - version: 2.1 ------------------------------------------------------------ # system commands ... seed The data seeder help you create fake data. import Import seeders. clear Clear seeders. sql SQL sync & diff tools. backup Backup sql. col Column operation export Export sql. import Import a sql file. profile Profiles. restore Restore to pervious point. table Model operation.

SQL Sync

Windwalker Sqlsync is a powerful SQL compare & diff tools help developers update their SQL schema., (*4)

Why Not Migration Tools?

Actually, we are developing a migration tools for Joomla & Windwalker now, but migration is not so suitable for Joomla CMS, sometimes we will want to sync Joomla articles, modules, extensions and menus to your production server. Migration tools are hard to do this., (*5)

So, using Sqlsync tools will help you compare sql schema between your local & remote machine, simply run export in your local, and git track all schema YAML files. Then push your files to remote server and run import, all schemas will update to remote., (*6)

Currently Sqlsync are weak on column name change, you can use hooks to do this., (*7)

Export & Import SQL Schema

``` bash php bin/windwalker sql export, (*8)

php bin/windwalker sql import, (*9)


Scheam will export to `resources/sqlsync/default/schema.yml` ### Track Tables Table track information stores in `resources/sqlsync/default/track.yml` Default is: ``` yaml table: '#__assets': all '#__associations': all '#__banner_clients': all '#__banner_tracks': all '#__banners': all '#__categories': all '#__contact_details': all '#__content': all '#__content_frontpage': all '#__content_rating': all '#__content_types': all '#__contentitem_tag_map': all '#__core_log_searches': all '#__extensions': all '#__finder_filters': cols '#__finder_links': cols '#__finder_links_terms0': cols '#__finder_links_terms1': cols '#__finder_links_terms2': cols '#__finder_links_terms3': cols '#__finder_links_terms4': cols '#__finder_links_terms5': cols '#__finder_links_terms6': cols '#__finder_links_terms7': cols '#__finder_links_terms8': cols '#__finder_links_terms9': cols '#__finder_links_termsa': cols '#__finder_links_termsb': cols '#__finder_links_termsc': cols '#__finder_links_termsd': cols '#__finder_links_termse': cols '#__finder_links_termsf': cols '#__finder_taxonomy': cols '#__finder_taxonomy_map': cols '#__finder_terms': cols '#__finder_terms_common': all '#__finder_tokens': cols '#__finder_tokens_aggregate': cols '#__finder_types': cols '#__languages': all '#__menu': all '#__menu_types': all '#__messages': all '#__messages_cfg': all '#__modules': all '#__modules_menu': all '#__newsfeeds': all '#__overrider': all '#__postinstall_messages': all '#__redirect_links': all '#__schemas': all '#__session': cols '#__tags': all '#__template_styles': all '#__ucm_base': all '#__ucm_content': all '#__ucm_history': all '#__update_sites': all '#__update_sites_extensions': all '#__updates': cols '#__user_keys': all '#__user_notes': all '#__user_profiles': all '#__user_usergroup_map': all '#__usergroups': all '#__users': all '#__utf8_conversion': all '#__viewlevels': all

There are 3 track rules:, (*10)

  • all - Track all data, always refresh data when import & export.
  • cols - Only track table columns, do not refresh data.
  • none - Ignore this table

All table which not list in track.yml will be none., (*11)

Sync Track Tables

If you installed a new component, there may be multiple tables added to ypur database, you can run:, (*12)

``` bash php bin/windwalker sql table sync, (*13)


To auto add all non-tracked table to `track.yml` ### Status This command help you check table track information. ``` bash php bin/windwalker sql status

p-2016-04-05-006, (*14)

Profiles

You can change profile by use, (*15)

``` bash, (*16)

List profile

php bin/windwalker sql profile, (*17)

Create & checkout profile

php bin/windwalker sql profile create test php bin/windwalker sql profile checkout test, (*18)


Now you can export schema to other profile, this is very similar to git branches. ### Quick import & export to profile You don't need to always checkout profiles, add profiles as arguments in commands. ``` bash # Single profile php bin/windwalker sql export test # Multiple profiles php bin/windwalker sql export default foo bar test # Ignore checking prompt php bin/windwalker sql export default foo bar test -y # Export all profiles php bin/windwalker sql export --all -y

This operations can support export / import both commands., (*19)

Rename Column

Modify From property in your schema files., (*20)

``` yaml columns: oldname: { Field: newname, ... , From: [oldname, oldname2] }, (*21)


All oldnames in `From` property will convert to `newname` > Currently Sqlsync are weak on column name change, try avoid to do this operation. ### Export & Import Hooks Add these files to profile folder. ``` php pre-export.php post-export.php pre-import.php post-import.php

And simply write your script to do something., (*22)

``` php // resources/sqlsync/default/pre-import.php, (*23)

if (!JFactory::getConfig()->get('debug')) { throw new \Exception('STOP importing, please enable debug mode to do any DB operations.'); }, (*24)

// Or do some advanced DB actions, for instance, rename column or remove indexes. JFactory::getDbo()->setQuery('ALTER TABLE ...')->execute();, (*25)


## Seeder Windwalker Developement Bundle provides a simple seeder and faker tools to help you generate fake data. Open `resources/seeders/DatabaseSeeder.php`, you will see `DatabaseSeeder` default class: Add a new seeder class at `resources/seeders/ProductSeeder.php` ``` php use Faker\Factory; use Windwalker\Data\Data; use Windwalker\DataMapper\DataMapper; class ProductSeeder extends \DevelopmentBundle\Seeder\AbstractSeeder { public function doExecute() { $faker = Factory::create(); $mapper = new DataMapper('#__mycomponent_products'); $categories = (new DataMapper('#__categories'))->findColumn('id', ['extension' => 'com_mycomponent']); $userIds = (new DataMapper('#__users'))->id; foreach (range(1, 200) as $i) { $data = new Data; $user_id = JFactory::getUser()->id; $data['catid'] = $faker->randomElement($categories); $data['title'] = $faker->sentence(rand(3, 5)); $data['alias'] = JFilterOutput::stringURLSafe($data['title']); $data['temperature'] = $faker->randomElement(['normal', 'refrigeration', 'freeze']); $data['price'] = rand(5000, 10000)/100; $data['location'] = $faker->country; $data['description'] = $faker->paragraph(5); $data['image'] = $faker->imageUrl(); $data['state'] = $faker->randomElement([1, 1, 1, 1, 1, 0]); $data['created'] = $faker->dateTimeThisMonth->format('Y-m-d H:i:s'); $data['created_by'] = $faker->randomElement($userIds); $data['modified'] = $faker->dateTimeThisMonth->format('Y-m-d H:i:s'); $data['modified_by'] = $faker->randomElement($userIds); $data['params'] = ''; $mapper->createOne($data); $this->command->out('.', false); } $this->command->out(); } public function doClear() { $this->truncate('#__mycomponent_products'); } }

And set this class to DatabaseSeeder, you must sort seeders by denpendencies., (*26)

``` php // ..., (*27)

public function doExecute()
{
    $this->execute(new CategorySeeder);

    $this->execute(new ProductSeeder);

    $this->execute(new OrderSeeder);
}

public function doClear()
{
    $this->clear(new CategorySeeder);

    $this->clear(new ProductSeeder);

    $this->clear(new OrderSeeder);
}

Now run seeder by: ``` bash php bin/windwalker seed import

Or clear it, (*28)

bash php bin/windwalker seed export, (*29)

The Versions

22/01 2018

dev-master

9999999-dev

Development Bundle includes Seeders and Sql sync tools.

  Sources   Download

GNU Lesser General Public License

The Requires

 

29/04 2017

1.0.5

1.0.5.0

Development Bundle includes Seeders and Sql sync tools.

  Sources   Download

GNU Lesser General Public License

The Requires

 

10/04 2017

1.0.4

1.0.4.0

Development Bundle includes Seeders and Sql sync tools.

  Sources   Download

GNU Lesser General Public License

The Requires

 

15/12 2016

1.0.3

1.0.3.0

Development Bundle includes Seeders and Sql sync tools.

  Sources   Download

GNU Lesser General Public License

The Requires

 

03/06 2016

1.0.2

1.0.2.0

Development Bundle includes Seeders and Sql sync tools.

  Sources   Download

GNU Lesser General Public License

The Requires

 

05/04 2016

1.0.1

1.0.1.0

Development Bundle includes Seeders and Sql sync tools.

  Sources   Download

GNU Lesser General Public License

The Requires

 

01/04 2016

1.0.0

1.0.0.0

Development Bundle includes Seeders and Sql sync tools.

  Sources   Download

GNU Lesser General Public License

The Requires