5 # Copyright:: 2011, OpenStreetMap Foundation
 
   7 # Licensed under the Apache License, Version 2.0 (the "License");
 
   8 # you may not use this file except in compliance with the License.
 
   9 # You may obtain a copy of the License at
 
  11 #     https://www.apache.org/licenses/LICENSE-2.0
 
  13 # Unless required by applicable law or agreed to in writing, software
 
  14 # distributed under the License is distributed on an "AS IS" BASIS,
 
  15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  16 # See the License for the specific language governing permissions and
 
  17 # limitations under the License.
 
  20 include_recipe "db::base"
 
  22 passwords = data_bag_item("db", "passwords")
 
  24 postgresql_user "tomh" do
 
  25   cluster node[:db][:cluster]
 
  29 postgresql_user "matt" do
 
  30   cluster node[:db][:cluster]
 
  34 postgresql_user "openstreetmap" do
 
  35   cluster node[:db][:cluster]
 
  36   password passwords["openstreetmap"]
 
  39 postgresql_user "rails" do
 
  40   cluster node[:db][:cluster]
 
  41   password passwords["rails"]
 
  44 postgresql_user "cgimap" do
 
  45   cluster node[:db][:cluster]
 
  46   password passwords["cgimap"]
 
  49 postgresql_user "planetdump" do
 
  50   cluster node[:db][:cluster]
 
  51   password passwords["planetdump"]
 
  54 postgresql_user "planetdiff" do
 
  55   cluster node[:db][:cluster]
 
  56   password passwords["planetdiff"]
 
  60 postgresql_user "backup" do
 
  61   cluster node[:db][:cluster]
 
  62   password passwords["backup"]
 
  65 postgresql_user "munin" do
 
  66   cluster node[:db][:cluster]
 
  67   password passwords["munin"]
 
  70 postgresql_user "replication" do
 
  71   cluster node[:db][:cluster]
 
  72   password passwords["replication"]
 
  76 postgresql_database "openstreetmap" do
 
  77   cluster node[:db][:cluster]
 
  81 postgresql_extension "btree_gist" do
 
  82   cluster node[:db][:cluster]
 
  83   database "openstreetmap"
 
  84   only_if { node[:postgresql][:clusters][node[:db][:cluster]] && node[:postgresql][:clusters][node[:db][:cluster]][:version] >= 9.0 }
 
  87 CGIMAP_PERMISSIONS = {
 
  88   "changeset_comments" => [:select],
 
  89   "changeset_tags" => [:select],
 
  90   "changesets" => [:select, :update],
 
  91   "client_applications" => [:select],
 
  92   "current_node_tags" => [:select, :insert, :delete],
 
  93   "current_nodes" => [:select, :insert, :update],
 
  94   "current_nodes_id_seq" => [:update],
 
  95   "current_relation_members" => [:select, :insert, :delete],
 
  96   "current_relation_tags" => [:select, :insert, :delete],
 
  97   "current_relations" => [:select, :insert, :update],
 
  98   "current_relations_id_seq" => [:update],
 
  99   "current_way_nodes" => [:select, :insert, :delete],
 
 100   "current_way_tags" => [:select, :insert, :delete],
 
 101   "current_ways" => [:select, :insert, :update],
 
 102   "current_ways_id_seq" => [:update],
 
 103   "node_tags" => [:select, :insert],
 
 104   "nodes" => [:select, :insert],
 
 105   "oauth_access_grants" => [:select],
 
 106   "oauth_access_tokens" => [:select],
 
 107   "oauth_applications" => [:select],
 
 108   "oauth_nonces" => [:select, :insert],
 
 109   "oauth_nonces_id_seq" => [:update],
 
 110   "oauth_tokens" => [:select],
 
 111   "relation_members" => [:select, :insert],
 
 112   "relation_tags" => [:select, :insert],
 
 113   "relations" => [:select, :insert],
 
 114   "user_blocks" => [:select],
 
 115   "user_roles" => [:select],
 
 116   "users" => [:select],
 
 117   "way_nodes" => [:select, :insert],
 
 118   "way_tags" => [:select, :insert],
 
 119   "ways" => [:select, :insert]
 
 122 PLANETDUMP_PERMISSIONS = {
 
 123   "note_comments" => :select,
 
 128 PLANETDIFF_PERMISSIONS = {
 
 129   "changeset_comments" => :select,
 
 130   "changeset_tags" => :select,
 
 131   "changesets" => :select,
 
 132   "node_tags" => :select,
 
 134   "relation_members" => :select,
 
 135   "relation_tags" => :select,
 
 136   "relations" => :select,
 
 138   "way_nodes" => :select,
 
 139   "way_tags" => :select,
 
 145   active_storage_attachments
 
 147   active_storage_variant_records
 
 152   changesets_subscribers
 
 156   current_relation_members
 
 157   current_relation_tags
 
 165   diary_entry_subscriptions
 
 182   oauth_openid_requests
 
 199   postgresql_table table do
 
 200     cluster node[:db][:cluster]
 
 201     database "openstreetmap"
 
 202     owner "openstreetmap"
 
 203     permissions "openstreetmap" => [:all],
 
 204                 "rails" => [:select, :insert, :update, :delete],
 
 205                 "cgimap" => CGIMAP_PERMISSIONS[table],
 
 206                 "planetdump" => PLANETDUMP_PERMISSIONS[table],
 
 207                 "planetdiff" => PLANETDIFF_PERMISSIONS[table],
 
 208                 "backup" => [:select]
 
 214   active_storage_attachments_id_seq
 
 215   active_storage_blobs_id_seq
 
 216   active_storage_variant_records_id_seq
 
 217   changeset_comments_id_seq
 
 219   client_applications_id_seq
 
 221   current_relations_id_seq
 
 224   diary_comments_id_seq
 
 229   issue_comments_id_seq
 
 234   oauth_access_grants_id_seq
 
 235   oauth_access_tokens_id_seq
 
 236   oauth_applications_id_seq
 
 238   oauth_openid_requests_id_seq
 
 247   postgresql_sequence sequence do
 
 248     cluster node[:db][:cluster]
 
 249     database "openstreetmap"
 
 250     owner "openstreetmap"
 
 251     permissions "openstreetmap" => [:all],
 
 253                 "cgimap" => CGIMAP_PERMISSIONS[sequence],
 
 254                 "backup" => [:select]
 
 258 cookbook_file "/usr/local/share/monthly-reindex.sql" do
 
 264 systemd_service "monthly-reindex" do
 
 265   description "Monthly database reindex"
 
 266   exec_start "/usr/bin/psql -f /usr/local/share/monthly-reindex.sql openstreetmap"
 
 269   restrict_address_families "AF_UNIX"
 
 272 systemd_timer "monthly-reindex" do
 
 273   description "Monthly database reindex"
 
 274   on_calendar "Sun *-*-1..7 02:00"
 
 277 service "monthly-reindex.timer" do
 
 278   action [:enable, :start]
 
 281 cookbook_file "/usr/local/share/yearly-reindex.sql" do
 
 287 systemd_service "yearly-reindex" do
 
 288   description "Yearly database reindex"
 
 289   exec_start "/usr/bin/psql -f /usr/local/share/yearly-reindex.sql openstreetmap"
 
 292   restrict_address_families "AF_UNIX"
 
 295 systemd_timer "yearly-reindex" do
 
 296   description "Yearly database reindex"
 
 297   on_calendar "Fri *-1-8..14 02:00"
 
 300 service "yearly-reindex.timer" do
 
 301   action [:enable, :start]