Fork me on GitHub
#sql
<
2019-03-03
>
kenny22:03:50

Hi. I'm investigating Postgres to store time series data and have never worked with Postgres before. Say you have a fresh install of Postgres. How to you typically initialize a database? It seems some people initialize a database by running a script (presumably before starting their app?). With Datomic you can call a create-database function that is idempotent. It'd be nice to have something similar with Postgres, but perhaps that pattern does not fit here. How do you guys do it?

seancorfield22:03:24

With nearly all SQL databases, you start with just some system data and a default account. You need to create new databases/schemas and add new accounts with permissions to access those databases/schemas.

seancorfield22:03:47

A lot of people these days use "migrations" -- SQL scripts to build the database up from the ground, a piece at a time (and reverse migrations to tear it down -- but that's not so important).

seancorfield22:03:54

Does that help at all @kenny?

kenny23:03:08

@seancorfield yes. How come that stuff isn’t done in Clojure? Or are these scripts written in Clojure?

seancorfield23:03:22

One way or another, it has to be SQL. Whether you write that SQL as strings in your Clojure code, or in separate SQL files that you load and run from Clojure.

seancorfield23:03:15

We do the latter, at work. We have now nearly 800 SQL files that represent all the migrations we've applied to go from an empty, freshly created database system, to the full-blown database we use for our systems today.

kenny23:03:27

Oh gotcha. Do you run those scripts each time at app startup?