summaryrefslogtreecommitdiff
path: root/bin/dbdef-create
diff options
context:
space:
mode:
authorivan <ivan>2001-04-15 12:56:31 +0000
committerivan <ivan>2001-04-15 12:56:31 +0000
commit018f6678557506e68cc6b8643862143cc332f7da (patch)
tree276ff363102fd038795946f30baa6eda64655e7b /bin/dbdef-create
parent3b817663a3667edaf8d2130c3a8d0fe38e5f2fa0 (diff)
s/dbdef/DBIx::DBSchema/
Diffstat (limited to 'bin/dbdef-create')
-rwxr-xr-xbin/dbdef-create76
1 files changed, 8 insertions, 68 deletions
diff --git a/bin/dbdef-create b/bin/dbdef-create
index fe7475bec..902f7f145 100755
--- a/bin/dbdef-create
+++ b/bin/dbdef-create
@@ -1,6 +1,6 @@
#!/usr/bin/perl -Tw
#
-# $Id: dbdef-create,v 1.2 1998-11-19 11:17:44 ivan Exp $
+# $Id: dbdef-create,v 1.3 2001-04-15 12:56:31 ivan Exp $
#
# create dbdef file for existing mySQL database (needs SHOW|DESCRIBE command
# not in Pg) based on fs-setup
@@ -8,14 +8,17 @@
# ivan@sisd.com 98-jun-2
#
# $Log: dbdef-create,v $
-# Revision 1.2 1998-11-19 11:17:44 ivan
+# Revision 1.3 2001-04-15 12:56:31 ivan
+# s/dbdef/DBIx::DBSchema/
+#
+# Revision 1.2 1998/11/19 11:17:44 ivan
# adminsuidsetup requires argument
#
use strict;
use DBI;
-use FS::dbdef;
-use FS::UID qw(adminsuidsetup datasrc);
+use DBIx::DBSchema;
+use FS::UID qw(adminsuidsetup datasrc driver_name);
my $user = shift or die &usage;
@@ -24,70 +27,7 @@ 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 FS::dbdef ( @tables );
+my $dbdef = new_native DBIx::DBSchema $dbh;
#important
$dbdef->save($dbdef_file);