[Cpan-forum-commit] rev 166 - in trunk: . bin

svn at pti.co.il svn at pti.co.il
Fri Aug 25 18:15:10 IDT 2006


Author: gabor
Date: 2006-08-25 18:15:09 +0300 (Fri, 25 Aug 2006)
New Revision: 166

Added:
   trunk/bin/upgrade_to_0_12.pl
Modified:
   trunk/
Log:
add script to do the upgrade



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   - 8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:10993
   + 8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:10994

Added: trunk/bin/upgrade_to_0_12.pl
===================================================================
--- trunk/bin/upgrade_to_0_12.pl	2006-08-25 15:15:06 UTC (rev 165)
+++ trunk/bin/upgrade_to_0_12.pl	2006-08-25 15:15:09 UTC (rev 166)
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use lib "lib";
+
+use File::Copy qw(move copy);
+use DBI;
+use Cwd qw(cwd);
+
+# tell application db is closed...
+
+my $time   = time;
+my $failed;
+my $db_file = 'db/forum.db';
+my $backup = $db_file . "_$time";
+print "Backup: $backup\n";
+copy $db_file, $backup;
+my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file") 
+    or die "Could not connect to database";
+my $source = do {
+    local $/ = undef;
+    <DATA>;
+};
+
+foreach my $sql (split /;/, $source) {
+    next if $sql !~ /\S/;
+    $dbh->do($sql);
+}
+#$failed = 1;
+
+if ($failed) {
+	print "Upgraded failed.\n";
+    unlink $db_file;
+	move $backup, $db_file;
+	print "Database restored\n";
+} else {
+	print "The datbase was upgraded successfully.\n";
+	
+}
+# set the application to "open" again
+
+__END__
+ALTER TABLE groups ADD version VARCHAR(100);
+ALTER TABLE groups ADD pauseid INTEGER;
+ALTER TABLE groups ADD rating VARCHAR(10);
+ALTER TABLE groups ADD review_count INTEGER;
+
+



More information about the Cpan-forum-commit mailing list