DBIx-Table-TestDataGenerator

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

        If true, new root nodes will have NULL as parent id, otherwise the
        value of their primary key column. Defaults to false. The value
        should be set according to the convention used in the target table.

    *   csv_dir

        Optional path to a csv file which will contain the test data, no
        data will be written to the target database in this case. If not
        defined, changes are applied to the target database.

    *   keep_connection_alive

        Optional parameter defining if the database handle dbh should still
        be connected after having created the test data, defaults to false.
        (For some install tests, we need to set it to true since we are
        using an in-memory database which would otherwise not be accessible
        for the tests, but this may also be of use in other scenarios.)

    *   transaction_size

        Optional parameter defining a transaction size. In case transactions

README  view on Meta::CPAN


    Returns:

    Nothing, only called for the side-effect of adding new records to the
    target table. (This may change, see the section "FURTHER DEVELOPMENT".)

  disconnect
    Arguments: none

    Allows to disconnect the connection to the target database in case
    keep_connection_alive was set to true before when calling
    create_testdata.

INSTALLATION AND CONFIGURATION
    To install this module, run the following commands:

            perl Build.PL
            ./Build
            ./Build test
            ./Build install

lib/DBIx/Table/TestDataGenerator.pm  view on Meta::CPAN

    sub create_testdata {
        my ( $self, %args ) = @_;

        my $target_size               = $args{target_size};
        my $num_random                = $args{num_random};
        my $max_tree_depth            = $args{max_tree_depth};
        my $min_children              = $args{min_children};
        my $min_roots                 = $args{min_roots};
        my $roots_have_null_parent_id = $args{roots_have_null_parent_id};
        my $csv_dir                   = $args{csv_dir};
        my $keep_connection_alive     = $args{keep_connection_alive};
        my $transaction_size          = $args{transaction_size};

        my $dumper = DBIxSchemaDumper->new(
            dsn                   => $self->dsn,
            user                  => $self->user,
            password              => $self->password,
            table                 => $self->table,
            on_the_fly_schema_sql => $self->on_the_fly_schema_sql,
        );

lib/DBIx/Table/TestDataGenerator.pm  view on Meta::CPAN

            #Commit all inserts.
            Query->commit($dbh_out)
              if !$is_autocommit
              && (
                (
                       $transaction_size
                    && $num_records_added % $transaction_size != 0
                )
                || !$transaction_size
              );
            Query->disconnect($dbh_out) unless $keep_connection_alive;
        };

        if ($@) {
            warn "Transaction aborted because $@";
            eval { $dbh->rollback };
        }

        return;
    }

lib/DBIx/Table/TestDataGenerator.pm  view on Meta::CPAN

In case of a self-reference, the minimum number of root elements to create. A record is considered to be a root element if the corresponding parent id is null or equal to the child id.

=item * roots_have_null_parent_id

If true, new root nodes will have NULL as parent id, otherwise the value of their primary key column. Defaults to false. The value should be set according to the convention used in the target table.

=item * csv_dir

Optional path to a csv file which will contain the test data, no data will be written to the target database in this case. If not defined, changes are applied to the target database.

=item * keep_connection_alive

Optional parameter defining if the database handle dbh should still be connected after having created the test data, defaults to false. (For some install tests, we need to set it to true since we are using an in-memory database which would otherwise ...

=item * transaction_size

Optional parameter defining a transaction size. In case transactions are not supported, setting the parameter has no effect. If transactions are supported, omitting the parameter resp. setting its value to 0 will result in one big transaction being u...

=back

Returns:

Nothing, only called for the side-effect of adding new records to the target table. (This may change, see the section L</"FURTHER DEVELOPMENT">.)

=head2 disconnect

Arguments: none

Allows to disconnect the connection to the target database in case keep_connection_alive was set to true before when calling create_testdata.

=head1 INSTALLATION AND CONFIGURATION

To install this module, run the following commands:

	perl Build.PL
	./Build
	./Build test
	./Build install

t/02DataGeneration.t  view on Meta::CPAN

my $min_children = 2;
my $min_roots    = 2;
my $max_tree_depth = 3;

$generator->create_testdata(
    target_size           => $target_size,
    num_random            => $num_random,
    max_tree_depth        => $max_tree_depth,
    min_children          => $min_children,
    min_roots             => $min_roots,
    keep_connection_alive => 1,
    transaction_size      => 100,
);

#test number of records
is( Query->num_records( $generator->schema, $table ),
    $target_size, "there are now $target_size records in the target table" );

#test number of roots
ok( SelfReference->num_roots( $generator->schema, $table ) >= $min_roots,
    "the number of roots is at least $min_roots" );

t/03DataGeneration_null_root_parents.t  view on Meta::CPAN

my $min_roots    = 3;
my $max_tree_depth = 5;

$generator->create_testdata(
    target_size               => $target_size,
    num_random                => $num_random,
    max_tree_depth            => $max_tree_depth,
    min_children              => $min_children,
    min_roots                 => $min_roots,
    roots_have_null_parent_id => 1,
    keep_connection_alive     => 1,
);

#test number of records
is( Query->num_records( $generator->schema, $table ),
    $target_size, "there are now $target_size records in the target table" );

#test number of roots
ok( SelfReference->num_roots( $generator->schema, $table, 1 ) >= $min_roots,
    "the number of roots is at least $min_roots" );



( run in 1.121 second using v1.01-cache-2.11-cpan-39bf76dae61 )