forge->addColumn('staff_attendance', [ 'class_section_id' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true, 'after' => 'user_id', ], 'position' => [ 'type' => 'ENUM', 'constraint' => ['main','ta'], 'null' => true, 'after' => 'class_section_id', ], ]); // Unique constraint: 1 record per user per date $this->db->query(" ALTER TABLE staff_attendance ADD UNIQUE KEY uniq_user_date (user_id, date) "); } public function down() { $this->forge->dropColumn('staff_attendance', 'class_section_id'); $this->forge->dropColumn('staff_attendance', 'position'); $this->db->query("ALTER TABLE staff_attendance DROP INDEX uniq_user_date"); } }