forked from gratipay/gratipay.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enforce-utc.sql
35 lines (33 loc) · 1.38 KB
/
enforce-utc.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
-- Enforce UTC
-- ===========
-- The production db is already in UTC (presumably per postgresql.conf). We
-- need local dev dbs to also use UTC, but we don't want to make users edit
-- postgresql.conf themselves, nor do we want to clutter schema.sql with this,
-- nor do we want to do it in the application layer per-session. So it's here
-- instead, and is applied in recreate-schema.sh. From the docs on ALTER
-- DATABASE:
--
-- The remaining forms change the session default for a run-time
-- configuration variable for a PostgreSQL database. Whenever a new
-- session is subsequently started in that database, the specified value
-- becomes the session default value. The database-specific default
-- overrides whatever setting is present in postgresql.conf or has been
-- received from the postgres command line."
--
-- http://www.postgresql.org/docs/current/static/sql-alterdatabase.html
--
-- See also:
--
-- "Time Zones"
-- http://www.postgresql.org/docs/current/interactive/datatype-datetime.html#DATATYPE-TIMEZONES
--
-- "Setting Parameters"
-- http://www.postgresql.org/docs/current/static/config-setting.html
--
-- "How can I execute ALTER DATABASE $current_database in PostgreSQL"
-- http://stackoverflow.com/q/10212707/253309
DO $$
BEGIN
EXECUTE '
ALTER DATABASE "' || current_database() || '" SET timezone TO ''UTC'' ';
END; $$;