承接 sharpen/versionna 相关项目开发

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

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

sharpen/versionna

Composer 安装命令:

composer require sharpen/versionna

包简介

Manticoresearch migration tool. Keep your index schemas up to date programmatically in your application

README 文档

README

Latest Version on Packagist tests phpstan Total Downloads

Manticoresearch migration tool. Keep updated your index schemas up to date using an executable CLI script or integrate it programmatically in your application code.

migrate and migrate:down

Table of contents

project progress and roadmap

  • Add CI pipeline
    • Add PHP versions supported
      • 8.0
      • 8.1
      • 8.2
    • PhpStan
    • PHPUnit run tests
  • Pre-commit linter and tests checks
    • Add Grumphp
      • PHPStan
      • PHPUnit
  • Add a logger implementation
  • Add docker-compose stack files for testing and development
  • Add code documentation
  • Write a complete README file explaining all
  • Add unit and integration tests
  • Add command line interface feature
    • Add cli application metadata such as name, description, etc.
    • Created structure of the CLI application
  • Executable script (bin/versionna)
  • Add commands
    • list
    • make:config
    • make:migration
    • migration:list:pending
    • migration:list:migrated
    • migrate
    • rollback
    • rollback with --steps
    • fresh
    • refresh
    • refresh with --steps
    • reset
    • status
    • help
  • Add drivers to support multiple DBs engines dialects
    • Add driver for SQLite
    • Add driver for MySQL
    • Add driver for PostgreSQL
  • Create a Laravel package
  • Create a Symfony package

Installation

composer require sharpen/versionna

Usage

First of all, you need to install the package.

composer require sharpen/versionna

After been installed, you need to create a directory. That directory will contain the migration files sorted by creation date.

You have two different ways to use this package:

  • programmatically
  • CLI

You can create your own integration with versionna using the programmatically way as you can see in hte examples directory in this repository.

In each section of these documentation you will see both: programmatically and CLI version to create, migrate, rollback, list applied and pending migrations.

Create migration

CLI

To create a migration file you have to use the make:migration and the class name (the migration class name that extends Migration class) using snake_case_style. This class name should be a descriptive name. It's better a long name for two reasons:

  • to better understand what the migration does
  • and for avoid duplicated class names
./vendor/bin/versionna make:migration -c config.php create_products_index

programmatically

<?php

use Sharpen\Versionna\MigrationCreator;

$configuration = require 'config.php';

$migrationName = 'create_users_index';
$description = 'users initial definition of the rt index';
$migrationCreator = new MigrationCreator(
    $configuration['migrations_path'],
    $migrationName,
    $description,
);

$migrationCreator->create();

echo 'Migration created successfully';

Apply migrations

migrate and migrate:down

CLI

There are two available commands for apply pending migrations using the Command Line Interface

./vendor/bin/versionna migrate -c config.php
./vendor/bin/versionna migrate:up -c config.php

programmatically

<?php

use Sharpen\Versionna\Manticore\ManticoreConnection;
use Sharpen\Versionna\MigrationDirector;
use Sharpen\Versionna\Storage\DatabaseConfiguration;
use Sharpen\Versionna\Storage\DatabaseConnection;
use Sharpen\Versionna\Storage\MigrationTable;

$configuration = require 'config.php';

$dbConnection = new DatabaseConnection(
    DatabaseConfiguration::fromArray(
        $configuration['connections']['mysql']
    )
);

$manticoreConnection = new ManticoreConnection(
    $configuration['manticore_connection']['host'],
    $configuration['manticore_connection']['port'],
);

$migrationTable = new MigrationTable(
    $dbConnection,
    $configuration['table_prefix'],
    $configuration['migration_table'],
);

$director = new MigrationDirector();

$director
    ->dbConnection($dbConnection)
    ->manticoreConnection($manticoreConnection)
    ->migrationsPath($configuration['migrations_path'])
    ->migrationTable($migrationTable);

if (! $migrationTable->exists()) {
    echo 'Migration table doesn\'t exist';
    exit(1);
} elseif (! $director->hasPendingMigrations()) {
    echo 'No pending migrations';

    exit(0);
}

