jamoliddin/pgschema

laravel 10 的 postgresql 架构

dev-Jamoliddin 2023-07-03 06:27 UTC

This package is not auto-updated.

Last update: 2024-09-25 13:01:29 UTC


README

当您在使用 PostgreSQL 架构的多租户应用程序时,这非常有用。

使用外观辅助函数,您可以轻松地创建/删除/切换架构。此包还提供了为每个架构的迁移和种子支持的 artisan 命令。

PGSchema 将检查并仅在特定的连接驱动程序为 pgsql 时才会产生影响。因此,您可以使用 PGSchema 安全地使用任何数据库连接驱动程序,而不会发生错误。

Laravel 版本

当前包版本适用于 Laravel 10 .

安装

  1. 使用 composer 将包添加到您的项目中
composer require jamoliddin/pgschema
  1. config/app.php 中的 providers 数组中添加服务提供者
Racklin\PGSchema\PGSchemaServiceProvider::class,
  1. config/app.php 中的 aliases 数组中添加别名
'PGSchema' => Racklin\PGSchema\Facades\PGSchema::class,

Artisan 命令

pgschema:migrate

pgschema:migrate 命令为 Laravel 的 migrate 命令添加了额外的 schema 选项,您可以为迁移指定数据库架构。并且它将自动为架构安装 migrations 存储库表。

Usage:
  pgschema:migrate [options]

Options:
      --database[=DATABASE]  The database connection to use.
      --schema[=SCHEMA]      The database schema to use.
      --force                Force the operation to run when in production.
      --path[=PATH]          The path of migrations files to be executed.
      --pretend              Dump the SQL queries that would be run.
      --seed                 Indicates if the seed task should be re-run.
      --step                 Force the migrations to be run so they can be rolled back individually.
  -h, --help                 Display this help message
  -q, --quiet                Do not output any message
  -V, --version              Display this application version
      --ansi                 Force ANSI output
      --no-ansi              Disable ANSI output
  -n, --no-interaction       Do not ask any interactive question
      --env[=ENV]            The environment the command should run under
  -v|vv|vvv, --verbose       Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  Run the database migrations

pgschema:rollback

pgschema:rollback 命令为 Laravel 的 migrate:rollback 命令添加了额外的 schema 选项。

Usage:
  pgschema:rollback [options]

Options:
      --database[=DATABASE]  The database connection to use.
      --force                Force the operation to run when in production.
      --path[=PATH]          The path of migrations files to be executed.
      --pretend              Dump the SQL queries that would be run.
      --step[=STEP]          The number of migrations to be reverted.
      --schema[=SCHEMA]      The database schema to use
  -h, --help                 Display this help message
  -q, --quiet                Do not output any message
  -V, --version              Display this application version
      --ansi                 Force ANSI output
      --no-ansi              Disable ANSI output
  -n, --no-interaction       Do not ask any interactive question
      --env[=ENV]            The environment the command should run under
  -v|vv|vvv, --verbose       Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  Rollback the last database migration

pgschema:reset

pgschema:reset 命令为 Laravel 的 migrate:reset 命令添加了额外的 schema 选项。

Usage:
  pgschema:reset [options]

Options:
      --database[=DATABASE]  The database connection to use.
      --force                Force the operation to run when in production.
      --path[=PATH]          The path of migrations files to be executed.
      --pretend              Dump the SQL queries that would be run.
      --schema[=SCHEMA]      The database schema to use
  -h, --help                 Display this help message
  -q, --quiet                Do not output any message
  -V, --version              Display this application version
      --ansi                 Force ANSI output
      --no-ansi              Disable ANSI output
  -n, --no-interaction       Do not ask any interactive question
      --env[=ENV]            The environment the command should run under
  -v|vv|vvv, --verbose       Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  Rollback all database migrations

pgschema:refresh

pgschema:refresh 命令为 Laravel 的 migrate:refresh 命令添加了额外的 schema 选项。

Usage:
  pgschema:refresh [options]

Options:
      --database[=DATABASE]  The database connection to use.
      --force                Force the operation to run when in production.
      --path[=PATH]          The path of migrations files to be executed.
      --seed                 Indicates if the seed task should be re-run.
      --seeder[=SEEDER]      The class name of the root seeder.
      --step[=STEP]          The number of migrations to be reverted & re-run.
      --schema[=SCHEMA]      The database schema to use
  -h, --help                 Display this help message
  -q, --quiet                Do not output any message
  -V, --version              Display this application version
      --ansi                 Force ANSI output
      --no-ansi              Disable ANSI output
  -n, --no-interaction       Do not ask any interactive question
      --env[=ENV]            The environment the command should run under
  -v|vv|vvv, --verbose       Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  Reset and re-run all migrations

pgschema:seed

pgschema:seed 命令为 Laravel 的 db:seed 命令添加了额外的 schema 选项。

Usage:
  pgschema:seed [options]

Options:
      --class[=CLASS]        The class name of the root seeder [default: "DatabaseSeeder"]
      --database[=DATABASE]  The database connection to seed
      --schema[=SCHEMA]      The database schema to seed
      --force                Force the operation to run when in production.
  -h, --help                 Display this help message
  -q, --quiet                Do not output any message
  -V, --version              Display this application version
      --ansi                 Force ANSI output
      --no-ansi              Disable ANSI output
  -n, --no-interaction       Do not ask any interactive question
      --env[=ENV]            The environment the command should run under
  -v|vv|vvv, --verbose       Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  Seed the database with records

pgschema:create-schema

pgschema:create-schemadatabase 创建 schema

Usage:
  pgschema:create-schema [options] [--] <schema>

Arguments:
  schema                     The database schema to create

Options:
      --database[=DATABASE]  The database connection to use
  -h, --help                 Display this help message
  -q, --quiet                Do not output any message
  -V, --version              Display this application version
      --ansi                 Force ANSI output
      --no-ansi              Disable ANSI output
  -n, --no-interaction       Do not ask any interactive question
      --env[=ENV]            The environment the command should run under
  -v|vv|vvv, --verbose       Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

外观辅助函数

创建新架构

PGSchema::create($schemaName, $databaseName)

如果没有调用 $databaseName 参数,它将使用默认连接。

删除架构

PGSchema::drop($schemaName, $databaseName)

如果没有调用 $databaseName 参数,它将使用默认连接。

切换架构

PGSchema::schema($schemaName, $databaseName)

如果没有调用 $schemaName 参数,它将切换到默认的公共架构(默认)。如果没有调用 $databaseName 参数,它将使用默认连接。

迭代架构

PGSchema::each(Closure $callback, $databaseName)

如果没有调用 $databaseName 参数,它将使用默认连接。

许可证

MIT: https://racklin.mit-license.org/