gforge-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gforge-commits] gforge/deb-specific sqlhelper.pm, NONE, 1.1 update-user


From: lo-lan-do
Subject: [Gforge-commits] gforge/deb-specific sqlhelper.pm, NONE, 1.1 update-user-group-cvs.sh, 1.14, 1.15 sqlparser.pm, 1.2, 1.3 db-upgrade.pl, 1.53, 1.54 tarballs.sh, 1.3, NONE install-cvs.sh, 1.7, NONE
Date: Sun, 16 May 2004 11:55:01 -0500

Update of /cvsroot/gforge/gforge/deb-specific
In directory db.perdue.net:/tmp/cvs-serv19357/deb-specific

Modified Files:
        update-user-group-cvs.sh sqlparser.pm db-upgrade.pl 
Added Files:
        sqlhelper.pm 
Removed Files:
        tarballs.sh install-cvs.sh 
Log Message:
The big SCM pluginification plugin: removed lots of code (moved it
into gforge-plugin-scmcvs), added hooks, added the SCMPlugin class,
various tweaks here and there.


--- NEW FILE: sqlhelper.pm ---
# $Id: sqlhelper.pm,v 1.1 2004/05/16 16:54:58 lo-lan-do Exp $
#
# A few SQL helper functions
#
### AUTHOR/COPYRIGHT
# This file is copyright 2004 Roland Mas <address@hidden>.
#
# This is Free Software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License version 2, as published by the
# Free Software Foundation.
#
### USAGE
# drop_view_if_exists ("view_name") ;
# drop_table_if_exists ("table_name") ;
# drop_index_if_exists ("index_name") ;
# drop_sequence_if_exists ("sequence_name") ;
# remove_plugin_from_groups ("plugin_name") ;
# remove_plugin_from_users ("plugin_name") ;
#
### BUGS
# * No real bugs known -- yet
#
### TODO

use strict ;

use subs qw/ &get_plugin_id &remove_plugin_from_groups
    &remove_plugin_from_users &drop_table_if_exists
    &drop_index_if_exists &drop_sequence_if_exists
    &drop_view_if_exists &bump_sequence_to &update_plugin_db_version
    &get_plugin_db_version &debug &create_plugin_metadata_table
    &is_lesser &is_greater/ ;

sub get_plugin_id ( $$ ) ;
sub remove_plugin_from_groups ( $$ ) ;
sub remove_plugin_from_users ( $$ ) ;
sub drop_table_if_exists ( $$ ) ;
sub drop_index_if_exists ( $$ ) ;
sub drop_sequence_if_exists ( $$ ) ;
sub drop_view_if_exists ( $$ ) ;
sub bump_sequence_to ( $$$ ) ;
sub update_plugin_db_version ( $$$ ) ;
sub get_plugin_db_version ( $$ ) ;
sub create_plugin_metadata_table ( $$$ ) ;
sub is_lesser ( $$ ) ;
sub is_greater ( $$ ) ;
sub debug ( $ ) ;

sub drop_table_if_exists ( $$ ) {
    my $dbh = shift or die "Not enough arguments" ;
    my $tname = shift or die  "Not enough arguments" ;
    my $query = "SELECT count(*) FROM pg_class WHERE relname='$tname' AND 
relkind='r'" ;
    my $sth = $dbh->prepare ($query) ;
    $sth->execute () ;
    my @array = $sth->fetchrow_array () ;
    $sth->finish () ;

    if ($array [0] != 0) {
        # debug "Dropping table $tname" ;
        $query = "DROP TABLE $tname" ;
        # debug $query ;
        $sth = $dbh->prepare ($query) ;
        $sth->execute () ;
        $sth->finish () ;
    }
}

sub drop_sequence_if_exists ( $$ ) {
    my $dbh = shift or die "Not enough arguments" ;
    my $sname = shift or die  "Not enough arguments" ;
    my $query = "SELECT count(*) FROM pg_class WHERE relname='$sname' AND 
relkind='S'" ;
    my $sth = $dbh->prepare ($query) ;
    $sth->execute () ;
    my @array = $sth->fetchrow_array () ;
    $sth->finish () ;

    if ($array [0] != 0) {
        # debug "Dropping sequence $sname" ;
        $query = "DROP SEQUENCE $sname" ;
        # debug $query ;
        $sth = $dbh->prepare ($query) ;
        $sth->execute () ;
        $sth->finish () ;
    }
}

sub drop_index_if_exists ( $$ ) {
    my $dbh = shift or die "Not enough arguments" ;
    my $iname = shift or die  "Not enough arguments" ;
    my $query = "SELECT count(*) FROM pg_class WHERE relname='$iname' AND 
relkind='i'" ;
    my $sth = $dbh->prepare ($query) ;
    $sth->execute () ;
    my @array = $sth->fetchrow_array () ;
    $sth->finish () ;

    if ($array [0] != 0) {
        # debug "Dropping index $iname" ;
        $query = "DROP INDEX $iname" ;
        # debug $query ;
        $sth = $dbh->prepare ($query) ;
        $sth->execute () ;
        $sth->finish () ;
    }
}

