首页 > 解决方案 > Laravel Postgres 多模式数据库迁移

问题描述

我正在使用 Postgres 和 Laravel 5.8。我的数据库有多个模式。每个模式都有一个patients表。我通过在现有患者表中添加密码列来为每个模式中的患者创建身份验证。迁移遍历每个模式,如果密码列不存在,则应添加它。迁移在我的控制台和迁移表中成功创建,但在数据库表中没有。我已经尝试了几次,但仍然没有。任何关于我可能做错的建议将不胜感激。

移民

class UpdatePatientsAuthentication extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $facilities = Facility::all();

        foreach ($facilities as $facility) {
            $search_path = $facility['schema_name'];
            DB::statement("SET search_path = $search_path");
            if (Schema::hasTable('patients')) {
                Schema::table('patients', function (Blueprint $table) {
                    $table->string('password')->nullable();
                });
            }
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $table->dropColumn('password');
    }
}

标签: phplaraveleloquentlaravel-migrations

解决方案


推荐阅读