0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Laravel] スプレッドシート → マイグレーション

Posted at

ExcelやGoogle Spreadsheetなんかに記述したテーブル定義からマイグレーションファイルを作成する際に使っている式をシェアします。
必要に応じてカスタマイズして使ってください。

こんなレイアウトの表を想定しています。

A B C D E F G H
フィールド名(英語) フィールド名(日本語) 備考 桁1 桁2 デフォルト? Null許可?
name string 名称 256 o
=IF($A5="created_at", "$table->timestamps()",
 IF($A5="updated_at", "//",
 IF($A5="deleted_at", "$table->softDeletes()",(
   IF($A5="id", "$table->bigIncrements('id')",
   IF($B5="long", "$table->bigInteger('" & $A5 & "')",
   IF($B5="boolean", "$table->boolean('" & $A5 & "')",
   IF($B5="datetime", "$table->dateTime('" & $A5 & "')",
   IF($B5="double", "$table->double('" & $A5 & "', " & $E5 & ", " & $F5 & ")",
   IF($B5="float", "$table->float('" & $A5 & "', " & $E5 & ", " & $F5 & ")",
   IF($B5="int", "$table->integer('" & $A5 & "')",
   IF($B5="string", "$table->string('" & $A5 & "', " & $E5 & ")",
   IF($B5="text", "$table->text('" & $A5 & "')",
   IF($B5="timestamp", "$table->timestamp('" & $A5 & "')",
   "// NO MATCH"))))))))))
   & IF(ISTEXT($G5), "->default('" & $G5 & "')",
     IF(ISNUMBER($G5), "->default(" & $G5 & ")",
     ""))
   & IF(ISTEXT($H5), "->nullable()", "")
   & "->comment('" & $C5 & "')"
 ))))
 & ";"

こんな感じのテキストが生成されるので、これをマイグレーションファイルにぺたり!

$table->string('name', 256)->nullable()->comment('名称');
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?