[Rt-commit] rt branch, 4.4/reset-sequences, repushed

Jim Brandt jbrandt at bestpractical.com
Mon Nov 20 16:18:50 EST 2017


The branch 4.4/reset-sequences was deleted and repushed:
       was 8ce2dd940df762de68bf5b542373708473ce42de
       now 6683b51c1753808a2221c0801b3050fdf2ad9987

1:  8ce2dd9 ! 1:  6683b51 Script to automatically update DB sequences to the next available value
    @@ -130,7 +130,7 @@
     +    OBJECTSCRIPS
     +    ACL
     +    GROUPMEMBERS
    -+    CachedGroupMembers
    ++    CACHEDGROUPMEMBERS
     +    USERS
     +    TICKETS
     +    SCRIPACTIONS
    @@ -140,13 +140,13 @@
     +    CUSTOMFIELDS
     +    CUSTOMFIELDVALUES
     +    ATTRIBUTES
    -+    Classes
    -+    Articles
    -+    Topics
    -+    ObjectTopics
    -+    ObjectClasses
    -+    Assets
    -+    Catalogs
    ++    CLASSES
    ++    ARTICLES
    ++    TOPICS
    ++    OBJECTTOPICS
    ++    OBJECTCLASSES
    ++    ASSETS
    ++    CATALOGS
     +    CUSTOMROLES
     +    OBJECTCUSTOMROLES
     +    );
    @@ -177,24 +177,48 @@
     +sub fix_id_sequence {
     +    my ($table, $sequence_per_db) = @_;
     +    my $sequence = $sequence_per_db->{$db_type} or return;
    -+
    -+    my ($max) = $dbh->selectrow_array("SELECT MAX(id) FROM $table;");
    ++    my ($max, $query);
    ++
    ++    if ($db_type eq 'Oracle') {
    ++        my $user = RT->Config->Get('DatabaseUser');
    ++        $query = "SELECT MAX(ID) FROM $user.$table";
    ++    }
    ++    else {
    ++        $query = "SELECT MAX(ID) FROM $table";
    ++    }
    ++
    ++    my $sth = $dbh->prepare($query) or die $dbh->errstr;
    ++    $sth->execute();
    ++    ($max) = $sth->fetchrow_array();
    ++
     +    my $next_id = ($max || 0) + 1;
    -+    warn "Resetting $sequence to $next_id";
    ++
    ++    # Nothing to do if there are no rows
    ++    return if $next_id == 1;
    ++
    ++    warn "Resetting $sequence to $next_id for $table";
     +
     +    my @sql;
     +    if ($db_type eq 'Pg') {
     +        @sql = "ALTER SEQUENCE $sequence RESTART WITH $next_id;";
     +    }
     +    elsif ($db_type eq 'Oracle') {
    ++        my $user = RT->Config->Get('DatabaseUser');
     +        @sql = (
    -+            "ALTER SEQUENCE $sequence INCREMENT BY " . ($next_id - 1) . ";",
    -+            "SELECT $sequence.nextval FROM dual;",
    -+            "ALTER SEQUENCE $sequence INCREMENT BY 1;",
    ++            "ALTER SEQUENCE $user.$sequence INCREMENT BY " . ($next_id - 1) . "",
    ++            "SELECT $user.$sequence.nextval FROM dual",
    ++            "ALTER SEQUENCE $user.$sequence INCREMENT BY 1",
     +        );
     +    }
     +
    -+    $dbh->do($_) for @sql;
    ++    foreach my $statement ( @sql ) {
    ++        my $rv = $dbh->do($statement);
    ++
    ++        if ( not defined $rv ) {
    ++            warn "Error: " . $dbh->errstr;
    ++        }
    ++    }
    ++    return;
     +}
     +
     +sub get_dba_password {



More information about the rt-commit mailing list