<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Migration 014 — Centralised media library
 * folder groups uploads (campaign / talent / event). file_type: image | video.
 */
class Migration_Create_media extends CI_Migration {

	public function up()
	{
		$this->dbforge->add_field(array(
			'id'         => array('type' => 'INT', 'constraint' => 11, 'unsigned' => TRUE, 'auto_increment' => TRUE),
			'title'      => array('type' => 'VARCHAR', 'constraint' => 200, 'null' => TRUE),
			'file_path'  => array('type' => 'VARCHAR', 'constraint' => 255),
			'thumb_path' => array('type' => 'VARCHAR', 'constraint' => 255, 'null' => TRUE),
			'file_type'  => array('type' => "ENUM('image','video','document')", 'default' => 'image'),
			'folder'     => array('type' => 'VARCHAR', 'constraint' => 80, 'default' => 'general'),
			'file_size'  => array('type' => 'INT', 'constraint' => 11, 'null' => TRUE),
			'alt_text'   => array('type' => 'VARCHAR', 'constraint' => 255, 'null' => TRUE),
			'uploaded_by'=> array('type' => 'INT', 'constraint' => 11, 'null' => TRUE),
			'created_at' => array('type' => 'DATETIME', 'null' => TRUE),
		));
		$this->dbforge->add_key('id', TRUE);
		$this->dbforge->add_key('folder');
		$this->dbforge->create_table('media', TRUE, array('ENGINE' => 'InnoDB'));
	}

	public function down()
	{
		$this->dbforge->drop_table('media', TRUE);
	}
}
