4 use vars qw($opt_d $opt_q $opt_v);
5 use vars qw($DEBUG $DRY_RUN);
7 use DBIx::DBSchema 0.31;
8 use FS::UID qw(adminsuidsetup checkeuid datasrc ); #getsecrets);
10 use FS::Schema qw( dbdef dbdef_dist reload_dbdef );
11 use FS::Misc qw(prune_applications);
13 die "Not running uid freeside!" unless checkeuid();
22 my $user = shift or die &usage;
23 $FS::CurrentUser::upgrade_hack = 1;
24 my $dbh = adminsuidsetup($user);
26 #needs to match FS::Schema...
27 my $dbdef_file = "%%%FREESIDE_CONF%%%/dbdef.". datasrc;
29 dbdef_create($dbh, $dbdef_file);
31 delete $FS::Schema::dbdef_cache{$dbdef_file}; #force an actual reload
32 reload_dbdef($dbdef_file);
34 $DBIx::DBSchema::DEBUG = $DEBUG;
35 $DBIx::DBSchema::Table::DEBUG = $DEBUG;
38 print join(";\n", dbdef->sql_update_schema( dbdef_dist, $dbh ) ). ";\n";
41 dbdef->update_schema( dbdef_dist, $dbh );
45 $hashref->{dry_run} = 1 if $DRY_RUN;
46 $hashref->{debug} = 1 if $DEBUG;
47 print join "\n", prune_applications($hashref);
48 print "\n" if $DRY_RUN;
51 $dbh->commit or die $dbh->errstr;
53 dbdef_create($dbh, $dbdef_file);
55 $dbh->disconnect or die $dbh->errstr;
58 my $init_config = "freeside-init-config -u $user ";
59 $init_config .= "%%%FREESIDE_CONF%%%/conf.". datasrc;
60 system "$init_config" ;
65 sub dbdef_create { # reverse engineer the schema from the DB and save to file
66 my( $dbh, $file ) = @_;
67 my $dbdef = new_native DBIx::DBSchema $dbh;
72 die "Usage:\n freeside-upgrade [ -d ] [ -q | -v ] user\n";
77 freeside-upgrade - Upgrades database schema for new freeside verisons.
81 freeside-upgrade [ -d ] [ -q | -v ]
85 Reads your existing database schema and updates it to match the current schema,
86 adding any columns or tables necessary.
88 [ -d ]: Dry run; output SQL statements (to STDOUT) only, but do not execute
91 [ -q ]: Run quietly. This may become the default at some point.
93 [ -v ]: Run verbosely, sending debugging information to STDERR. This is the