package #
  DBICTest;

use strict;
use warnings;

use DBICTest::Schema;

sub _database {
    my $self = shift;
    my $db_file = "t/var/DBIxClass.db";

    unlink($db_file) if -e $db_file;
    unlink($db_file . "-journal") if -e $db_file . "-journal";
    mkdir("t/var") unless -d "t/var";

    my $dsn = $ENV{"DBICTEST_DSN"} || "dbi:SQLite:${db_file}";
    my $dbuser = $ENV{"DBICTEST_DBUSER"} || '';
    my $dbpass = $ENV{"DBICTEST_DBPASS"} || '';

    my @connect_info = ($dsn, $dbuser, $dbpass, { AutoCommit => 1 });

    return @connect_info;
}

sub init_schema {
    my $class = shift;
    my %args = @_;

    my $schema;

    $schema = DBICTest::Schema->compose_namespace($class);

    if ( !$args{no_connect} ) {
      $schema = $schema->connect($class->_database);
      $schema->storage->on_connect_do(['PRAGMA synchronous = OFF']);
    }
    if ( !$args{no_deploy} ) {
        __PACKAGE__->deploy_schema( $schema );
    }
    return $schema;
}

sub deploy_schema {
    my $class = shift;
    my $schema = shift;

    return $schema->deploy();
}

1;
