Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, your question is actually quite relevant to any database developer, and, if I understand it correctly, there is another way to get to your desired results.</p> <p>One interesting thing to mention is that your idea of separating different changes into different files is the concept of migrations of Ruby On Rails. You might even be able to use the rake utility to keep track of a workflow like yours.</p> <p>But now to what I think migh be your solution. PostgreSQL, and others to be sincere, have specific utilities to handle data and schemas like what you probably need.</p> <p>The <a href="http://www.postgresql.org/docs/9.2/static/app-pg-dumpall.html" rel="nofollow">pg_dumpall</a> command-line executable will dump the whole database into a file or the console, in a way that the <a href="http://www.postgresql.org/docs/9.2/static/app-psql.html" rel="nofollow">psql</a> utility can simply "reload" into the same, or into another (virgin) database.</p> <p>So, if you want to keep only the current schema (no data!) of a running database cluster, you can, as the postgres-process owner user:</p> <pre><code>$ pg_dumpall --schema-only &gt; schema.sql </code></pre> <p>Now the <em>schema.sql</em> will hold exactly the same users/databases/tables/triggers/etc, but not data. If you want to have a "full-backup" style dump (and that's one way to take a full backup of a database), just remove the "--schema-only" option from the command line.</p> <p>You can reload the file into another (should be virgin, you might mess up a database with other data doing this):</p> <pre><code>$ psql -f schema.sql postgres </code></pre> <p>Now if you only want to dump one database, one table, etc. you should use the pg_dump utility.</p> <pre><code>$ pg_dump --schema-only &lt;database&gt; &gt; database-schema.sql </code></pre> <p>And then, to reload the database into a running postgresql server:</p> <pre><code>$ psql &lt;database&gt; &lt; database-schema.sql </code></pre> <p>As for version control, you can just keep the schema.sql file under it, and just dump the database again into the file before every vc commit. So at some particular version control state will you have the code and the working database schema that goes with it.</p> <p>Oh, and all the tools I mentioned are free, and pg_dump and pg_dumpall come with the standard PostgreSQL installation.</p> <p>Hope that helps,</p> <p>Marco</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload