cyberrebell / doctrine-db-patcher

dev-master 2014-06-20 21:39 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:02:55 UTC


README

## doctrine-db-patcher 为您的 ZF2+Doctrine-Project 提供一套数据库补丁工具集。

===================

### DoctrineDbPatcher

#### 要求:php >=5.4

ZF2: https://github.com/zendframework/zf2

DoctrineMongoODMModule: https://github.com/doctrine/DoctrineMongoODMModule

或者

DoctrineORMModule: https://github.com/doctrine/DoctrineORMModule

#### 使用 composer 安装:在 composer.json 中添加

    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/Cyberrebell/doctrine-db-patcher"
        }
    ],
    "require": {
        "Cyberrebell/doctrine-db-patcher": "dev-master"
    },

#### 项目配置:在 application.config.php 中添加

return [
    'modules' => [
        'DoctrineDbPatcher'
    ]
];

添加到任何 module.config.php

return [
    'DoctrineDbPatcher' => [
        'doctrine-objectmanager-service' => 'Doctrine\ODM\Mongo\DocumentManager', //or Doctrine\ORM\EntityManager
        'patches' => include 'doctrine.patches.php'
    ]
];

创建 doctrine.patches.php 并添加您的补丁,如下所示

<?php 
return [
    '1.0.0' => [
        'insert' => [
            'User\Entity\Resource' => [
                'attributes' => ['route'],
                'values' => [
                    ['login'],
                    ['logout'],
                ]
            ],
            'User\Entity\Permission' => [
                'attributes' => ['description'],
                'values' => [
                    ['Sich einloggen'],
                    ['Sich ausloggen'],
                ]
            ],
        ],
        'update' => [
             'User\Entity\Guestbook' => [
                 [
                     'attributes' => ['title'],
                     'values' => [
                         ['old' => ['This is a niec website'], 'new' => ['This is a nice website']],
                     ]
                 ],
             ],
        ],
        'delete' => [
             'User\Entity\Guestbook' => [
                 [
                     'attributes' => ['title'],
                     'values' => [
                         ['Hello everyone'],
                     ]
                 ],
             ],
        ],
        'connect' => [
            [
                'entities' => ['User\Entity\Permission' => 'User\Entity\Resource'],
                'methods' => ['addResource' => 'removeResource'],
                'targets' => [
                    ['source' => ['description' => 'Sich einloggen'], 'target' => ['route' => 'login']],
                    ['source' => ['description' => 'Sich ausloggen'], 'target' => ['route' => 'logout']],
                ]
            ]
        ]
    ]
];

#### 项目配置:运行补丁工具

php public/index.php dbpatch