Alex Dai Playground

[pm2] In-memory PM2 is out-of-date

| Comments

問題

>>>> In-memory PM2 is out-of-date, do:
>>>> $ pm2 update
In memory PM2 version: 2.4.6
Local PM2 version: 2.7.2
-------------------------------------------------------
因為 nvm 有舊版 node 安裝 pm2 的關係,只要移除舊版就可以 
nvm use old-version
npm uninstall -g pm2
nvm use new-vsersion
npm i -g pm2

方法1

pm2 kill
npm uninstall pm2 -g
npm install pm2@latest -g

方法2

pm2 kill
npm remove pm2 -g
which pm2 (/usr/bin/pm2)
rm (directory from call above)
npm install pm2@latest -g
ln -s /usr/local/bin/pm2 /usr/bin/pm2

  • nvm: /usr/local/bin/pm2 換成 /root/.nvm/versions/node/v8.7.0/bin/pm2

https://github.com/Unitech/pm2/issues/3175

[MySql] 5.7 ONLY_FULL_GROUP_BY

| Comments

MySql 5.7

sql-mode 預設有使用

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION.

其中 ONLY_FULL_GROUP_BY 會造成 一對多的資料 group id 錯誤

解決方式一

設定 my.ini 只保留 NO_ENGINE_SUBSTITUTION(5.6的預設)

my.ini
sql-mode="NO_ENGINE_SUBSTITUTION"

[Laravel] MAMP migrate error SQLSTATE[HY000] [2002] No such file or directory

| Comments

Add

'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',

config/database.php
     'mysql' => [
          'driver'    => 'mysql',
          'host'      => env('DB_HOST', 'localhost'),
          'database'  => env('DB_DATABASE', 'forge'),
          'username'  => env('DB_USERNAME', 'forge'),
          'password'  => env('DB_PASSWORD', ''),
          'charset'   => 'utf8',
          'collation' => 'utf8_unicode_ci',
          'prefix'    => '',
          'strict'    => false,
          'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',
      ],

[AWS] amazon linux insatll docker & docker-compose

| Comments

install docker

$ sudo yum update
$ sudo yum install -y docker
$ sudo usermod -aG docker ec2-user
$ sudo service docker start

install docker-compose

$ sudo su

$ curl -L "https://github.com/docker/compose/releases/download/1.8.0/docker-compose-$(uname -s)-$(uname -m)" > /usr/local/bin/docker-compose

$ chmod +x /usr/local/bin/docker-compose

$ exit

$ docker-compose --version

[Laravel] cli

| Comments

建立資料表

  • 產生 book model
    php artisan make:model Book
    
  • 產生 books table

    php artisan make:migration create_books_table
    
  • 設定 books schema

    2016_10_05_085026_create_books_table.php
    class CreateBooksTable extends Migration
    {
    public function up()
    {
    Schema::create('books', function (Blueprint $table) {
    $table->increments('id');
    $table->string('title');
    $table->string('author');
    $table->integer('price', 0);
    $table->timestamps();
    });
    }
    ...
    }


    • Schema 寫入資料庫
      php artisan migrate
      

    資料表更新

    • 產生更新遷移檔,指定 books table
      php artisan make:migration add_userid_to_books_table --table="books"
      
    • 撰寫更新程式碼 (新增外來鍵失敗,遷移順序問題?)

      2016_10_17_030053_add_userid_to_books_table.php
      class AddUseridToBooksTable extends Migration
      {
        public function up()
        {
            Schema::table('books', function (Blueprint $table) {
                // 新增外來鍵欄位 對應使用者 id
                $table->integer('user_id')->unsigned();
      
                $table->foreign('user_id')
                    ->references('id')
                    ->on('users')
                    ->onDlete('cascade');
                });
        }
      
        public function down()
        {
            Schema::table('books', function (Blueprint $table) {
                  $table->dropColumn('user_id');
            });
        }
      }
      
    • 更新 Schema

      php artisan migrate
      
    • https://laravel.com/docs/5.1/migrations#creating-tables

    • http://laravel5-book.kejyun.com/database/migration/database-migration-README.html