5 use DBIx::DBSchema 0.20;
6 use DBIx::DBSchema::Table;
7 use DBIx::DBSchema::Column;
8 use DBIx::DBSchema::ColGroup::Unique;
9 use DBIx::DBSchema::ColGroup::Index;
10 use FS::UID qw(adminsuidsetup);
11 use FS::Record qw(dbdef);
13 my $user = shift or die &usage;
14 my $dbh = adminsuidsetup $user;
18 #false laziness w/fs-setup
19 foreach my $table ( grep { ! /^h_/ } $schema->tables ) {
20 my $tableobj = $schema->table($table);
21 my $h_tableobj = DBIx::DBSchema::Table->new( {
23 primary_key => 'historynum',
24 unique => DBIx::DBSchema::ColGroup::Unique->new( [] ),
25 'index' => DBIx::DBSchema::ColGroup::Index->new( [
26 @{$tableobj->unique->lol_ref},
27 @{$tableobj->index->lol_ref}
30 DBIx::DBSchema::Column->new( {
31 'name' => 'historynum',
38 DBIx::DBSchema::Column->new( {
39 'name' => 'history_date',
46 DBIx::DBSchema::Column->new( {
47 'name' => 'history_user',
54 DBIx::DBSchema::Column->new( {
55 'name' => 'history_action',
62 map { $tableobj->column($_) } $tableobj->columns
65 foreach my $statement ( $h_tableobj->sql_create_table($dbh) ) {
66 $dbh->do( $statement )
67 or die "CREATE error: ". $dbh->errstr. "\ndoing statement: $statement";
72 $dbh->commit or die $dbh->errstr;
73 $dbh->disconnect or die $dbh->errstr;
76 die "Usage:\n create-history-tables user\n";