[freeside-commits] freeside/FS/bin freeside-setup, 1.51,
1.52 freeside-upgrade, NONE, 1.1
Ivan,,,
ivan at wavetail.420.am
Wed Aug 17 15:23:47 PDT 2005
Update of /home/cvs/cvsroot/freeside/FS/bin
In directory wavetail:/tmp/cvs-serv31511/FS/bin
Modified Files:
freeside-setup
Added Files:
freeside-upgrade
Log Message:
infrastructure for easier schema changes, and: add payment_gateway, payment_gateway_option and agent_payment_gateway tables, add paystart_month, paystart_year, payissue and payip fields to cust_main, add preliminary gateway and gateway override editing to web UI, use payment gateway override when processing payments (card type, not taxclass yet)
Index: freeside-setup
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/bin/freeside-setup,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- freeside-setup 7 Apr 2005 09:26:18 -0000 1.51
+++ freeside-setup 17 Aug 2005 22:23:45 -0000 1.52
@@ -1,29 +1,24 @@
#!/usr/bin/perl -Tw
#to delay loading dbdef until we're ready
-BEGIN { $FS::Record::setup_hack = 1; }
+BEGIN { $FS::Schema::setup_hack = 1; }
use strict;
use vars qw($opt_s);
use Getopt::Std;
use Locale::Country;
use Locale::SubCountry;
[...1145 lines suppressed...]
-
- 'clientapi_session_field' => {
- 'columns' => [
- 'fieldnum', 'serial', '', '',
- 'sessionnum', 'int', '', '',
- 'fieldname', 'varchar', '', $char_d,
- 'fieldvalue', 'text', 'NULL', '',
- ],
- 'primary_key' => 'fieldnum',
- 'unique' => [ [ 'sessionnum', 'fieldname' ] ],
- 'index' => [],
- },
-
- );
-
- %tables;
-
-}
+1;
--- NEW FILE: freeside-upgrade ---
#!/usr/bin/perl -w
use strict;
use vars qw($DEBUG $DRY_RUN);
use Term::ReadKey;
use DBIx::DBSchema 0.27;
use FS::UID qw(adminsuidsetup checkeuid datasrc ); #getsecrets);
use FS::Schema qw( dbdef dbdef_dist reload_dbdef );
$DEBUG = 1;
$DRY_RUN = 0;
die "Not running uid freeside!" unless checkeuid();
my $user = shift or die &usage;
my $dbh = adminsuidsetup($user);
#needs to match FS::Schema...
my $dbdef_file = "/usr/local/etc/freeside/dbdef.". datasrc;
dbdef_create($dbh, $dbdef_file);
reload_dbdef($dbdef_file);
foreach my $table ( dbdef_dist->tables ) {
if ( dbdef->table($table) ) {
warn "$table exists\n" if $DEBUG > 1;
foreach my $column ( dbdef_dist->table($table)->columns ) {
if ( dbdef->table($table)->column($column) ) {
warn " $table.$column exists\n" if $DEBUG > 2;
} else {
if ( $DEBUG ) {
print STDERR "column $table.$column does not exist. create?";
next unless yesno();
}
foreach my $statement (
dbdef_dist->table($table)->column($column)->sql_add_column( $dbh )
) {
warn "$statement\n" if $DEBUG || $DRY_RUN;
unless ( $DRY_RUN ) {
$dbh->do( $statement)
or die "CREATE error: ". $dbh->errstr. "\nexecuting: $statement";
}
}
}
}
#should eventually check & create missing indices
#should eventually drop columns not in dbdef_dist...
} else {
if ( $DEBUG ) {
print STDERR "table $table does not exist. create?";
next unless yesno();
}
foreach my $statement (
dbdef_dist->table($table)->sql_create_table( $dbh )
) {
warn "$statement\n" if $DEBUG || $DRY_RUN;
unless ( $DRY_RUN ) {
$dbh->do( $statement)
or die "CREATE error: ". $dbh->errstr. "\nexecuting: $statement";
}
}
}
}
# should eventually drop tables not in dbdef_dist too i guess...
$dbh->commit or die $dbh->errstr;
dbdef_create($dbh, $dbdef_file);
$dbh->disconnect or die $dbh->errstr;
###
my $all = 0;
sub yesno {
print STDERR ' [yes/no/all] ';
if ( $all ) {
warn "yes\n";
return 1;
} else {
while ( 1 ) {
ReadMode 4;
my $x = lc(ReadKey);
ReadMode 0;
if ( $x eq 'n' ) {
warn "no\n";
return 0;
} elsif ( $x eq 'y' ) {
warn "yes\n";
return 1;
} elsif ( $x eq 'a' ) {
warn "yes\n";
$all = 1;
return 1;
}
}
}
}
sub dbdef_create { # reverse engineer the schema from the DB and save to file
my( $dbh, $file ) = @_;
my $dbdef = new_native DBIx::DBSchema $dbh;
$dbdef->save($file);
}
sub usage {
die "Usage:\n freeside-upgrade user\n";
}
1;
More information about the freeside-commits
mailing list