X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=bin%2Fdbdef-create;h=c977f876ed7c801b8cdb05f664a9aacec1dfe9f7;hp=fe7475becd09b0fcb279b7718689bfacb81f45f7;hb=2b6242f9d8fe2d9afb3937e3eea03cd0ece1e5f8;hpb=8935cf3566726a2757c3b8f988acfcc0b7ac9352 diff --git a/bin/dbdef-create b/bin/dbdef-create index fe7475bec..c977f876e 100755 --- a/bin/dbdef-create +++ b/bin/dbdef-create @@ -1,21 +1,11 @@ #!/usr/bin/perl -Tw # -# $Id: dbdef-create,v 1.2 1998-11-19 11:17:44 ivan Exp $ -# -# create dbdef file for existing mySQL database (needs SHOW|DESCRIBE command -# not in Pg) based on fs-setup -# -# ivan@sisd.com 98-jun-2 -# -# $Log: dbdef-create,v $ -# Revision 1.2 1998-11-19 11:17:44 ivan -# adminsuidsetup requires argument -# +# $Id: dbdef-create,v 1.6 2002-09-19 13:34:52 ivan Exp $ use strict; use DBI; -use FS::dbdef; -use FS::UID qw(adminsuidsetup datasrc); +use DBIx::DBSchema 0.21; +use FS::UID qw(adminsuidsetup datasrc driver_name); my $user = shift or die &usage; @@ -24,70 +14,9 @@ my($dbh)=adminsuidsetup $user; #needs to match FS::Record my($dbdef_file) = "/usr/local/etc/freeside/dbdef.". datasrc; -my($tables_sth)=$dbh->prepare("SHOW TABLES"); -my($tables_rv)=$tables_sth->execute; - -my(@tables); -foreach ( @{$tables_sth->fetchall_arrayref} ) { - my($table)=${$_}[0]; - #print "TABLE\t$table\n"; - - my($index_sth)=$dbh->prepare("SHOW INDEX FROM $table"); - my($primary_key)=''; - my(%index,%unique); - for ( 1 .. $index_sth->execute ) { - my($row)=$index_sth->fetchrow_hashref; - if ( ${$row}{'Key_name'} eq "PRIMARY" ) { - $primary_key=${$row}{'Column_name'}; - next; - } - if ( ${$row}{'Non_unique'} ) { #index - push @{$index{${$row}{'Key_name'}}}, ${$row}{'Column_name'}; - } else { #unique - push @{$unique{${$row}{'Key_name'}}}, ${$row}{'Column_name'}; - } - } - - my(@index)=values %index; - my(@unique)=values %unique; - #print "\tPRIMARY KEY $primary_key\n"; - foreach (@index) { - #print "\tINDEX\t", join(', ', @{$_}), "\n"; - } - foreach (@unique) { - #print "\tUNIQUE\t", join(', ', @{$_}), "\n"; - } - - my($columns_sth)=$dbh->prepare("SHOW COLUMNS FROM $table"); - my(@columns); - for ( 1 .. $columns_sth->execute ) { - my($row)=$columns_sth->fetchrow_hashref; - #print "\t", ${$row}{'Field'}, "\n"; - ${$row}{'Type'} =~ /^(\w+)\(?([\d\,]+)?\)?( unsigned)?$/ - or die "Illegal type ${$row}{'Type'}\n"; - my($type,$length)=($1,$2); - my($null)=${$row}{'Null'}; - $null =~ s/YES/NULL/; - push @columns, new FS::dbdef_column ( - ${$row}{'Field'}, - $type, - $null, - $length, - ); - } - - #print "\n"; - push @tables, new FS::dbdef_table ( - $table, - $primary_key, - new FS::dbdef_unique (\@unique), - new FS::dbdef_index (\@index), - @columns, - ); - -} +my $dbdef = new_native DBIx::DBSchema $dbh; -my($dbdef) = new FS::dbdef ( @tables ); +#print $dbdef->pretty_print; #important $dbdef->save($dbdef_file);