Esempio n. 1
0
 /**
  * Create yaml files from database data.
  *
  * Usage (from command line):
  *
  * php oil r dbfixt:generate [-n=5] [-o=/tmp] <table1> [<table2> [...]]
  *
  * @return string
  */
 public static function generate()
 {
     $num = Cli::option('n') ? (int) Cli::option('n') : 5;
     $dir = Cli::option('o');
     if (is_null($dir)) {
         $dir = APPPATH . 'tests/fixture';
         if (!is_dir($dir)) {
             mkdir($dir);
         }
     } else {
         if (!is_dir($dir)) {
             return Cli::color('No such directory: ' . $dir, 'red');
         }
     }
     $args = func_get_args();
     foreach ($args as $table) {
         if (DBUtil::table_exists($table)) {
             $result = DB::select('*')->from($table)->limit($num)->execute();
             $data = $result->as_array();
             static::setToYaml($dir, $data, $table);
         } elseif (Mongo_Db::instance()->get_collection($table)) {
             $mongo = Mongo_Db::instance();
             $data = $mongo->limit($num)->get($table);
             static::setToYaml($dir, $data, $table);
         } else {
             echo Cli::color('No such table: ' . $table, 'red') . PHP_EOL;
         }
     }
 }
Esempio n. 2
0
 public static function down_run($table_name)
 {
     $table_exists = DBUtil::table_exists($table_name);
     if (!$table_exists) {
         return false;
     }
     DBUtil::drop_table($table_name);
 }
Esempio n. 3
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['product_id' => ['constraint' => 11, 'type' => 'int'], 'category_id' => ['constraint' => 11, 'type' => 'int']], ['product_id', 'category_id'], true, 'InnoDB', 'utf8_general_ci');
 }
Esempio n. 4
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'group_id' => ['constraint' => 50, 'type' => 'varchar'], 'group_name' => ['constraint' => 50, 'type' => 'varchar'], 'privacy' => ['constraint' => 255, 'type' => 'varchar'], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'group_id', 'group_id');
 }
Esempio n. 5
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'maintenance' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 0], 'email' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'telephone' => ['constraint' => 12, 'type' => 'varchar', 'null' => true], 'address' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'fb_url' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'shop_name' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'maintenance', 'maintenance');
 }
Esempio n. 6
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'parent_id' => ['constraint' => 11, 'type' => 'int'], 'provider' => ['constraint' => 255, 'type' => 'varchar'], 'uid' => ['constraint' => 50, 'type' => 'varchar'], 'secret' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'access_token' => ['constraint' => 255, 'type' => 'varchar', 'default' => ''], 'expires' => ['constraint' => 11, 'type' => 'int', 'default' => 0], 'refresh_token' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'created_at' => ['constraint' => 11, 'type' => 'int', 'default' => 0]], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'parent_id', 'parent_id');
 }
Esempio n. 7
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['order_item_id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'order_id' => ['constraint' => 11, 'type' => 'int'], 'product_id' => ['constraint' => 11, 'type' => 'int'], 'product_price' => ['constraint' => 11, 'type' => 'int'], 'quantity' => ['constraint' => 11, 'type' => 'int'], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')]], ['order_item_id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'order_id', 'order_id');
     DBUtil::create_index(self::$_table_name, 'product_id', 'product_id');
 }
Esempio n. 8
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'code' => ['constraint' => 50, 'type' => 'varchar'], 'product_name' => ['type' => 'text'], 'product_description' => ['type' => 'text', 'null' => true], 'product_info' => ['type' => 'text', 'null' => true], 'note' => ['type' => 'text', 'null' => true], 'product_photo' => ['constraint' => 50, 'type' => 'varchar', 'null' => true], 'status' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 2], 'highlight' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 0], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'code', 'code');
     DBUtil::create_index(self::$_table_name, 'status', 'status');
     DBUtil::create_index(self::$_table_name, 'highlight', 'highlight');
 }
Esempio n. 9
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['order_id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'user_id' => ['constraint' => 11, 'type' => 'int'], 'message' => ['type' => 'text', 'null' => true], 'order_email' => ['type' => 'text', 'null' => true], 'order_gender' => ['type' => 'text', 'null' => true], 'order_last_name' => ['type' => 'text', 'null' => true], 'order_first_name' => ['type' => 'text', 'null' => true], 'order_last_name_kana' => ['type' => 'text', 'null' => true], 'order_first_name_kana' => ['type' => 'text', 'null' => true], 'order_tel' => ['type' => 'text', 'null' => true], 'order_fax' => ['type' => 'text', 'null' => true], 'order_zip' => ['type' => 'text', 'null' => true], 'order_addr' => ['type' => 'text', 'null' => true], 'payment_total' => ['constraint' => 11, 'type' => 'int'], 'payment_method' => ['constraint' => 1, 'type' => 'int'], 'payment_status' => ['constraint' => 1, 'type' => 'int', 'default' => 1], 'payment_date' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00'], 'del_flg' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 0], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['order_id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'user_id', 'user_id');
     DBUtil::create_index(self::$_table_name, 'payment_method', 'payment_method');
     DBUtil::create_index(self::$_table_name, 'payment_status', 'payment_status');
     DBUtil::create_index(self::$_table_name, 'del_flg', 'del_flg');
 }
Esempio n. 10
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'username' => ['constraint' => 32, 'type' => 'varchar'], 'email' => ['constraint' => 255, 'type' => 'varchar'], 'password' => ['constraint' => 255, 'type' => 'varchar'], 'login_hash' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'last_login' => ['constraint' => 11, 'type' => 'int', 'default' => 0], 'group' => ['constraint' => 11, 'type' => 'int', 'default' => 1], 'password_code' => ['constraint' => 32, 'type' => 'varchar', 'null' => true], 'full_name' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'gender' => ['constraint' => 1, 'type' => 'int', 'default' => 0], 'birthday' => ['constraint' => 10, 'type' => 'varchar', 'null' => true], 'address' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'telephone' => ['constraint' => 12, 'type' => 'varchar', 'null' => true], 'user_photo' => ['constraint' => 50, 'type' => 'varchar', 'null' => true], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'username', 'username');
     DBUtil::create_index(self::$_table_name, 'email', 'email');
     DBUtil::create_index(self::$_table_name, 'password', 'password');
     DBUtil::create_index(self::$_table_name, 'login_hash', 'login_hash');
     DBUtil::create_index(self::$_table_name, 'group', 'group');
 }