try {
    $director->migrate();
} catch (Exception $exception) {
    echo $exception->getMessage();

    exit(1);
}

echo 'Applied all migrations';

Rollback migration

migrate and migrate:down

CLI

There are two available commands to rollback applied migrations using the Command Line Interface

./vendor/bin/versionna rollback -c config.php
./vendor/bin/versionna migrate:down -c config.php

programmatically

<?php

use Sharpen\Versionna\Manticore\ManticoreConnection;
use Sharpen\Versionna\MigrationDirector;
use Sharpen\Versionna\Storage\DatabaseConfiguration;
use Sharpen\Versionna\Storage\DatabaseConnection;
use Sharpen\Versionna\Storage\MigrationTable;

$configuration = require 'config.php';

$dbConnection = new DatabaseConnection(
  DatabaseConfiguration::fromArray(
    $configuration['connections']['mysql']
  ),
);

$manticoreConnection = new ManticoreConnection(
  $configuration['manticore_connection']['host'],
  $configuration['manticore_connection']['port'],
);

$migrationTable = new MigrationTable(
  $dbConnection,
  $configuration['table_prefix'],
  $configuration['migration_table']
);

$director = new MigrationDirector();
$director
  ->dbConnection($dbConnection)
  ->manticoreConnection($manticoreConnection)
  ->migrationsPath($configuration['migrations_path'])
  ->migrationTable($migrationTable);

$steps = 1;

$director->undoMigrations($steps);

List migrations applied history

migration:list:migrated

CLI

For list pending migrations using the Command Line tool

./vendor/bin/versionna migration:list:pending -c config.php

programmatically

<?php

$configuration = require 'config.php';

$dbConnection = new DatabaseConnection(
    DatabaseConfiguration::fromArray(
        $configuration['connections']['mysql']
    )
);

$migrationTable = new MigrationTable(
    $dbConnection,
    $configuration['table_prefix'],
    $configuration['migration_table']
);

$ascending = false;

$migrations = $migrationTable->getAll($ascending);

if ($migrations) {
    $migrationsDone = array_map(
        function ($migration) {
            return $migration->toArray();
        },
        $migrations,
    );

    var_dump($migrationsDone);
} else {
    echo 'The migration table is empty';
}

List pending migrations

migration:list:pending

CLI

For list pending migrations using the Command Line tool

./vendor/bin/versionna migration:list:pending -c config.php

programmatically

<?php

use Sharpen\Versionna\Manticore\ManticoreConnection;
use Sharpen\Versionna\MigrationDirector;
use Sharpen\Versionna\Storage\DatabaseConfiguration;
use Sharpen\Versionna\Storage\DatabaseConnection;
use Sharpen\Versionna\Storage\MigrationTable;

$dbConnection = new DatabaseConnection(
    DatabaseConfiguration::fromArray(
        $configuration['connections'][$connection]
    )
);

$manticoreConnection = new ManticoreConnection(
    $configuration['manticore_connection']['host'],
    $configuration['manticore_connection']['port'],
);

$migrationTable = new MigrationTable(
    $dbConnection,
    $configuration['table_prefix'],
    $configuration['migration_table']
);

$director = new MigrationDirector();

$director
    ->dbConnection($dbConnection)
    ->manticoreConnection($manticoreConnection)
    ->migrationsPath($configuration['migrations_path'])
    ->migrationTable($migrationTable);

$pendingMigrations = $director->getPendingMigrations();

if (count($pendingMigrations) > 0) {
    array_map(
        function ($migration) {
            return ['name' => $migration];
        },
        array_values(array_keys($pendingMigrations)),
    );
} else {
    echo 'ManticoreSearch is up to date! no pending migrations';
}

sharpen/versionna 适用场景与选型建议

sharpen/versionna 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46 次下载、GitHub Stars 达 4, 最近一次更新时间为 2022 年 12 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 sharpen/versionna 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sharpen/versionna 我们能提供哪些服务?
定制开发 / 二次开发

基于 sharpen/versionna 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

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