Upgrade to Pro — share decks privately, control downloads, hide ads and more …

開発体験を爆上げするLaravel Dacapo マイグレーションサポートツールのススメ

開発体験を爆上げするLaravel Dacapo マイグレーションサポートツールのススメ

PHPカンファレンス沖縄2022の発表資料です。

ゆうきゃん

August 27, 2022
Tweet

More Decks by ゆうきゃん

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ • Ώ͏͖ΌΜ • ௕࡚ग़਎ • גࣜձࣾROLOॴଐ • ͓࢓ࣄ͸αʔόʔαΠυΤϯδχΞ •

    झຯ͸HADOɺݪਆɺࡾᅳࢤਅઓɺΞχϝɺອը 
 ΧϑΣ८ΓɺεϚϒϥSPɺϧʔϏοΫΩϡʔϒ 
 ...ͨ͘͞Μɻ
  2. એ఻2: ຖ݄HADOͯ͠·͢ʂ • HADO (https://meleap.com) • ಄ͱ࿹ʹηϯλʔΛ૷ணͯ͠ٿΛ์ͭ࠷৽ͷARεϙʔπ • ੈք39ΧࠃɺԆ΂350ສਓ͕ϓϨΠ •

    1ࢼ߹80ඵؒɺ3ର3Ͱ఺਺ΛऔΓ߹͏ήʔϜ • HADOެೝνʔϜʮShim Shamʯʹॴଐ • ৔ॴ͸͓୆৔(ԭೄʹ͸ແ͍Έ͍ͨ...😢) • ڵຯ͋Δํ͸ @ucan_lab ·Ͱ
  3. ໨࣍ • Laravel Migrationػೳͷ͓͞Β͍ • Laravel Dacapoͷ঺հ • Laravel Dacapoͷ࢖͍ํ

    • ࠓޙͷΞοϓσʔτʹ͍ͭͯ • ※Laravel࢖ͬͯͳ͍ਓʹ͸ؔ܎ͳ͍࿩ʹͳΓ·͢🙏 • ※ίʔυ͕Ͱͯ͘ΔͷͰ͓खݩͰࢿྉΛݟ͍ͯͩ͘͞🙏
  4. MigrationϑΝΠϧͷத਎ <?php // ... return new class extends Migration {

    public function up() { Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); $table->timestamps(); }); } public function down() { Schema::dropIfExists('users'); } };
  5. YAMLϑΝΠϧͷத਎ # database/schemas/sample.yml users: columns: id: bigIncrements name: string email:

    type: string unique: true email_verified_at: type: timestamp nullable: true password: string rememberToken: true timestamps: true • 1֊૚ʹςʔϒϧ໊ • 2֊૚͸columnsݻఆ • 3֊૚ʹΧϥϜఆٛ • 4֊૚͸ඞཁʹԠͯ͡Φϓγϣϯఆٛ
  6. ੜ੒͞ΕͨMigrationϑΝΠϧͷத਎ <?php // ... return new class extends Migration {

    public function up() { Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); $table->timestamps(); }); } public function down() { Schema::dropIfExists('users'); } };
  7. εΩʔϚYAMLϑΥʔϚοτ テーブル名: comment: テーブルコメント columns: カラム名: カラムタイプ カラム名: type: カラムタイプ

    args: カラムタイプの引数(任意) カラム修飾⼦: カラム修飾⼦の引数 カラムエイリアス(timestamps等): indexes: - columns: [カラム名] type: インデックス修飾⼦ name: インデックス名(任意) foreign_keys: - columns: [カラム名] references: [カラム名] table: テーブル名
  8. εΩʔϚYAMLઃఆྫ lessons: columns: id: instructor_id: unsignedBigInteger studio_id: unsignedBigInteger name: unsignedInteger

    capacity: unsignedInteger started_at: dateTime minutes: unsignedInteger timestamps: indexes: - columns: started_at type: index foreign_keys: - columns: instructor_id references: id table: instructors - columns: studio_id references: id table: studios instructors: columns: id: name: string stores: columns: id: name: string address: string phone_number: string timestamps: studios: columns: id: store_id: unsignedBigInteger name: string timestamps: foreign_keys: - columns: store_id references: id table: stores
  9. YAMLͰදݱͰ͖ͳ͍΋ͷ $ php artisan make:migration create_flights_table <?php use Illuminate\Support\Facades\Schema; use

    Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Query\Expression; use Illuminate\Database\Migrations\Migration; return new class extends Migration { public function up() { Schema::create('flights', function (Blueprint $table) { $table->id(); $table->json('movies')->default(new Expression('(JSON_ARRAY())')); $table->timestamps(); }); } public function down() { Schema::drop('flights'); } }; $ php artisan dacapo ௨ৗͷMigrationϑΝΠϧͱڞଘՄ