#! /bin/csh

setenv db_name ihe-europe-2010
setenv db_user gazelle


setenv id_seq _id_seq
# O FK
foreach table ( tm_object_file_type tm_object_instance_validation tm_object_parameter_validator tm_object_type_status ) 
       # For Linux: pg_dump -U $db_user  $db_name -t $table -D -a > 01_${table}_data.sql
       pg_dump -U$db_user  $db_name -t $table -a --column-inserts > 01_${table}_data.sql
	echo "" >> 01_${table}_data.sql
	echo "SELECT setval(' $table$id_seq', max(id) ) from $table ; " >> 01_${table}_data.sql
end

# 1 FK
foreach table ( tm_object_class_validator tm_object_type ) 
       # For Linux: pg_dump -U $db_user  $db_name -t $table -D -a > 10_${table}_data.sql
       pg_dump -U $db_user  $db_name -t $table -a --column-inserts > 10_${table}_data.sql
	echo "" >> 10_${table}_data.sql
	echo "SELECT setval(' $table$id_seq', max(id) ) from $table ; " >> 10_${table}_data.sql
end

# 2 FK
foreach table ( tm_object_attribute tm_object_file tm_object_method_validator )
       # For Linux: pg_dump -U $db_user  $db_name -t $table -D -a > 20_${table}_data.sql
       pg_dump -U $db_user  $db_name -t $table -a --column-inserts > 20_${table}_data.sql
	echo "" >> 20_${table}_data.sql
	echo "SELECT setval(' $table$id_seq', max(id) ) from $table ; " >> 20_${table}_data.sql
end

# 3 FK
foreach table ( tm_object_file_method tm_object_attribute_option tm_object_method_parameter )
       # For Linux: pg_dump -U $db_user  $db_name -t $table -D -a > 30_${table}_data.sql
       pg_dump -U $db_user  $db_name -t $table -a --column-inserts > 30_${table}_data.sql
	echo "" >> 30_${table}_data.sql
	echo "SELECT setval(' $table$id_seq', max(id) ) from $table ; " >> 30_${table}_data.sql
end

# 4 FK
foreach table ( tm_object_creator tm_object_reader  )
       # For Linux: pg_dump -U $db_user  $db_name -t $table -D -a > 40_${table}_data.sql
       pg_dump -U $db_user  $db_name -t $table -a --column-inserts > 40_${table}_data.sql
	echo "" >> 40_${table}_data.sql
	echo "SELECT setval(' $table$id_seq', max(id) ) from $table ; " >> 40_${table}_data.sql
end



