#!/usr/bin/perl

use strict;
use warnings;
use DBI;

my $instances = 10000;

my $dbh = DBI->connect('dbi:mysql:database=test;host=172.16.0.1', 'root', '');
my @schema = (
    'DROP TABLE IF EXISTS acl',
    'DROP TABLE IF EXISTS grp',
    'CREATE TABLE acl(id INT PRIMARY KEY, type VARCHAR(32))',
    'CREATE TABLE grp(id INT PRIMARY KEY AUTO_INCREMENT, type VARCHAR(32), domain VARCHAR(32), instance INT)',
);
$dbh->do($_) foreach @schema;

$dbh->do("INSERT INTO acl VALUES(1, 'Owner')");
$dbh->do("INSERT INTO acl VALUES(2, 'Owner')");
foreach my $type ( qw(Owner Requester Cc AdminCc) ) {
    my $domain = 'RT::Ticket-Role';
    foreach my $instance ( 1 .. $instances ) {
        $dbh->do("INSERT INTO grp(type, domain, instance) VALUES('$type', '$domain', $instance)");
    }
}

my @indexes = (
    'CREATE INDEX grp1 ON grp(type, domain, instance)',
    'CREATE INDEX grp2 ON grp(domain, instance, type)',
);
$dbh->do($_) foreach @indexes;
