JBAS-481 update sequences for sample data
authorBill Erickson <berickxx@gmail.com>
Thu, 19 Feb 2015 16:10:27 +0000 (11:10 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
When cherry-picking data to insert for various large tables (bibs,
auths, copies, etc.), update the ID sequence for each table to match the
maximum ID used, so that the correct sequence values may be used on
future inserts.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/sql/dev-data/create-dev-db.sh

index 0e1bcf7..a2f4a5f 100755 (executable)
@@ -23,6 +23,8 @@ echo "Loading org unit settings..."
 echo "
 BEGIN;
 COPY actor.org_unit_setting FROM '$DIR/kcls-dev-aous.sql';
+SELECT SETVAL('actor.org_unit_setting_id_seq', 
+    (SELECT MAX(id) FROM actor.org_unit_setting));
 COMMIT;" | $PSQL
 
 echo "Loading sample records..."
@@ -30,6 +32,8 @@ echo "
 BEGIN; 
 COPY biblio.record_entry FROM '$DIR/kcls-dev-recs.sql'; 
 UPDATE biblio.record_entry SET creator = 1, editor = 1; 
+SELECT SETVAL('biblio.record_entry_id_seq', 
+    (SELECT MAX(id) FROM biblio.record_entry));
 COMMIT;" | $PSQL 
 
 echo "Loading sample call numbers..."
@@ -37,6 +41,8 @@ echo "
 BEGIN; 
 COPY asset.call_number FROM '$DIR/kcls-dev-cns.sql'; 
 UPDATE asset.call_number SET creator = 1, editor = 1; 
+SELECT SETVAL('asset.call_number_id_seq', 
+    (SELECT MAX(id) FROM asset.call_number));
 COMMIT;" | $PSQL 
 
 echo "Loading sample copies..."
@@ -44,6 +50,7 @@ echo "
 BEGIN; 
 COPY asset.copy FROM '$DIR/kcls-dev-copies.sql'; 
 UPDATE asset.copy SET creator = 1, editor = 1; 
+SELECT SETVAL('asset.copy_id_seq', (SELECT MAX(id) FROM asset.copy));
 COMMIT;" | $PSQL 
 
 echo "Loading sample authority records..."
@@ -51,6 +58,8 @@ echo "
 BEGIN; 
 COPY authority.record_entry FROM '$DIR/kcls-dev-auths.sql'; 
 UPDATE authority.record_entry SET creator = 1, editor = 1; 
+SELECT SETVAL('authority.record_entry_id_seq', 
+    (SELECT MAX(id) FROM authority.record_entry));
 COMMIT;" | $PSQL