Skip to content

Commit

Permalink
Change Migration of table user_visit_log for SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan39 committed Jan 14, 2018
1 parent 716f0bc commit 09ece11
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
2 changes: 1 addition & 1 deletion migrations/m141023_141535_create_user_visit_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function safeUp()
'token' => 'string not null',
'ip' => 'varchar(15) not null',
'language' => 'char(2) not null',
'browser_and_os' => 'string not null',
'user_agent' => 'string not null',
'user_id' => 'int',
'visit_time' => 'int not null',
0 => 'FOREIGN KEY (user_id) REFERENCES '.Yii::$app->getModule('user-management')->user_table.' (id) ON DELETE SET NULL ON UPDATE CASCADE',
Expand Down
22 changes: 2 additions & 20 deletions migrations/m141121_194858_split_browser_and_os_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@ public function safeUp()
{
$this->addColumn(Yii::$app->getModule('user-management')->user_visit_log_table, 'browser', 'varchar(30)');
$this->addColumn(Yii::$app->getModule('user-management')->user_visit_log_table, 'os', 'varchar(20)');
if ( $this->db->driverName === 'sqlite' )
{
$this->execute('ALTER '.Yii::$app->getModule('user-management')->user_visit_log_table.' CHANGE COLUMN browser_and_os user_agent');
}
else
{
$this->renameColumn(Yii::$app->getModule('user-management')->user_visit_log_table, 'browser_and_os', 'user_agent');
}

if (Yii::$app->cache) {
if (Yii::$app->cache) {
Yii::$app->cache->flush();
}
}
Expand All @@ -26,16 +17,7 @@ public function safeDown()
{
$this->dropColumn(Yii::$app->getModule('user-management')->user_visit_log_table, 'os');
$this->dropColumn(Yii::$app->getModule('user-management')->user_visit_log_table, 'browser');
if ( $this->db->driverName === 'sqlite' )
{
$this->execute('ALTER '.Yii::$app->getModule('user-management')->user_visit_log_table.' CHANGE COLUMN user_agent browser_and_os');
}
else
{
$this->renameColumn(Yii::$app->getModule('user-management')->user_visit_log_table, 'user_agent', 'browser_and_os');
}

if (Yii::$app->cache) {
if (Yii::$app->cache) {
Yii::$app->cache->flush();
}
}
Expand Down

0 comments on commit 09ece11

Please sign in to comment.