Skip to content

Commit be778c9

Browse files
committed
Fix migration issues on MSSQL
1 parent 64941f2 commit be778c9

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

migrations/handle_subscriptions.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,24 @@ public function copy_subscription_tables()
9898
$core_push_subscriptions_table => $wpn_push_subscriptions_table
9999
] as $core_table => $ext_table)
100100
{
101+
// Turn on identity insert on mssql to be able to insert into
102+
// identity columns (e.g. id)
103+
if (strpos($this->db->sql_layer, 'mssql') !== false)
104+
{
105+
$sql = 'SET IDENTITY_INSERT ' . $core_table . ' ON';
106+
$this->db->sql_query($sql);
107+
}
108+
101109
$sql = 'INSERT INTO ' . $core_table . '
102110
SELECT * FROM ' . $ext_table;
103111
$this->db->sql_query($sql);
112+
113+
// Disable identity insert on mssql again
114+
if (strpos($this->db->sql_layer, 'mssql') !== false)
115+
{
116+
$sql = 'SET IDENTITY_INSERT ' . $core_table . ' OFF';
117+
$this->db->sql_query($sql);
118+
}
104119
}
105120
}
106121
}

0 commit comments

Comments
 (0)