fitness-web/console/migrations/m160523_055217_add_customer_newsletter_token.php

40 lines
772 B
PHP

<?php
use yii\db\Schema;
use yii\db\Migration;
use common\models\Customer;
class m160523_055217_add_customer_newsletter_token extends Migration
{
public function up()
{
$this->addColumn("customer", "newsletter_token", "string" );
$customers = Customer::find()->all();
foreach ($customers as $customer ){
$customer->newsletter_token = Yii::$app->security->generateRandomString() . '_' . time();
$customer->save();
}
}
public function down()
{
echo "m160523_055217_add_customer_newsletter_token cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}