[freeside-commits] branch master updated. 6e33e8af0974d49c1c0cf65b1963846d35f6c156
Ivan
ivan at 420.am
Tue Mar 1 09:08:54 PST 2016
The branch, master has been updated
via 6e33e8af0974d49c1c0cf65b1963846d35f6c156 (commit)
via b946b5a2acce328ac0e163dbf7bf8e83e7eb677a (commit)
from 47f8f6a1868aeb155b985c10f332c5a9d455f032 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 6e33e8af0974d49c1c0cf65b1963846d35f6c156
Merge: b946b5a 47f8f6a
Author: Ivan Kohler <ivan at freeside.biz>
Date: Tue Mar 1 09:08:48 2016 -0800
Merge branch 'master' of git.freeside.biz:/home/git/freeside
commit b946b5a2acce328ac0e163dbf7bf8e83e7eb677a
Author: Ivan Kohler <ivan at freeside.biz>
Date: Tue Mar 1 09:08:43 2016 -0800
making counters for ancient sequence-less installs
diff --git a/bin/makecounters b/bin/makecounters
new file mode 100644
index 0000000..0490ef5
--- /dev/null
+++ b/bin/makecounters
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+
+use strict;
+use FS::UID qw( adminsuidsetup driver_name );
+use FS::Record qw( dbdef );
+
+my $user = shift or die;
+my $dbh = adminsuidsetup $user;
+
+my $schema = dbdef();
+
+my @tables = scalar(@ARGV)
+ ? @ARGV
+ : grep { ! /^h_/ } $schema->tables;
+
+foreach my $table ( @tables ) {
+ my $tableobj = $schema->table($table)
+ or die "unknown table $table (did you run dbdef-create?)\n";
+
+ my $primary_key = $tableobj->primary_key;
+ next unless $primary_key;
+
+ my $col = $tableobj->column($primary_key);
+
+#warn "$table ". $col->type;
+#warn "$table ". $col->default;
+
+ next if uc($col->type) eq 'SERIAL'
+ || ( driver_name eq 'Pg'
+ && defined($col->default)
+ && $col->quoted_default =~ /^nextval\(/i
+ )
+ || ( driver_name eq 'mysql'
+ && defined($col->local)
+ && $col->local =~ /AUTO_INCREMENT/i
+ );
+
+ my $value = FS::Record->scalar_sql("SELECT max($primary_key) FROM $table")
+ or next;
+
+ warn "setting counter for $table to $value\n";
+ open(FILE, ">/usr/local/etc/freeside/counters.DBI:Pg:dbname=freeside/$table.$primary_key")
+ or die $!;
+ print FILE "#COUNTER-1.0\n$value\n";
+ close FILE or die $!;
+
+}
-----------------------------------------------------------------------
Summary of changes:
bin/makecounters | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
create mode 100644 bin/makecounters
More information about the freeside-commits
mailing list