Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: modules/discourse/manifests/sitesetting.pp

Issue 29347356: Issue 4234 - Migrate Discourse to a Docker-based setup (Closed)
Patch Set: Clone from GitHub, updated to Discourse 1.6.4 Created Oct. 12, 2016, 1:17 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « modules/discourse/manifests/init.pp ('k') | modules/discourse/templates/app.yml.erb » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 define discourse::sitesetting(
2 $setting = $title,
3 $value = undef,
4 $type = 1,
5 $ensure = 'present'
6 ) {
7
8 $escaped_value = postgresql_escape($value)
9 $escaped_setting = postgresql_escape($setting)
10 $escaped_type = postgresql_escape($type)
11
12 case $ensure {
13 default: {
14 err("unknown ensure value ${ensure}")
15 }
16 present: {
17 # This is apparently how you do a conditional INSERT in PostgreSQL - sorry
18 $update_sql = "UPDATE site_settings SET value = $escaped_value, data_type = $escaped_type WHERE name = $escaped_setting RETURNING 1"
19 $columns = "name, data_type, value, created_at, updated_at"
20 $values = "SELECT $escaped_setting, $escaped_type, $escaped_value, CURRENT _TIMESTAMP, CURRENT_TIMESTAMP"
21
22 postgresql_psql {"WITH upd AS ($update_sql) INSERT INTO site_settings ($co lumns) $values WHERE NOT EXISTS (SELECT * FROM upd)":
23 db => 'discourse',
24 psql_user => 'discourse',
25 notify => Service['discourse'],
26 unless => "SELECT 1 FROM site_settings WHERE name = $escaped_setting AND value = $escaped_value AND data_type = $escaped_type",
27 }
28 }
29 absent: {
30 postgresql_psql {"DELETE FROM site_settings WHERE name = $escaped_setting" :
31 db => 'discourse',
32 psql_user => 'discourse',
33 notify => Service['discourse'],
34 unless => "SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM site_settings WHERE name = $escaped_setting)",
35 }
36 }
37 }
38 }
OLDNEW
« no previous file with comments | « modules/discourse/manifests/init.pp ('k') | modules/discourse/templates/app.yml.erb » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld