}
if ($this->db->schema->getTableSchema(self::TABLE_NAME)->getColumn('target_date') === null) {
- $this->addColumn(self::TABLE_NAME,
- 'target_date',
- $this->date()->notNull()->comment('Целевая дата'));
+ $this->addColumn(self::TABLE_NAME, 'target_date', $this->date()->comment('Целевая дата'));
+
+ $this->execute("
+ UPDATE " . self::TABLE_NAME . " sk
+ SET target_date = sk.kogort_date + (
+ CASE sk.kogort_number
+ WHEN 1 THEN COALESCE((SELECT day_before_step1 FROM erp24.users_message_management LIMIT 1), 10)
+ WHEN 2 THEN COALESCE((SELECT day_before_step2 FROM erp24.users_message_management LIMIT 1), 4)
+ WHEN 3 THEN COALESCE((SELECT day_before_step3 FROM erp24.users_message_management LIMIT 1), 2)
+ ELSE 0
+ END
+ ) * INTERVAL '1 day'
+ WHERE sk.target_date IS NULL
+ ");
+
+ $this->alterColumn(self::TABLE_NAME, 'target_date', $this->date()->notNull()->comment('Целевая дата'));
}
}