initphp/barbarian 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

initphp/barbarian

最新稳定版本:1.0.1

Composer 安装命令:

composer require initphp/barbarian

包简介

Small library that can be used for database migrations.

README 文档

README

Small library that can be used for database migrations.

Warning : This library has not yet been fully tested and is under development. Please consider this information when using.

Requirements

Installation

composer require initphp/barbarian

Usage

Start by creating a directory for the Migrations classes.

Let your working directory be /Migrations/ for example.

An example migration class would look like this;

<?php
declare(strict_types=1);

namespace App\Migrations;

use InitPHP\Barbarian\QueryInterface;

class Migration_20220718152243 extends \InitPHP\Barbarian\MigrationAbstract
{

    public function up(QueryInterface $query) : bool
    {
        $query->query("CREATE TABLE IF NOT EXISTS `users` (
                    `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
                    `name` varchar(255) NOT NULL,
                    `mail` varchar(255) NOT NULL,
                    `status` tinyint(1) NOT NULL DEFAULT 1,
                    PRIMARY KEY (`id`)
                    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;");
        return true;
    }
    
    public function down(QueryInterface $query) : bool
    {
        $query->query("DROP TABLE `users`");
        return true;
    }
    
}

Usage in your PHP code

require_once "vendor/autoload.php";

$pdo = new PDO("mysql:host=localhost;dbname=test;charset=utf8mb4", "root", "");

$migration = new \InitPHP\Barbarian\Migrations($pdo, __DIR__ . '/Migrations/', [
    'migrationTable'    => 'migrations_versions',
    'namespace'         => '\\App\\Migrations\\' // If you are not using namespace, define NULL.
]);


// Runs the up() method of a migration object.
$migration->upMigration(new \App\Migrations\Migration_20221230153013());

// Runs the down() method of a migration object.
$migration->upMigration(new \App\Migrations\Migration_20221230153013());

Using the Basic CLI

To use the CLI interface, first create the "barbarian.json" file in your working directory and save the following structure by editing it according to you.

{
  "dsn":"mysql:host=localhost;dbname=test;charset=utf8mb4",
  "username":"root",
  "password":"",
  "folder":"C:\\xampp\\Projects\\App\\Migrations\\",
  "table_name":"migrations_versions",
  "namespace":null
}

Or you can try to create this file with the command below.

vendor/bin/barbarian json

You can use the command below to create a new migration class.

vendor/bin/barbarian create

You can use the command below to up all migrations.

vendor/bin/barbarian up

You can use the -version flag to only up a migration.

vendor/bin/barbarian up -version=20221230153013

or

vendor/bin/barbarian up -version=Migration_20221230153013

You can use the command below to down all migrations.

vendor/bin/barbarian down

You can use the -version flag to only up a migration.

vendor/bin/barbarian down -version=20221230153013

or

vendor/bin/barbarian down -version=Migration_20221230153013

Credits

License

Copyright © 2022 MIT License

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固