承接 marekskopal/orm-migrations 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

marekskopal/orm-migrations

最新稳定版本:v0.9.0

Composer 安装命令:

composer require marekskopal/orm-migrations

包简介

Migrations for MarekSkopal ORM.

README 文档

README

Migration module for MarekSkopalORM library.

Creates migrations from your Entity and database schema with simple API. Migrations are PHP files and that extends Migration class and may contain any of your custom logic.

Installation

Install via Composer:

composer require marekskopal/orm-migrations

Usage

Create Migrator instance

//Create DB connection
$database = new MysqlDatabase('localhost', 'root', 'password', 'database');

//Create schema
$schema = new SchemaBuilder()
    ->addEntityPath(__DIR__ . '/Entity')
    ->build();

//Create Migrator
$pathWithMigrations = __DIR__ . '/migrations/';
$migrator = new Migrator($pathWithMigrations, $database);

Create new migration

$migrator->generate(
    $schema,
    name: 'CreateUserTable',
);

This will create new migration PHP file in __DIR__ . '/migrations/' directory.

Example of generated migration file:

<?php

declare(strict_types=1);

namespace MarekSkopal\ORM\Migrations\Tests\Generator\Migrations;

use MarekSkopal\ORM\Enum\Type;
use MarekSkopal\ORM\Migrations\Migration\Migration;

final class CreateUserTable extends Migration
{
    public function up(): void
    {
        $this->table('table_a')
            ->addColumn('id', Type::Int, autoincrement: true, primary: true)
            ->addColumn('name', Type::String, nullable: true, size: 255)
            ->addColumn('address', Type::String, size: 50, default: 'New York')
            ->addColumn('score', Type::Int, size: 10)
            ->addColumn('price', Type::Decimal, precision: 10, scale: 2)
            ->addColumn('type', Type::Enum, enum: ['a', 'b', 'c'], default: 'a')
            ->create();
    }

    public function down(): void
    {
        $this->table('table_a')
            ->drop();
    }
}

Added, changed or removed tables, columns, indexes and keys are automatically detected from comparing Entity schema with your database.

Run migrations

$migrator->migrate();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-23