21 my @opt = <<'=back' =~ /B<--(\S+)>/g;
25 DSN. Defaults to C<dbi:SQLite:dbname=$workdir/quickaccess.db> where
26 $workdir comes from the configuration.
36 Just the quickaccess db and there the table distcontext: migrate from
37 sqlite to sqlite. We did this only to get a bug in the schema fixed.
38 The migration to postgres was not yet on the agenda, on the horizon
39 yes, but not on agenda.
41 The original table had greenish as a text field, we now make it an
42 integer field. This cannot be achieved with their "alter table"
43 support, so we must do it in a script.
45 Before we started the scrpt, we had this histogram:
47 sqlite> SELECT greenish, count(*) FROM distcontext group by greenish ;
55 We would expect that we have 7049 records with 0 afterwards and all
58 On the first run on Nov 20th I was interrupting and delaying this to a
59 later time because it was too slow for the middle of the night. Today
60 I added a remaining seconds indicator and after a few minutes it
61 reaches a stable 10800 seconds, so I'll do the finishing at about
62 11:00 which looks good.
68 use lib
"$FindBin::Bin/../lib";
74 use File
::Basename
qw(dirname);
75 use File
::Path
qw(mkpath);
80 use Hash
::Util
qw(lock_keys);
83 lock_keys
%Opt, map { /([^=|!]+)/ } @opt;
92 $SIG{INT
} = $SIG{TERM
} = sub { my $sig = shift; warn "Caught $sig\n"; $SIGNAL=1 };
95 use Time
::HiRes
qw(sleep time);
97 use lib
"$FindBin::Bin/../CPAN-Blame/lib";
98 use CPAN
::Blame
::Config
::Cnntp
;
99 my($workdir,$cpan_home,$ext_src);
101 $workdir = File
::Spec
->catdir
102 ($CPAN::Blame
::Config
::Cnntp
::Config
->{solver_vardir
},
104 $cpan_home = $CPAN::Blame
::Config
::Cnntp
::Config
->{cpan_home
};
105 $ext_src = $CPAN::Blame
::Config
::Cnntp
::Config
->{ext_src
};
108 $Opt{db
} ||= "dbi:SQLite:dbname=$workdir/quickaccess.db";
111 my($dbi,$sql,@args) = @_;
112 my $success = $dbi->do($sql,undef,@args);
114 my $err = $dbi->errstr;
117 "Warning: error occurred while executing sql[%s]with args[%s]: %s",
119 join(":",map { defined $_ ?
"'$_'" : "<undef>"} @args),
126 my $sldbi = DBI
->connect ($Opt{db
}); # return a dbi handle
127 my $slsth0 = $sldbi->prepare("SELECT count(*) from distcontext");
129 my($slcnt) = $slsth0->fetchrow_array();
131 my $slsth = $sldbi->prepare("SELECT distv,yaml,greenish,dist from distcontext order by distv");
133 my $sql = "CREATE TABLE IF NOT EXISTS ngdistcontext (
134 distv text primary key,
138 my_do_query
($sldbi, $sql);
139 my $slsth2 = $sldbi->prepare("INSERT INTO ngdistcontext
140 (distv,yaml,greenish,dist) values
144 my $lastreport = my $starttime = time;
147 ROW
: while (my(@row) = $slsth->fetchrow_array) {
149 unless ($slsth2->execute(@row)) {
150 warn sprintf "ALERT: error inserting row/id[%s]: %s\n", $row[0], $sldbi->errstr;
154 my $eta = int((time - $^T
)*($slcnt - $i)/$i);
155 printf "\r%d/%d remaining seconds: %d ", $i, $slcnt, $eta;
159 my $tooktime = time - $starttime;
160 warn "records transferred[$i] tooktime[$tooktime]\n";
164 # cperl-indent-level: 4