cloudlog/application/migrations/257_create_station_diary_reactions_table.php
Peter Goodhall a4d284a0c0 Add reactions to station diary entries
Introduce a reactions feature for public station diary entries. Adds a migration to create station_diary_reactions with indexes and a unique (diary_id, visitor_hash) constraint; bumps migration version to 257 and registers a new route for /entry/:id/react. Controller: implements visitor token/hash creation, a react() endpoint to accept POSTed reactions (like, love, fire), increments/updates reactions, invalidates cache and returns totals and visitor reaction. Model: new methods to get totals, fetch visitor reaction and save/update reactions. View: UI, styles and client-side JS for reaction buttons, counts, and copy/share enhancements; integrates totals and visitor state into the single-entry view.
2026-03-09 13:29:14 +00:00

55 lines
1.3 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Migration_create_station_diary_reactions_table extends CI_Migration {
public function up()
{
if ($this->db->table_exists('station_diary_reactions')) {
return;
}
$this->dbforge->add_field(array(
'id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => TRUE,
'auto_increment' => TRUE,
),
'diary_id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => TRUE,
),
'reaction' => array(
'type' => 'VARCHAR',
'constraint' => 16,
),
'visitor_hash' => array(
'type' => 'VARCHAR',
'constraint' => 64,
),
'created_at' => array(
'type' => 'DATETIME',
'null' => TRUE,
),
'updated_at' => array(
'type' => 'DATETIME',
'null' => TRUE,
),
));
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('station_diary_reactions', TRUE);
$this->db->query('ALTER TABLE station_diary_reactions ADD INDEX idx_diary_reactions_diary (diary_id)');
$this->db->query('ALTER TABLE station_diary_reactions ADD INDEX idx_diary_reactions_reaction (reaction)');
$this->db->query('ALTER TABLE station_diary_reactions ADD UNIQUE KEY uniq_diary_reactions_visitor (diary_id, visitor_hash)');
}
public function down()
{
$this->dbforge->drop_table('station_diary_reactions', TRUE);
}
}