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

Generation Gap Pattern on CakePHP4

Kanazawa Yuki
September 30, 2022

Generation Gap Pattern on CakePHP4

Kanazawa Yuki

September 30, 2022
Tweet

More Decks by Kanazawa Yuki

Other Decks in Programming

Transcript

  1. Speaker Biography Yuki Kanazawa - Lancers, Inc. / Site Reliability

    Engineer (2013/11 -) - Live in Sapporo, Japan - Github:yKanazawa - Twitter: @yakitori009 - Language: C++, Java, PHP, Go - Hobby: Shogi(Japanese Chess) 2022.09.30 CakeFest
  2. About Lancers Pioneer of "freelance platform" in Japan Basic Crowdsourcing

    Model Global Crowdsourcing Player Management Resources Openness Corporation (Client) Flexible working styles Person (Lancer) 2015 2009 2008 Work or Delivery Escrow payment Upwork Elance+ODesk Freelancer.com Elance 1998 ODesk 2004 2022.09.30 CakeFest
  3. Service Map For Freelancers Services For Clients Services Mentoring Job

    Matching Education Placement Consulting 2022.09.30 CakeFest
  4. Upgrade History ( https://www.lancers.jp/ ) 1.3 → 2.8 2.8 →

    2.10 2.10→ 4.x .. more 5.3 → 5.6 5.6 → 7.3 1.7 year PHP5.6 requires CakePHP2.10 requires PHP7.3 requires 1.8 month 1 day 2 months Ongoing 1.3 5.3 + 2017/06/06 2019/02/05 2019/03/27 2019/03/28 2019/05/28 2022.09.30 CakeFest
  5. Lancers Servers(2019) PHP7.3 CakePHP2.10 lancers PHP7.3 CakePHP2.10 lancers PHP7.3 CakePHP2.10

    lancers EC2 instance CloudFront Route 53 ALB Auto Scaling App Aurora Reader Aurora Reader Aurora Writer Service Batch MySQL5.7 ALB Admin Admin Console Same Repository S3 CloudFront API Gateway Lambda Thumbnail ElastiCache Redis 2022.09.30 CakeFest
  6. Separate repository and rebuild with CakePHP4 PHP7.3 CakePHP4 Lancers_admin PHP7.3

    CakePHP2.10 lancers PHP7.3 CakePHP4 Lancers_batch EC2 instance CloudFront Route 53 ALB Auto Scaling App Aurora Reader Aurora Reader Aurora Writer Service Batch MySQL5.7 ALB Admin Admin Console S3 CloudFront API Gateway Lambda Thmbnail ElastiCache Redis New development with CakePHP4 New development with CakePHP4 2022.09.30 CakeFest
  7. Migration to containers(2022-) PHP8.1 CakePHP4.3 PHP7.3 CakePHP2.10 PHP8.1 CakePHP4.3 EC2

    instance CloudFront Route 53 ALB Auto Scaling App Aurora Reader Aurora Reader Aurora Writer Service Batch (Scheduling Task) ALB Admin Admin Console Fargate CloudWatch Logs Transferred by AWS Logs Kinesis Firehose S3 CloudFront API Gateway Lambda Thmbnail ElastiCache Redis Deploy 2022.09.30 CakeFest
  8. UpGrade Progress (admin, batch) Progress admin CakePHP4 75% batch CakePHP4

    50% main CakePHP2 ・Migration from main repository to admin and batch repositories on migration 2022.09.30 CakeFest
  9. What is Generation Gap Pattern? ・A kind of design pattern

    ・Patterns that assume automatic source code generation tools ・Designs that can be automatically generated again after design changes 2022.09.30 CakeFest
  10. Examples of automatic source code generation tools ・Visual Studio Wizard

    ・GitHub Copilot ・Ruby on rails rails generate ・Laravel artisan ・CakePHP bake and more.. 2022.09.30 CakeFest
  11. What is Generation Gap Pattern? ・Automatic source generator generates only

    superclass sources ・The programmer creates only its subclasses ・Instantiate only subclasses ・Subclasses inherit, override, or add new methods to superclass methods ・The auto-generator does not change the interface (API) used from the subclass. ・The automatic generation tool does not change the Template Method either. 2022.09.30 CakeFest
  12. Model generated by executing bake + config + src +

    Controller + Lib + Model + Entity + User.php + Table + UserTable.php + tests + Fixture + UsersFixture.php + TestCase + Model + Table + UserTableTest.php + vendor + webroot Entity User Table UsersTable Bake DB Table structure 2022.09.30 CakeFest
  13. Additional implementation in the generated model + config + src

    + Controller + Lib + Model + Entity + User.php + Table + UserTable.php + tests + Fixture + UsersFixture.php + TestCase + Model + Table + UserTableTest.php + vendor + webroot Entity User Table UsersTable implement DB Bake 2022.09.30 CakeFest
  14. Add columns to the database tables + config + src

    + Controller + Lib + Model + Entity + User.php + Table + UserTable.php + tests + Fixture + UsersFixture.php + TestCase + Model + Table + UserTableTest.php + vendor + webroot Entity User Table UsersTable Bake DB ALTER TABLE 2022.09.30 CakeFest
  15. We want to reflect the updated results, but... + config

    + src + Controller + Lib + Model + Entity + User.php + Table + UserTable.php + tests + Fixture + UsersFixture.php + TestCase + Model + Table + UserTableTest.php + vendor + webroot Entity User Table UsersTable Bake DB Updated Table structure Implementation is lost 2022.09.30 CakeFest ALTER TABLE
  16. Interleave superclass for auto-generation + config + src + Controller

    + Lib + Model + Baked + Entity + User.php + Table + UserTable.php + Entity + User.php + Table + UserTable.php + tests + Fixture + UserFixture.php + TestCase + Model + Table + UserTableTest.php + vendor + webroot Entity Baked¥User Table Baked¥UsersTable User UsersTable Bake DB Table structure 2022.09.30 CakeFest
  17. Inherit from auto-generated superclass + config + src + Controller

    + Lib + Model + Baked + Entity + User.php + Table + UserTable.php + Entity + User.php + Table + UserTable.php + tests + Fixture + UserFixture.php + TestCase + Model + Table + UserTableTest.php + vendor + webroot <?php declare(strict_types=1); namespace App¥Model¥Table; use App¥Model¥Baked¥Table¥UsersTable as BakedTable; use Cake¥ORM¥RulesChecker; use Cake¥Validation¥Validator; /** * {@inheritDoc} */ class UsersTable extends BakedTable <?php declare(strict_types=1); namespace App¥Model¥Entity; use App¥Model¥Baked¥Entity¥User as BakedEntity; /** * User Entity * {@inheritDoc} … */ class User extends BakedEntity { 2022.09.30 CakeFest
  18. Additional implementation in inherited classes + config + src +

    Controller + Lib + Model + Baked + Entity + User.php + Table + UserTable.php + Entity + User.php + Table + UserTable.php + tests + Fixture + UserFixture.php + TestCase + Model + Table + UserTableTest.php + vendor + webroot Entity Baked¥User Table Baked¥UsersTable User UsersTable implement DB Bake 2022.09.30 CakeFest
  19. Database(Table) is updated + config + src + Controller +

    Lib + Model + Baked + Entity + User.php + Table + UserTable.php + Entity + User.php + Table + UserTable.php + tests + Fixture + UserFixture.php + TestCase + Model + Table + UserTableTest.php + vendor + webroot Entity Baked¥User Table Baked¥UsersTable User UsersTable Bake DB implement Bake DB ALTER TABLE 2022.09.30 CakeFest
  20. Reflects updated results in superclass + config + src +

    Controller + Lib + Model + Baked + Entity + User.php + Table + UserTable.php + Entity + User.php + Table + UserTable.php + tests + Fixture + UserFixture.php + TestCase + Model + Table + UserTableTest.php + vendor + webroot Entity Baked¥User Table Baked¥UsersTable User UsersTable Bake DB implement Bake DB Updated Table structure 2022.09.30 CakeFest ALTER TABLE
  21. Diff of default and plugin behavior + config + src

    + Controller + Lib + Model + Baked + Entity + User.php + Table + UserTable.php + Entity + Table + tests + Fixture + UserFixture.php + TestCase + Model + Table + UserTableTest.php + vendor + webroot $ ./bin/cake bake extended_model users + config + src + Controller + Lib + Model + Entity + User.php + Table + UserTable.php + tests + Fixture + UserFixture.php + TestCase + Model + Table + UserTableTest.php + vendor + webroot $ ./bin/cake bake model users 2022.09.30 CakeFest