sub drop_view_if_exists ( $$ ) {
    my $dbh = shift or die "Not enough arguments" ;
    my $vname = shift or die  "Not enough arguments" ;

    my $query = "SELECT count(*) FROM pg_class WHERE relname='$vname' AND 
relkind='v'" ;
    my $sth = $dbh->prepare ($query) ;
    $sth->execute () ;
    my @array = $sth->fetchrow_array () ;
    $sth->finish () ;

    if ($array [0] != 0) {
        # debug "Dropping view $vname" ;
        $query = "DROP VIEW $vname" ;
        # debug $query ;
        $sth = $dbh->prepare ($query) ;
        $sth->execute () ;
        $sth->finish () ;
    }
}

sub bump_sequence_to ( $$$ ) {
    my $dbh = shift or die "Not enough arguments" ;
    my $seqname = shift or die "Not enough arguments" ;
    my $targetvalue = shift or die "Not enough arguments" ;

    my ($sth, @array) ;

    do {
        my $query = "select nextval ('$seqname')" ;
        $sth = $dbh->prepare ($query) ;
        $sth->execute () ;
        @array = $sth->fetchrow_array () ;
        $sth->finish () ;
    } until $array[0] >= $targetvalue ;
}

sub get_plugin_id ( $$ ) {
    my $dbh = shift or die "Not enough arguments" ;
    my $pluginname = shift or die "Not enough arguments" ;
    
    my $pluginid = -1 ;
    
    my $query = "SELECT plugin_id FROM plugins WHERE plugin_name = 
'$pluginname'" ;
    my $sth = $dbh->prepare ($query) ;
    $sth->execute () ;
    if (my @array = $sth->fetchrow_array ()) {
        $pluginid = $array [0] ;
    }
    $sth->finish () ;
    
    return $pluginid ;
}

sub remove_plugin_from_groups ( $$ ) {
    my $dbh = shift or die "Not enough arguments" ;
    my $pluginid = shift or die "Not enough arguments" ;
    
    my $query = "DELETE FROM group_plugin WHERE plugin_id = $pluginid" ;
    my $sth = $dbh->prepare ($query) ;
    $sth->execute () ;
    $sth->finish () ;
}

sub remove_plugin_from_users ( $$ ) {
    my $dbh = shift or die "Not enough arguments" ;
    my $pluginid = shift or die "Not enough arguments" ;
    
    my $query = "DELETE FROM user_plugin WHERE plugin_id = $pluginid" ;
    my $sth = $dbh->prepare ($query) ;
    $sth->execute () ;
    $sth->finish () ;
}

sub update_plugin_db_version ( $$$ ) {
    my $dbh = shift or die "Not enough arguments" ;
    my $pluginname = shift or die "Not enough arguments" ;
    my $v = shift or die "Not enough arguments" ;

    my $tablename = "plugin_" .$pluginname . "_meta_data" ;

    debug "Updating $tablename table." ;
    my $query = "UPDATE $tablename SET value = '$v' WHERE key = 'db-version'" ;
    # debug $query ;
    my $sth = $dbh->prepare ($query) ;
    $sth->execute () ;
    $sth->finish () ;
}

sub get_plugin_db_version ( $$ ) {
    my $dbh = shift or die "Not enough arguments" ;
    my $pluginname = shift or die "Not enough arguments" ;

    my $tablename = "plugin_" .$pluginname . "_meta_data" ;

    my $query = "SELECT value FROM $tablename WHERE key = 'db-version'" ;
    # debug $query ;
    my $sth = $dbh->prepare ($query) ;
    $sth->execute () ;
    my @array = $sth->fetchrow_array () ;
    $sth->finish () ;

    my $version = $array [0] ;

    return $version ;
}

sub debug ( $ ) {
    my $v = shift ;
    chomp $v ;
    print STDERR "$v\n" ;
}

sub create_plugin_metadata_table ( $$$ ) {
    my $dbh = shift or die "Not enough arguments" ;
    my $pluginname = shift or die "Not enough arguments" ;
    my $v = shift || "0" ;

    my $tablename = "plugin_" .$pluginname . "_meta_data" ;
    # Do we have the metadata table?

    my $query = "SELECT count(*) FROM pg_class WHERE relname = '$tablename' and 
relkind = 'r'";
    # debug $query ;
    my $sth = $dbh->prepare ($query) ;
    $sth->execute () ;
    my @array = $sth->fetchrow_array () ;
    $sth->finish () ;

    # Let's create this table if we have it not

    if ($array [0] == 0) {
        debug "Creating $tablename table." ;
        $query = "CREATE TABLE $tablename (key varchar primary key, value text 
not null)" ;
        # debug $query ;
        $sth = $dbh->prepare ($query) ;
        $sth->execute () ;
        $sth->finish () ;
    }

    $query = "SELECT count(*) FROM $tablename WHERE key = 'db-version'";
    # debug $query ;
    $sth = $dbh->prepare ($query) ;
    $sth->execute () ;
    @array = $sth->fetchrow_array () ;
    $sth->finish () ;

    # Empty table?  We'll have to fill it up a bit

    if ($array [0] == 0) {
        debug "Inserting first data into $tablename table." ;
        $query = "INSERT INTO $tablename (key, value) VALUES ('db-version', 
'$v')" ;
        # debug $query ;
        $sth = $dbh->prepare ($query) ;
        $sth->execute () ;
        $sth->finish () ;
    }
}

