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

/**
 * Migration 010 — Partners & clients
 * Drives the moving logo slider on the homepage and the Partners page.
 */
class Migration_Create_partners extends CI_Migration {

	public function up()
	{
		$this->dbforge->add_field(array(
			'id'            => array('type' => 'INT', 'constraint' => 11, 'unsigned' => TRUE, 'auto_increment' => TRUE),
			'name'          => array('type' => 'VARCHAR', 'constraint' => 160),
			'logo'          => array('type' => 'VARCHAR', 'constraint' => 255, 'null' => TRUE),
			'website'       => array('type' => 'VARCHAR', 'constraint' => 255, 'null' => TRUE),
			'category'      => array('type' => 'VARCHAR', 'constraint' => 60, 'null' => TRUE, 'comment' => 'client / partner / press'),
			'is_featured'   => array('type' => 'TINYINT', 'constraint' => 1, 'default' => 1, 'comment' => 'Show in homepage slider'),
			'sort_order'    => array('type' => 'INT', 'constraint' => 5, 'default' => 0),
			'is_active'     => array('type' => 'TINYINT', 'constraint' => 1, 'default' => 1),
			'created_at'    => array('type' => 'DATETIME', 'null' => TRUE),
			'updated_at'    => array('type' => 'DATETIME', 'null' => TRUE),
		));
		$this->dbforge->add_key('id', TRUE);
		$this->dbforge->create_table('partners', TRUE, array('ENGINE' => 'InnoDB'));

		$now = date('Y-m-d H:i:s');
		$demo = array('Aurora Couture', 'Velvet Studios', 'Lumen Beverages', 'Metro Apparel',
			'Solace Beauty', 'Northwave Media', 'Glow Cosmetics', 'Atelier Nine');
		$order = 1;
		foreach ($demo as $name)
		{
			$this->db->insert('partners', array(
				'name' => $name,
				'logo' => 'partners/'.url_title($name, '-', TRUE).'.png',
				'category' => 'client', 'is_featured' => 1,
				'sort_order' => $order++, 'is_active' => 1, 'created_at' => $now,
			));
		}
	}

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