Created
August 1, 2014 04:55
-
-
Save benkolera/f98cd652bd9b1fcc57c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| use warnings; | |
| =head1 NAME | |
| create_dbic.pl | |
| =head1 SYNOPSIS | |
| perl maintenaince/create_dbic.pl --help | <options> | |
| Options: | |
| [--db_yaml=<value>] | |
| Regenerates the ResultSet classes in lib/iseek/WIGI/MV/CallProcessor/Schema with the | |
| tables from the database. Defaults to using the database yaml in ./etc but can | |
| be overridden on the command line. | |
| If you need more tables in the schema than otherwise provided, then add them to | |
| the tables list in this file. | |
| Also, if any ResultSet classes come out funny (e.g. bearer_vas comes out as | |
| BearerVa.pm due to 'depluralisation') then add the mappings to the monikier_map | |
| in this file. If you add nothing to this then the defaults will be used and are | |
| generally fine. | |
| =head1 OPTIONS | |
| =over 8 | |
| =item B<--help> | |
| Print a brief help message and exits. | |
| =item B<--db_yaml> | |
| The path to the database.yaml if you don't wish to use the one packaged in this | |
| module. | |
| =back | |
| =cut | |
| use Getopt::Long; | |
| use Pod::Usage; | |
| use Log::Log4perl qw(:easy); | |
| BEGIN{ | |
| Log::Log4perl::easy_init($DEBUG); | |
| } | |
| my %options = (); | |
| GetOptions( | |
| \%options, | |
| "help|?", | |
| "db_yaml=s", | |
| 'output_dir=s', | |
| ); | |
| pod2usage(1) if $options{help}; | |
| my $db_yaml_path = | |
| $options{db_yaml} || $ENV{ISEEKDB_CONFIG} || '/etc/iseek-common/database.yaml'; | |
| $iseek::DB::database_setting_override = $db_yaml_path; | |
| use DBIx::Class::Schema::Loader qw/ make_schema_at /; | |
| use Regexp::Trie; | |
| use iseek::DB; | |
| my $rt = Regexp::Trie->new; | |
| my @tables = | |
| qw| | |
| account | |
| account_type | |
| account_details | |
| action | |
| bearer | |
| bearer_plan | |
| client | |
| charge | |
| charge_type | |
| charge_mobile_voice | |
| inventory_status | |
| mobile_bearer | |
| mobile_bearer_log | |
| mobile_number | |
| mobile_voice_output_file | |
| mobile_voice_gsm_content_record | |
| mobile_voice_gsm_data_record | |
| mobile_voice_gsm_home_record | |
| mobile_voice_gsm_message_record | |
| mobile_voice_gsm_roam_record | |
| mobile_voice_gsm_record_charge | |
| plan | |
| plan_mobile | |
| plan_mobile_call_rate | |
| plan_mobile_cap | |
| plan_mobile_cap_consumption | |
| service_type | |
| service_sub_type | |
| template | |
| transaction | |
| vas_type | |
| wholesaler | |
| |; | |
| map { $rt->add($_) } @tables; | |
| my $tables_re = '^' . $rt->regexp . '$'; | |
| my @db_details = iseek::DB::get_connect_string('wigi'); | |
| # Refer to DBIx::Class::Schema::Loader::Base for more options | |
| make_schema_at( | |
| 'iseek::WIGI::MV::Billing::ChargeGenerator::Schema', | |
| { | |
| skip_load_external => 1, | |
| debug => 1 , | |
| schema_base_class => 'iseek::DBIC::Schema', | |
| dump_directory => $options{output_dir} || './lib/', | |
| constraint => $tables_re, | |
| use_moose => 1 , | |
| overwrite_modifications => 1, | |
| # components loads into all resultsets | |
| components => ["InflateColumn::DateTime"] , | |
| # result_component_map specifies components per resultset | |
| #result_comonent_map => {}, | |
| #moniker_map => { | |
| #eg: bearer_vas => "BearerVas" to make BearerVas.pm instead of BearerVa.pm | |
| #}, # Add Stuff to this hash if you need to override the default name mapping | |
| # col_accessor_map => { | |
| # }, # Overrides the naming of columns | |
| #generate_pod => 1, | |
| }, | |
| \@db_details | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment