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. Generation Gap Pattern
    on CakePHP4
    2022.09.30 CakeFest
    2022.09.30 CakeFest

    View Slide

  2. 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

    View Slide

  3. About Lancers
    2022.09.30 CakeFest

    View Slide

  4. 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

    View Slide

  5. Service Map
    For Freelancers
    Services
    For Clients
    Services
    Mentoring
    Job Matching
    Education
    Placement
    Consulting
    2022.09.30 CakeFest

    View Slide

  6. https://www.lancers.jp/
    Upgrade History
    2022.09.30 CakeFest

    View Slide

  7. 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

    View Slide

  8. 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

    View Slide

  9. 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

    View Slide

  10. 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

    View Slide

  11. 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

    View Slide

  12. What is Generation Gap Pattern?
    2022.09.30 CakeFest

    View Slide

  13. 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

    View Slide

  14. 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

    View Slide

  15. 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

    View Slide

  16. Conditions for
    Generation Gap Pattern
    on CakePHP4
    2022.09.30 CakeFest

    View Slide

  17. 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

    View Slide

  18. 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

    View Slide

  19. 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

    View Slide

  20. 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

    View Slide

  21. Generation Gap Pattern
    on CakePHP4
    2022.09.30 CakeFest

    View Slide

  22. News: New bake updates ( --updates option)
    2022.09.30 CakeFest

    View Slide

  23. 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

    View Slide

  24. 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
    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
    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

    View Slide

  25. 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

    View Slide

  26. 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

    View Slide

  27. 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

    View Slide

  28. Introduce Plugin
    2022.09.30 CakeFest

    View Slide

  29. Plugin for Generation Gap Pattern on CakePHP4
    ・lancers/cakephp-
    generation-gap-pattern-
    model-baker
    2022.09.30 CakeFest

    View Slide

  30. 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

    View Slide

  31. New bake updates
    2022.09.30 CakeFest

    View Slide

  32. New bake updates only table structure!
    ・In Bake 2.8.0-RC1
    2022.09.30 CakeFest

    View Slide