summaryrefslogtreecommitdiff
path: root/bin/sequences.reset
blob: 2dc1d3bb2a123dee890765558cc29d1d7a2cf407 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/perl

use FS::UID qw(adminsuidsetup);
use FS::Record qw(dbdef dbh);

my $user = shift;
adminsuidsetup $user or die;

foreach my $table ( dbdef->tables ) {
  my $primary_key = dbdef->table($table)->primary_key;
  next unless $primary_key;
  #my $local = dbdef->table($table)->column($primary_key)->local;
  ##next unless $default =~ /nextval/;
  #print "$local\n";

  my $statement = "select setval('${table}_${primary_key}_seq', ( select max($primary_key) from $table ) )";

  print "$statement;\n";
  next;
  
  my $sth = dbh->prepare($statement) or do {
    warn dbh->errstr. " preparing $statement\n";
    next;
  };
  $sth->execute or do {
    warn dbh->errstr. " executing $statement\n";
    dbh->commit;
    next;
  }

}