GithubHelp home page GithubHelp logo

initphp / barbarian Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 9 KB

It is a primitive Migration library. The biggest advantage of being primitive is that it is simple and understandable.

License: MIT License

PHP 100.00%
migration migrations mysql pdo php php-migration php7 postgresql sql-migration sql-migrations

barbarian's Introduction

Barbarian

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

barbarian's People

Contributors

muhammetsafak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.