Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
DBUtil::create_table with Unique?
  • I'm trying to create a migration for the sessions table using the DBUtil::create_table(). Is there any way to identify previous_id as a unique key?
    \DBUtil::create_table('sessions', array(
     'session_id' => array('constraint' => 40, 'type' => 'varchar'),
     'previous_id' => array('constraint' => 40, 'type' => 'varchar'),
     'user_agent' => array('type' => 'text'),
     'ip_address' => array('constraint' => 16, 'type' => 'varchar'),
     'created' => array('constraint' => 10, 'type' => 'int', 'default' => 0),
     'updated' => array('constraint' => 10, 'type' => 'int', 'default' => 0),
     'payload' => array('type' => 'longtext'),
    ), array('session_id'));
    
  • Hey man, I just added support for this. Check out pull request: https://github.com/fuel/core/pull/245 - Calvin
  • Here is example using both indexes and foreign keys: \DBUtil::create_table('solution_media',
    array(
    'media_id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true, 'null' => false),
    'fk_solution_id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true, 'null' => false),
    'media_type' => array('constraint' => 45, 'type' => 'varchar', 'null' => false),
    'media_location' => array('constraint' => 255, 'type' => 'varchar', 'null' => false),
    'primary' => array('constraint' => 1, 'type' => 'tinyint', 'null' => false, 'default' => 0),
    ),
    array('media_id'),
    false,
    'InnoDB',
    'utf8_bin',
    array(
    array(
    'unique' => true,
    'name' => 'media_id_UNIQUE',
    'field' => 'media_id',
    'order' => 'ASC',
    ),
    array(
    'unique' => false,
    'name' => 'solution_media.solution_id',
    'field' => 'fk_solution_id',
    'order' => 'ASC',
    )
    ),
    array(
    array(
    'constraint_name' => 'solution_media.solution_id',
    'fk_name' => 'fk_solution_id',
    'fk_reference' =>
    array(
    'table' => 'solutions',
    'field' => 'solution_id',
    ),
    'fk_on_update' => 'CASCADE',
    'fk_on_delete' => 'CASCADE',
    ),
    )
    );
  • Did not realize there was already another pull request for (some of) the same functionality. Here it is as well: https://github.com/fuel/core/pull/158
  • Haven't had time to review them. I'll see if I can do that later today...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion