Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're not far off. I'm a Java developer, not a DBA, but building out the database as a project grows is an important task for the teams I've been on, and here's how I've seen it done best:</p> <ol> <li>All DB changes are driven by DDL (SQL create, alter, or delete statements) plain text scripts. No changes through the DB client. Use a text editor that supports syntax highlighting like vim or notepad++, as the highlighting can help you find errors before you run the script.</li> <li>Use a number at the beginning of each DDL script to define the order that scripts are run in. Base scripts have lower numbers. As the project grows, use alter new alter scripts to change the table, don't redefine the table in the initial script.</li> <li>Use a script and the psql client to load the DDL scripts from lowest to highest. Here's the bash script we use. You can use it as a base for a .bat script on windows.</li> </ol> <blockquote> <p>#!/bin/bash</p> <p>export PGDATABASE=your_db export</p> <p>export PGUSER=your_user export</p> <p>export PGPASSWORD=your_password</p> <p>for SQL_SCRIPT in $( find ./ -name "*.sql" -print | sort);<br> do</p> <pre><code>echo "**** $SQL_SCRIPT ****" psql -q &lt; $SQL_SCRIPT </code></pre> <p>done</p> </blockquote> <ol> <li><p>As the project grows, use new alter scripts to change the table, don't redefine the table in the initial script.</p></li> <li><p>All scripts are checked into source control. Each release is tagged so you can regenerate that version of the database in the future.</p></li> <li><p>For unit testing and CI, most CI servers can run a script to drop and recreate a schema. One oft-cited framework for PostGresql unit testing is <a href="http://pgtap.org/" rel="nofollow">pgTAP</a></p></li> </ol>
    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