MySQL::Workbench::DBIC - create DBIC scheme for MySQL workbench .mwb files
version 0.04
use MySQL::Workbench::DBIC; my $foo = MySQL::Workbench::DBIC->new( file => '/path/to/file.mwb', output_path => $some_path, namespace => 'MyApp::DB', version_add => 0.01, column_details => 1, # default 1 use_fake_dbic => 1, # default 0 ); $foo->create_schema;
creates a new object of MySQL::Workbench::DBIC. You can pass some parameters to new:
my $foo = MySQL::Workbench::DBIC->new( output_path => '/path/to/dir', input_file => '/path/to/dbdesigner.file', namespace => 'MyApp::Database', version_add => 0.001, schema_name => 'MySchema', column_details => 1, use_fake_dbic => 1, # default 0. belongs_to_prefix => 'fk_', has_many_prefix => 'has_', );
use_fake_dbic is helpful when DBIx::Class is not installed on the machine where you use this module.
use_fake_dbic
DBIx::Class
creates all the files that are needed to work with DBIx::Class schema:
The main module that loads all classes and one class per table. If you haven't specified an input file, the module will croak.
sets / gets the output path for the scheme
print $foo->output_path;
sets / gets the name of the Workbench file
print $foo->input_file;
If enabled, the column definitions are more detailed. Default: disabled.
Standard (excerpt from Result classes):
__PACKAGE__->add_columns( qw/ cert_id register_nr state );
With enabled column details:
__PACKAGE__->add_columns( cert_id => { data_type => 'integer', is_nullable => 0, is_auto_increment => 1, }, register_nr => { data_type => 'integer', is_nullable => 0, }, state => { data_type => 'varchar', size => 1, is_nullable => 0, default_value => 'done', }, );
This is useful when you use DBIx::Class::DeploymentHandler to deploy the columns correctly.
The files should be versioned (e.g. to deploy the DB via DBIx::Class::DeploymentHandler). On the first run the version is set to "0.01". When the schema file already exists, the version is increased by the value of version_add (default: 0.01)
DBIx::Class::DeploymentHandler
version_add
sets a new name for the schema. By default on of these names is used:
DBIC_Scheme Database DBIC MyScheme MyDatabase DBIxClass_Scheme
sets / gets the name of the namespace. If you set the namespace to 'Test' and you have a table named 'MyTable', the main module is named 'Test::DBIC_Scheme' and the class for 'MyTable' is named 'Test::DBIC_Scheme::MyTable'
In relationships the accessor for the objects of the "other" table shouldn't have the name of the column. Otherwise it is very clumsy to get the orginial value of this table.
'belongs_to' => 'fk_' 'has_many' => 'has_'
creates (col1 is the column name of the foreign key)
__PACKAGE__->belongs_to( 'fk_col1' => 'OtherTable', {'foreign.col1' => 'self.col1' } );
Renee Baecker <reneeb@cpan.org>
This software is Copyright (c) 2013 by Renee Baecker.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install MySQL::Workbench::DBIC, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MySQL::Workbench::DBIC
CPAN shell
perl -MCPAN -e shell install MySQL::Workbench::DBIC
For more information on module installation, please visit the detailed CPAN module installation guide.