From: Will Hawes Date: Mon, 23 Jan 2006 17:10:59 +0000 (+0000) Subject: add 'Easy migration from class-based to schema-based setup' X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b0a204547980f707a0542a1ba94536900c9689be;p=dbsrgits%2FDBIx-Class-Historic.git add 'Easy migration from class-based to schema-based setup' --- diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 5618980..ec8948e 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -438,6 +438,44 @@ And import using the mysql client: mysql -h "host" -D "database" -u "user" -p < Schema1.sql +=head2 Easy migration from class-based to schema-based setup + +You want to start using the schema-based approach to L +(see L), but have an established class-based setup with lots +of existing classes that you don't want to move by hand. Try this nifty script +instead: + + use MyDB; + use SQL::Translator; + + my $schema = MyDB->schema_instance; + + my $translator = SQL::Translator->new( + debug => $debug || 0, + trace => $trace || 0, + no_comments => $no_comments || 0, + show_warnings => $show_warnings || 0, + add_drop_table => $add_drop_table || 0, + validate => $validate || 0, + parser_args => { + 'DBIx::Schema' => $schema, + } + producer_args => { + 'prefix' => 'My::Schema', + } + ); + + $translator->parser('DBIx::Class'); + $translator->producer('DBIx::Class::File'); + + my $output = $translator->translate(@args) or die + "Error: " . $translator->error; + + print $output; + +You could use L to search for all subclasses in the MyDB::* +namespace, which is currently left as an excercise for the reader. + =head2 Schema versioning The following example shows simplistically how you might use DBIx::Class to