codeigniter-migrations icon indicating copy to clipboard operation
codeigniter-migrations copied to clipboard

CodeIgniter migration: more database

Open bobc82 opened this issue 8 years ago • 0 comments

i tried to do migrations with more database: a default database and another. This is the database.php file:

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

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
'dsn'   => '',
'hostname' => '127.0.0.1',
'username' => 'root',
'password' => '',
'database' => 'buy_prova_test',
'dbdriver' => 'mysqli',
'dbprefix' => 'ext_',
'pconnect' => FALSE,
//'db_debug' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);

$db['oauth_test'] = array(
'dsn'   => '',
'hostname' => '127.0.0.1',
'username' => 'root',
'password' => '',
'database' => 'oauth_test',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
//'db_debug' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);

?>

This is, instead, the first migration that runs fine:

<?php
class Migration_Create_external_site_manager extends CI_Migration
{
public function up()
{
    $this->dbforge->add_field("
     ID bigint(20) NOT NULL AUTO_INCREMENT,
     sito varchar(255) NOT NULL,
     url_override text NOT NULL,
     title varchar(255) NOT NULL,
     title_facebook text NOT NULL,
     description text NOT NULL,
     description_facebook text NOT NULL,
     description_twitter text NOT NULL,
     img_facebook text NOT NULL,
     img_twitter text NOT NULL,
     PRIMARY KEY (ID)"
    );
    $this->dbforge->create_table('external_site_manager');
}

public function down()
{
    $this->dbforge->drop_table('external_site_manager');
}
}
?>

And this is the second migration that i would do on oauth_test database, it doesn't return error, but i don't see any table in the database:

<?php
class Migration_Create_oauth_test extends CI_Migration
{


public function up()
{
    $oauth=$this->load->database('oauth_test',true);
    $this->oauth_forge=$this->load->dbforge($oauth,TRUE));
    $this->oauth_forge->add_field("
        access_token varchar(40) NOT NULL,
        client_id varchar(80) NOT NULL,
        user_id varchar(255) DEFAULT NULL,
        expires timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        scope varchar(2000) DEFAULT NULL,
        PRIMARY KEY (access_token)");
    $this->oauth_forge->create_table("oauth_access_tokens");
    $this->oauth_forge->add_field("
        client_id varchar(80) NOT NULL,
         client_secret varchar(80) NOT NULL,
         redirect_uri varchar(2000) NOT NULL,
         grant_types varchar(80) DEFAULT NULL,
         scope varchar(100) DEFAULT NULL,
         user_id varchar(80) DEFAULT NULL,
         PRIMARY KEY (client_id)
        ");
    $this->oauth_forge->create_table("oauth_clients");
}

public function down()
{
    $oauth=$this->load->database('oauth_test',true);
    $this->oauth_forge=$this->load->dbforge($oauth,TRUE));
    $this->oauth_forge->drop_table("oauth_clients");
    $this->oauth_forge->drop_table("oauth_access_tokens");
}
}

?>

Thank you in advance for help!

bobc82 avatar Jul 25 '16 10:07 bobc82