agashe/sigmaphp-db

PHP 数据库工具

0.1.8 2024-09-09 11:19 UTC

This package is auto-updated.

Last update: 2024-09-09 11:24:02 UTC


README

SigmaPHP-DB 是一组 PHP 数据库工具。主要支持 MySQL 关系型数据库管理系统(未来将添加对其他 RDBMS 的支持)。包括迁移和回滚、播种、查询构建器、ORM 等功能,所有这些功能都可以通过终端中的优雅 CLI 脚本来使用。

安装

composer require agashe/sigmaphp-db

配置

安装后,您应该创建一个新的配置文件,包括您的数据库连接参数,还可以编辑其他选项,如迁移/播种器路径。

要生成新的配置文件,请运行以下命令

php ./vendor/bin/sigma-db create:config

将在您项目目录的根目录下创建一个名为 database.php 的新配置文件。

您可以简单地更改配置文件的名字和位置,但这样做需要您在使用 CLI 脚本时传递配置文件路径。

php ./vendor/bin/sigma-db migrate --config=/path/to/my-config.php

文档

CLI 使用

在下面的表中,您可以找到所有可用的命令

以下是一些使用命令的示例

php ./vendor/bin/sigma-db create:migration UsersTable
// will create UsersTableMigration.php file into /path/to/migrations

php ./vendor/bin/sigma-db create:seed UsersRolesSeeder
// run seeder UsersRolesSeeder.php

php ./vendor/bin/sigma-db create:rollback 2023-1-20
// rollback all migrations up to 2023-1-20 , the migrations running dates all saved into the migrations logs table (default name is db_logs). And of course you can change it in the config file

php ./vendor/bin/sigma-db drop
// to drop all tables

php ./vendor/bin/sigma-db fresh --config=/path/to/db-testing-config.php
// to drop all tables then migrate and seed , and in this example we assume that you have put the config in your path of choice

许可证

(SigmaPHP-DB) 在 MIT 许可证的条款下发布。