sub is_lesser ( $$ ) {
    my $v1 = shift || 0 ;
    my $v2 = shift || 0 ;

    my $rc = system "dpkg --compare-versions $v1 lt $v2" ;

    return (! $rc) ;
}

sub is_greater ( $$ ) {
    my $v1 = shift || 0 ;
    my $v2 = shift || 0 ;

    my $rc = system "dpkg --compare-versions $v1 gt $v2" ;

    return (! $rc) ;
}

1 ;

Index: update-user-group-cvs.sh
===================================================================
RCS file: /cvsroot/gforge/gforge/deb-specific/update-user-group-cvs.sh,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- update-user-group-cvs.sh    1 Apr 2004 17:32:42 -0000       1.14
+++ update-user-group-cvs.sh    16 May 2004 16:54:58 -0000      1.15
@@ -24,8 +24,8 @@
        /usr/lib/gforge/bin/user_dump_update.pl
        /usr/lib/gforge/bin/group_dump_update.pl
        /usr/lib/gforge/bin/ssh_dump_update.pl
-       [ -f /usr/lib/gforge/bin/cvs_dump.pl ] && su -s /bin/sh gforge -c 
/usr/lib/gforge/bin/cvs_dump.pl
-       [ -f /usr/lib/gforge/bin/cvs_update.pl ] && 
/usr/lib/gforge/bin/cvs_update.pl
+       [ -f /usr/lib/gforge/bin/cvs_dump.pl ] && su -s /bin/sh gforge -c 
/usr/lib/gforge/bin/cvs_dump.pl || true
+       [ -f /usr/lib/gforge/bin/cvs_update.pl ] && 
/usr/lib/gforge/bin/cvs_update.pl || true
 
        #CB#su gforge -c /usr/lib/gforge/bin/dump_database.pl -s /bin/sh
        #CB#su gforge -c /usr/lib/gforge/bin/ssh_dump.pl -s /bin/sh

Index: sqlparser.pm
===================================================================
RCS file: /cvsroot/gforge/gforge/deb-specific/sqlparser.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- sqlparser.pm        5 Aug 2002 17:00:54 -0000       1.2
+++ sqlparser.pm        16 May 2004 16:54:58 -0000      1.3
@@ -38,7 +38,7 @@
 
 sub parse_sql_file ( $ ) {
     my $f = shift ;
-    open F, $f || die "Could not open file $f: $!\n" ;
+    open F, $f or die "Could not open file $f: $!\n" ;
 
     # This is a state machine to parse potentially complex SQL files
     # into individual SQL requests/statements

Index: db-upgrade.pl
===================================================================
RCS file: /cvsroot/gforge/gforge/deb-specific/db-upgrade.pl,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- db-upgrade.pl       9 May 2004 18:15:37 -0000       1.53
+++ db-upgrade.pl       16 May 2004 16:54:58 -0000      1.54
@@ -22,16 +22,12 @@
     $server_admin $domain_name $newsadmin_groupid $statsadmin_groupid
     $skill_list/ ;
 
-sub is_lesser ( $$ ) ;
-sub is_greater ( $$ ) ;
-sub debug ( $ ) ;
-sub parse_sql_file ( $ ) ;
-
 require ("/etc/gforge/local.pl") ; 
 require ("/usr/lib/gforge/lib/sqlparser.pm") ; # Our magic SQL parser
+require ("/usr/lib/gforge/lib/sqlhelper.pm") ; # Our SQL functions
[...1332 lines suppressed...]
-       $sth = $dbh->prepare ($query) ;
-       $sth->execute () ;
-       $sth->finish () ;
-    }
-}
-
-sub bump_sequence_to ( $$ ) {
-    my ($sth, @array, $seqname, $targetvalue) ;
-
-    $seqname = shift ;
-    $targetvalue = shift ;
-
-    do {
-       $query = "select nextval ('$seqname')" ;
-       $sth = $dbh->prepare ($query) ;
-       $sth->execute () ;
-       @array = $sth->fetchrow_array () ;
-       $sth->finish () ;
-    } until $array[0] >= $targetvalue ;
-}

--- tarballs.sh DELETED ---

--- install-cvs.sh DELETED ---





reply via email to

[Prev in Thread] Current Thread [Next in Thread]