title: pg_dump and pg_restore (DROP IF EXISTS)
body: <p>I want a completely shell-based solution for testing my database by allowing my to restore it to a consistent state by running a terminal command. </p>
  
  <p>I dump my database like so:</p>
  
  <pre><code>pg_dump -F c -b -f -i -h domain.edu -p 5432 -n myschema -U me mydatabase -W -f mydump.sql
  </code></pre>
  
  <p>Then I want to restore it like so:</p>
  
  <pre><code>pg_restore -h domain.edu -p 5432 -U me -d mydatabase -W mydump.sql
  </code></pre>
  
  <p>but it doesn't work because I get tons of errors like these:</p>
  
  <pre><code>pg_restore: [archiver (db)] could not execute query: ERROR:  constraint "settings_person_id_fkey" for relation "settings" already exists
      Command was: ALTER TABLE ONLY settings
      ADD CONSTRAINT settings_learner_id_fkey FOREIGN KEY (person_id) REFERENCES pe...
  </code></pre>
  
  <p>basically there are just a bunch of things that need to be dropped first before being re-added (<code>DROP TABLE &lt;whatever&gt; IF EXISTS</code>, same with types, etc). </p>
  
  <p>How can I do this with Postgres? I don't want to use the <code>psql</code> console, only the linux terminal. </p>