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

Migrating Anything with Baleen

Migrating Anything with Baleen

Several migration frameworks and libraries have been created over the years in order to help developers manage their data and schema changes in a reliable, collaborative manner. But even well-adopted solutions like Phinx and Doctrine Migrations have either struggled to keep-up with modern PHP due to architectural issues, or failed to provide enough framework integration to be actually practical for everyday use.

In this talk I'll guide you through Baleen: an open-source PHP framework that synthesizes the very core of the migrations mechanism into a “domain library”, which can be re-used to power migrations for virtually any modern PHP framework (not kidding!). I'll also reveal plans of re-building Doctrine Migrations using the Baleen framework. But most importantly, you'll see an example of how separating common logic into small domain models can help you invent and contribute relevant modules to the open-source community.

Gabriel Somoza

January 31, 2016
Tweet

More Decks by Gabriel Somoza

Other Decks in Technology

Transcript

  1. About Me • Started coding around 2000 • Consultant PHP

    Architect (Strategery) @ Cu.be • ZCE & Magento Certified Developer (PLUS) • Organizer of the PHP Limburg meetup in Belgium • Regularly contribute to open-source
  2. Describing Change Q1 Q2 Q3 d1 d2 Git Commits Qn

    = States dn = Deltas Source: http://gá.be/1PrKEAh STATE baleen.org
  3. Describing Change Q1 Q2 Q3 d1 d2 SVN, Mercurial, etc.

    Qn = States dn = Deltas Source: http://gá.be/1PrKEAh DELTAS baleen.org
  4. Collaborating with Deltas About Migrations Feature A Feature B Production

    Continuous Integration Stage D1 D2 D1 D2 D1 D2 baleen.org
  5. The Migrations Ecosystem FRAGME Doctrine Migrations Phinx Laravel Migrations Magento

    (Install Scripts) CakePHP Yii Migrations NTED baleen.org
  6. Challenges of Fragmentation • No unified vision / roadmap •

    Features cannot be ported • Incomplete tests (or none at all) • Repeated business logic = Poor Community Experience baleen.org
  7. The Idea 21 You! Anyone can contribute, there’s lots to

    do Mike Simonson Maintainer for Doctrine Migrations & Baleen co-author Gabriel Somoza Baleen Architect baleen.org baleen.org
  8. Packages Overview Baleen Migrations Baleen CLI Doctrine Laravel Phinx Etc.

    Web App Entities Business Logic Value Objects Generic Tasks (Commands) Config Specialization Config Views Views baleen.org The Baleen Ecosystem
  9. Community Effort Cycle Enriches Gives Back Baleen Migrations Baleen CLI

    Doctrine Laravel Phinx Etc. Web App baleen.org The Baleen Ecosystem
  10. What Baleen IS • A framework- and infrastructure- agnostic domain

    model • Designed to empower migration tools • With sensible defaults but highly customizable • An open-source project for the PHP community (MIT) • Very well tested baleen.org
  11. What Baleen is NOT • Another migration library • An

    API / DSL that with a similar workflow to Phinx or Java’s Liquibase • A magic bullet baleen.org
  12. Our Sample Scenarios I. You are using a DAL, like

    Doctrine. II. It has no tools for managing deltas (migrations). III. You build a tool from scratch. IV. It has only the features you need. I. Probably not enough tests. II. Its not generic enough to redistribute. V. You work a lot to get it to a point where you can distribute it. (or use-cases) #1 baleen.org
  13. Our Sample Scenarios I. You are using a DAL, like

    Doctrine. II. It has no tools for managing deltas (migrations). III. You build a tool from scratch. (or use-cases) #1 baleen.org
  14. Our Sample Scenarios I. You are using a DAL, like

    Doctrine. II. It has no tools for managing deltas (migrations). III. You build a tool from scratch. (or use-cases) #1 baleen.org
  15. Our Sample Scenarios I. You are using a DAL, like

    Doctrine. II. It has no tools for managing deltas (migrations). III. You build a tool using Baleen. IV. You get most features out of the box. V. Test coverage for the core mechanisms. VI. Detailed documentation for end-users. VII. Your end-users already know how Baleen works. (or use-cases) #1 baleen.org
  16. Our Sample Scenarios I. You’re using a tool that’s already

    based on Baleen. II. You’d like to have a “status” command (new feature). III. You contribute that feature to the core library. IV. Every other tool that uses Baleen can now get that feature. Not only yours. (or use-cases) #2 baleen.org
  17. The Migrations Domain Who are the Domain Experts ? •

    Framework Authors & Contributors • Database Administrators • Deployment Managers baleen.org
  18. The Migrations Domain Who are the End-Users ? • Developers

    that use your migration tool to manage deltas (migrations). baleen.org
  19. The Migrations Domain (how we see it) Migration Tool (e.g.

    Baleen CLI) Target Domain Model Infrastructure Data-Access Layer (ORM / ODM / etc.) baleen.org
  20. Baleen Architectural Overview 37 Delta (Aggregate) Domain Model Migration Class

    Business Logic Baleen Core Commands Events State Storage DAL Target Domain Migration Tool Target Domain Infrastructure DAL Config Infrastructure baleen.org
  21. Commands Baleen Architectural Overview 44 Domain Model Business Logic Baleen

    Core baleen.org Events State Storage DAL Target Domain Migration Tool Target Domain Infrastructure DAL Config Infrastructure Migration Class Delta (Aggregate)
  22. Delta Aggregate Uniquely IDENTIFIES a migration file, STATE and can

    INVOKE it knows its when commanded. baleen.org
  23. Commands Baleen Architectural Overview 47 Delta (Aggregate) Domain Model Business

    Logic Baleen Core baleen.org Events State Storage DAL Target Domain Migration Tool Target Domain Infrastructure DAL Config Infrastructure Migration Class
  24. Migration Class Life-Cycle Migration Class Requested Factory Injects •Application •Infrastructure

    Instance migrate(direction) •Customizable process •Fires events Update state Done baleen.org
  25. Baleen Architectural Overview 54 Delta (Aggregate) Domain Model Migration Class

    Business Logic Baleen Core baleen.org Events State Storage DAL Target Domain Migration Tool Target Domain Infrastructure DAL Config Infrastructure Commands
  26. Migrate Command Migrates through one or more DELTAS towards a

    target using one of the following strategies: UP DOWN CONVERGE baleen.org
  27. Domain Events Ubiquitous Language v1 v2 v3 v4 v5 target

    head BeforeCollection Deltas to Migrate Target version Options baleen.org
  28. Domain Events Ubiquitous Language v1 v2 v3 v4 v5 target

    head BeforeMigration Delta Options Collection Context baleen.org
  29. Domain Events Ubiquitous Language v1 v2 v3 v4 v5 target

    head AfterMigration Delta Options Collection Context baleen.org
  30. Domain Events Ubiquitous Language v1 v2 v3 v4 v5 target

    head AfterCollection Modified Deltas Target Options baleen.org
  31. How YOU Can Help The Migration Ecosystem Tomorrow 1. Review

    Code 2. Spread the Word 3. Fork and Contribute! 4. Integrate baleen.org