initial copy of text from email
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / Cookbook / CustomVersionHandler.pod
CommitLineData
0453c87d 1DBIx::Class::DeploymentHandler (short name of DBICDH) is a tool for creating
2and upgrading your database. In code it is a significant extension of
3DBIx::Class::Schema::Versioned; in spirit it is similar to ActiveRecord
4migrations, but at a different angle; with this tool you define your database's
5schema (and thus your migrations as well) with the perl classes instead of
6having your migrations define the database and *that* defining your schema.
7
8In general the tool is as simple as instantiating a DBICDH with a DBIC schema
9and calling ->install or ->upgrade. But what makes DBICDH so much nicer
10than DBIx::Class::Schema::Versioned is it's extensibility. DBICDH uses a
11combination of delegation and roles to allow for easy extension and code reuse.
12
13There are 3 basic parts (which are delegated to) in a typical DBICDH:
14
15 1. VersionHandler: The component that says what version to go to next
16 2. VersionStorage: The component that knows the version of the current
17 database 3. DeployMethod: The component that generates and runs the sql
18 for migrations
19
20Again, typically people will go with the defaults, but if someone wants to
21do something unusual the first thing that will get overridden will probably
22be the VersionHandler.
23
24The default VersionHandler merely upgrades (and downgrades) with monotonic
25integers, increasing and decreasing respectively. So if your database is at
26version 5 and you ask to upgrade to version 10, it will request the following
27discrete migrations to be deployed, in order: (5,6), (6,7), (7,8), (8,9),
28(9,10).
29
30Now lets say we are working on a large project and the database deploys
31are piling up. Programmer Jack has set up a user authentication system.
32Programmer Steve has set up a verification system based on Jacks auth.
33Programmer Antonio has created a "friend" system in the spirit of social
34networking which is also based on Jacks auth. Lastly Programmer Bethany
35has created a parts management system which does not depend on any of the
36other systems.
37
38Basically we can look at these as 4 distinct "versions" of the database, let's
39call them "Auth", "Verification", "Friends", and "Parts." If code is managed
40carefully supposedly git can be used to see what code depends on other code.
41Let's pretend that we already have that part working. Using such a tool
42would allow us to query git to discover what database versions depend on
43other versions and thus allow a non-linear migration path, allowing QC to
44take more time on more complex features without holding up the deployment
45of different parts of the live database.
46
47Lets do a quick example using the versions we've defined above. QC requests
48to install "Verification" since it's a major feature that must exist in the
49live site even before a private beta. Our overridden VersionHandler will
50query git and see that "Verification" depends on "Auth." It will then query
51git again to see what "Auth" depends on and it will discover that "Auth"
52does not depend on anything else. So it will run two migrations, first
53"Auth," and then "Verification."
54
55QC signs off on "Verification" and it gets deployed to the live site and
56the beta begins. Meanwhile Antonio and Bethany both finish their respective
57subsystems. QC requests that "Parts" be installed. Because Parts depends on
58nothing else, it installs, QC likes it, it also gets deployed to the live beta.
59
60QC asks for Antonio's "Friend" system to be deployed, and because it only
61depends on "Auth," which is already installed, it has no new dependencies
62and is installed just fine. Finally, QC signs off on this last subsystem
63and it is also deployed to the live site.
64
65The beauty of a system like the above described is that it allows the database
66to be upgraded based on what's ready as opposed to what people are working on.
67And because VersionHandler can easily be replaced with a more sophisticated
68VersionHandler the above is completely feasible, assuming the communication
69with git can be done (and it can.)