承接 iyogesharma/multi-db 相关项目开发

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

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

iyogesharma/multi-db

最新稳定版本:v1.0.3

Composer 安装命令:

composer require iyogesharma/multi-db

包简介

README 文档

README

What is this repository for?

  • This Repo is created to make creating one main database and multiple client specific database easily.

  • It will automatically resolve db connection names using some properties defined in YS\MultiDB\Models\Model Class.

  • Model::$cachekey key to search client db name in cache. if set it will auto configure database connection based on this key value from cache. If not itn will connect to default database

  • Model::$cronKey Similar to $cacheKey you can set this key from crons jobs to automatically resolve database conection

  • Version 1.0

How do I get set up?

  • Installing
    composer require iyogesharma/multi-db

    php artisan vendor:publish --tag=multidb:migrations

    php artisan vendor:publish --tag=multidb:models

    //optional
    
    php artisan vendor:publish --tag=multidb:config

For PgSql

  • instead of default Illuminate\Database\Migrations\Migration extend YS\MultiDB\Migration
  • This class contains a static property called $schema which helps in identifying schema name for running migrations with dynamic schema names

For Example

```php 

        <?php

    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    use YS\MultiDB\Migration;

    return new class extends Migration
    {
        /**
         * Run the migrations.
         */
        public function up(): void
        {
            Schema::create(static::$schema.'.clients', function (Blueprint $table) {
                $table->id();
                $table->string('code');
                $table->string('name');
                $table->string('created_by');
                $table->string('modified_by')->nullable();
                $table->boolean('active')->default(1);
                $table->timestamps();
            });
        }

        /**
         * Reverse the migrations.
         */
        public function down(): void
        {
            Schema::dropIfExists('clients');
        }
    };

```
  • In your Models instead of default model class extend YS\MultiDB\Models\Model Class
  • This class contains a static propert called $inMaindb with default value as false. You can set this value to true if your model belongs to main database not client specific database
  protected static $inMainDb = false;

To run client database/schema specific migration

  • create a directory called newdatabase inside app directory
  • you can customize name of this directory just publish config and update value of key new_migrations_path
  • Place all the migration related to client specific database inside this folder
  • Run php artisan new:migrations
  • Run php artisan new:migrations_rollback to rollback migrations
  • To create new migration inside app/newdatabase folder for client specific database use
  • php artisan make:new-migration {name of migration}
  • In order to run seeders for client specific database you can create seeders directory inside app/newdatabase folder and pass --seed option along with php artisan new:migrations command to run seeders inside this directory
  • To run only seeders you can run php artisan new:seed
  • to run a specific seeder inside this folder run
  • php artisan new:seed --path=App\\Newdatabase\\Seeders\\TESTSeeder

To Check How TO Create New DB Or Schema

@see src/Controllers/ClientController

Who do I talk to?

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固