Business-Cart-Generic

 view release on metacpan or  search on metacpan

lib/Business/Cart/Generic/Database/Create.pm  view on Meta::CPAN

package Business::Cart::Generic::Database::Create;

use strict;
use warnings;

use DBIx::Admin::CreateTable;

use Moose;

use Try::Tiny;

extends 'Business::Cart::Generic::Base';

has creator =>
(
 is       => 'rw',
 isa      => 'DBIx::Admin::CreateTable',
 required => 0,
);

has engine =>
(
 is       => 'rw',
 isa      => 'Str',
 required => 0,
);

has time_option =>
(
 is       => 'rw',
 isa      => 'Str',
 required => 0,
);

use namespace::autoclean;

our $VERSION = '0.85';

# -----------------------------------------------

sub BUILD
{
	my($self) = @_;

	$self -> creator
		(
		 DBIx::Admin::CreateTable -> new
		 (
		  dbh     => $self -> connector -> dbh,
		  verbose => 0,
		 )
		);

	$self -> engine
		(
		 $self -> creator -> db_vendor =~ /(?:Mysql)/i ? 'engine=innodb' : ''
		);

	$self -> time_option
		(
		 $self -> creator -> db_vendor =~ /(?:MySQL|Postgres)/i ? '(0) without time zone' : ''
		);

}	# End of BUILD.

# -----------------------------------------------

sub create_all_tables
{
	my($self) = @_;

	$self -> connector -> txn
		(
		 fixup => sub{ $self -> create_tables }, catch{ defined $_ ? die $_ : ''}
		);

}	# End of create_all_tables.

# -----------------------------------------------

sub create_tables
{
	my($self) = @_;

	# Warning: The order is important.

	my($method);
	my($table_name);

	# Note: The logger creates the log table, if necessary.

	for $table_name (qw/
log
sessions
yes_no



( run in 2.712 seconds using v1.01-cache-2.11-cpan-98e64b0badf )