移动框架时的数据库迁移

zwghvu4y  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(221)

在我工作的地方,我决定尝试更新一些用香草php编写的网站。考虑到这一点,我们选择了拉雷夫,因为经过一些研究,这似乎是一个明智的选择。
最近我一直在研究数据迁移,因为我们有一个应用程序,服务于大约500个需要移动数据的客户机;这些数据使用定制的php类进行加密和解密。
因此,我采取了以下步骤来处理迁移
使用应用程序中的解密函数对数据进行解密
将此数据移到csv文件中
更新了所有列并删除了不再使用的列
已使用phpmyadmin导入csv文件
在我的laravel应用程序中安装了一个包,可以将数据库数据转换为可在laravel中使用的数据库播种器
我现在有一个名为userstableeder的种子程序,它包含所有旧用户数据。
在我的用户模型中,我定义了访问器和变异器,通过laravel的原生加密和解密函数来处理加密和解密。
例如,对于first_name,我做了以下工作:

/**
 * Encrypt first_name
 *
 * @param [type] $value
 * @return void
 */
public function setFirstNameAttribute($value)
{
    $this->attributes['first_name'] = encrypt(ucfirst($value));
}

/**
 * Decrypt first_name if the field is NOT empty.
 *
 * @param [type] $value
 * @return void
 */
public function getFirstNameAttribute($value)
{
    return empty($value) ? '' : decrypt($value);
}

这种方法在从应用程序中写入和检索数据时有效。
我的 UsersTableSeeder 看起来像这样:

\DB::table('users')->insert(array (
        0 => 
        array (
            'title' => 'Mr',
            'first_name' => 'first',
            'last_name' => 'last',
            'email' => 'me@gmail.com',
            'mobile_number' => NULL,
            'member_type' => 'Active',
            'contact_by_email' => '0',
            'contact_by_phone' => '0',
            'contact_by_post' => '0',
            'remember_token' => 'pOxr1PgwQo',
            'created_at' => '2018-01-29 00:00:00',
            'updated_at' => '2018-01-29 00:00:00',
        ),

它是通过对我导入的数据库进行反向种子设定而创建的。
问题是 \DB::table('users')->insert() 不是通过 User 因此在种子运行时数据不会加密。
我可以更改播种机中的每个语句以使用 User::create([]) 但编写控制台命令是否更可行?
你们有没有遇到过类似的情况?
数据库迁移通常只由数据库本身处理,而不是通过应用程序泵送数据吗?
我用于反向种子设定的程序包是:https://github.com/orangehill/iseed

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题