+Or on Pg versions that don't support DROP CONSTRAINT and ADD PRIMARY KEY (tested on 7.1 and 7.2 so far):
+DROP INDEX h_part_pkg_temp_pkey;
+CREATE UNIQUE INDEX h_part_pkg_pkey ON h_part_pkg (historynum);
+probably this one?: select setval('h_part_pkg_temp_historynum_seq', ( select max(historynum) from h_part_pkg) );
+probably not this one?: select setval('h_part_pkg_historynum_seq', ( select max(historynum) from h_part_pkg) );
+
+CREATE TABLE cust_pay_refund (
+ payrefundnum serial NOT NULL,
+ paynum int NOT NULL,
+ refundnum int NOT NULL,
+ _date int NOT NULL,
+ amount decimal(10,2) NOT NULL,
+ PRIMARY KEY (payrefundnum)
+);
+CREATE INDEX cust_pay_refund1 ON cust_pay_refund(paynum);
+CREATE INDEX cust_pay_refund2 ON cust_pay_refund(refundnum);
+
+CREATE TABLE cust_pay_void (
+ paynum int NOT NULL,
+ custnum int NOT NULL,
+ paid decimal(10,2) NOT NULL,
+ _date int,
+ payby char(4) NOT NULL,
+ payinfo varchar(80),
+ paybatch varchar(80),
+ closed char(1),
+ void_date int,
+ reason varchar(80),
+ otaker varchar(32) NOT NULL,
+ PRIMARY KEY (paynum)
+);
+CREATE INDEX cust_pay_void1 ON cust_pay_void(custnum);
+
+CREATE TABLE part_pkg_option (
+ optionnum int primary key,
+ pkgpart int not null,
+ optionname varchar(80) not null,
+ optionvalue text NULL
+);
+CREATE INDEX part_pkg_option1 ON part_export_option ( pkgpart );
+CREATE INDEX part_pkg_option2 ON part_export_option ( optionname );
+
+CREATE TABLE rate (
+ ratenum serial NOT NULL,
+ reatename varchar(80) NOT NULL,
+ PRIMARY KEY (ratenum)
+);
+
+CREATE TABLE rate_detail (
+ ratenum int NOT NULL,
+ orig_regionnum int NULL,
+ dest_regionnum int NOT NULL,
+ min_included int NOT NULL,
+ min_charge decimal(10,2) NOT NULL,
+ sec_granularity int NOT NULL
+);
+CREATE UNIQUE INDEX rate_detail1 ON rate_detail ( ratenum, orig_regionnum, dest_regionnum );
+
+CREATE TABLE rate_region (
+ regionnum serial NOT NULL,
+ regionname varchar(80) NOT NULL,
+ PRIMARY KEY (regionnum)
+);
+
+CREATE TABLE rate_prefix (
+ prefixnum serial NOT NULL,
+ regionnum int NOT NULL,
+ countrycode varchar(3) NOT NULL,
+ npa varchar(4) NULL,
+ nxx varchar(3) NULL,
+ PRIMARY KEY (prefixnum)
+);
+CREATE INDEX rate_prefix1 ON rate_prefix ( countrycode );
+CREATE INDEX rate_prefix2 ON rate_prefix ( regionnum );