Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 76 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ Yii 2 Database Toolkit
About
-----


### [dmstr\db\behaviors\HydratedAttributes](https://github.com/dmstr/yii2-db/blob/master/db/behaviors/HydratedAttributes.php)

Retrieves all eager loaded attributes of a model including relations. Once the extension is installed, simply use it in your code by accessing the corresponding classes by their full namespaced path.

### [dmstr\db\mysql\FileMigration](https://github.com/dmstr/yii2-db/blob/master/db/mysql/FileMigration.php)

runs database migrations from `sql` files


- Generic database exentsions
- Hydrated Attributes
- Database extensions for MySQL
Expand All @@ -25,7 +35,7 @@ The preferred way to install this extension is through [composer](http://getcomp
Either run

```
php composer.phar require --prefer-dist dmstr/yii2-db "*"
composer require --prefer-dist dmstr/yii2-db "*"
```

or add
Expand All @@ -36,87 +46,109 @@ or add

to the require section of your `composer.json` file.

Commands
--------
Configuration
-------------

### [dmstr\console\controllers](https://github.com/dmstr/yii2-db/blob/master/console/controllers)

Include it in your console configuration

```
'controllerMap' => [
'db' => [
'class' => 'dmstr\console\controllers\MysqlController',
'noDataTables' => [
'app_log',
'app_session',
]
],
],
```

Usage
-----

### Commands

### `yii db`
#### `yii migrate ...`

Create a file migration class

```
yii migrate/create \
--templateFile='@vendor/dmstr/yii2-db/db/mysql/templates/file-migration.php' init_dump
```


#### `yii db ...`

```
DESCRIPTION

MySQL database maintenance command.
MySQL database maintenance command for current (db) connection


SUB-COMMANDS

- db/create Create MySQL database
- db/destroy Remove the current schema
- db/dump Dumps current database tables to runtime folder
- db/export export data tables, without logs and caches
- db/import
- db/create Create schema
- db/destroy Remove schema
- db/dump Dump schema (all tables)
- db/export Export tables (INSERT only)
- db/import Import from file to database and flush cache
- db/index (default) Displays tables in database
- db/wait-for-connection

To see the detailed information about individual sub-commands, enter:

yii help <sub-command>

```


Usage
-----

### [dmstr\db\behaviors\HydratedAttributes](https://github.com/dmstr/yii2-db/blob/master/db/behaviors/HydratedAttributes.php)
Show help

Retrieves all eager loaded attributes of a model including relations. Once the extension is installed, simply use it in your code by accessing the corresponding classes by their full namespaced path.
```
yii help db
```

### [dmstr\db\mysql\FileMigration](https://github.com/dmstr/yii2-db/blob/master/db/mysql/FileMigration.php)

runs database migrations from `sql` files
### Examples

Create a file migration class
Dry-run command (not available for all commands)

```
./yii migrate/create \
--templateFile='@vendor/dmstr/yii2-db/db/mysql/templates/file-migration.php' init_dump
yii db/create root secret -n
```

### [dmstr\console\controllers](https://github.com/dmstr/yii2-db/blob/master/console/controllers)

Include it in your console configuration
Destroy database

```
'controllerMap' => [
'db' => [
'class' => 'dmstr\console\controllers\MysqlController',
'noDataTables' => [
'app_log',
'app_session',
]
],
],
yii db/destroy root secret
```

Show help
Dump all tables

```
./yii help db
```

Available commands

yii db/dump -o /dumps
```
DESCRIPTION

MySQL database maintenance command.
Dump from different connection, exclude logging tables

```
yii db/dump -o /dumps \
--db=dbReadonly \
--noDataTables=app_audit_data,app_audit_entry,app_audit_error,app_audit_javascript,app_audit_mail
```

SUB-COMMANDS
Dump from secondary connection, import into primary (default)

- db/create Create MySQL database from ENV vars and grant permissions
- db/dump Dumps current database tables to runtime folder
- db/index (default) Displays tables in database
```
yii db/dump -o /dumps \
--db=dbReadonly \
--noDataTables=app_audit_data,app_audit_entry,app_audit_error,app_audit_javascript,app_audit_mail \
| xargs yii db/import --interactive=0
```


---

Expand Down
Loading