Alexandros Kosiaris has submitted this change and it was merged. Change subject: Support spatial_ref_sys and comments in postgres ......................................................................
Support spatial_ref_sys and comments in postgres Automate installing spatial_ref_sys and comments in a postgres spatially enabled database. Automate grants handling Enable pgversion handling Add spatialdb tests Change-Id: Ibd781745ca923ea7668de15cdc62bc765eedb41b --- M modules/postgresql/manifests/spatialdb.pp M modules/postgresql/spec/defines/postgresql_spatial_db_spec.rb A modules/postgresql/tests/spatial.pp 3 files changed, 46 insertions(+), 29 deletions(-) Approvals: Alexandros Kosiaris: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/postgresql/manifests/spatialdb.pp b/modules/postgresql/manifests/spatialdb.pp index 265d780..482ba42 100644 --- a/modules/postgresql/manifests/spatialdb.pp +++ b/modules/postgresql/manifests/spatialdb.pp @@ -15,31 +15,58 @@ # postgresql::spatialdb { 'mydb': } # define postgresql::spatialdb( - $ensure = 'present' + $ensure = 'present', + $pg_version = '9.1', ) { # Check if our db exists and store it - $dbexists = "/usr/bin/psql --tuples-only -c \'SELECT datname FROM pg_catalog.pg_database;\' | /bin/grep \'^ ${name}\'" + $db_exists = "/usr/bin/psql --tuples-only -c \'SELECT datname FROM pg_catalog.pg_database;\' | /bin/grep \'^ ${name}\'" # Check if plgsql is installed - $plpgsqlexists = "/usr/bin/psql --tuples-only -c \'SELECT lanname FROM pg_catalog.pg_language;\' | /bin/grep \'^ plpgsql\'" + $plpgsql_exists = "/usr/bin/psql --tuples-only -c \'SELECT lanname FROM pg_catalog.pg_language;\' | /bin/grep \'^ plpgsql\'" # Check if postgis is installed - $postgisexists = "/usr/bin/psql --tuples-only -c \"SELECT table_catalog FROM information_schema.tables where table_name=\'geometry_columns\';\" ${name} | /bin/grep \'^ ${name}\'" + $postgis_exists = "/usr/bin/psql --tuples-only -c \"SELECT table_catalog FROM information_schema.tables where table_name=\'geometry_columns\';\" ${name} | /bin/grep \'^ ${name}\'" if $ensure == 'present' { exec { "create_db-${name}": command => "/usr/bin/createdb ${name}", - user => "postgres", - unless => $dbexists, + user => 'postgres', + unless => $db_exists, } exec { "create_plpgsql_lang-${name}": command => "/usr/bin/createlang plpgsql ${name}", - user => "postgres", - unless => $plpgsqlexists, + user => 'postgres', + unless => $plpgsql_exists, } exec { "create_postgis-${name}": - command => "/usr/bin/psql -d ${name} -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql", - user => "postgres", - unless => $postgisexists, + command => "/usr/bin/psql -d ${name} -f /usr/share/postgresql/${pg_version}/contrib/postgis-1.5/postgis.sql", + user => 'postgres', + unless => $postgis_exists, + } + # Create spatial_ref_sys + exec { "create_spatial_ref_sys-${name}": + command => "/usr/bin/psql -d ${name} -f /usr/share/postgresql/${pg_version}/contrib/postgis-1.5/spatial_ref_sys.sql", + user => 'postgres', + refreshonly => true, + require => Exec["create_postgis-${name}"], + } + exec { "grant_ref_sys_cmd-${name}": + command => "/usr/bin/psql -d ${name} -c \"GRANT SELECT ON spatial_ref_sys TO PUBLIC;\"", + user => 'postgres', + refreshonly => true, + require => Exec["create_spatial_ref_sys-${name}"], + } + # Create comments + exec { "create_comments-${name}": + command => "/usr/bin/psql -d ${name} -f /usr/share/postgresql/${pg_version}/contrib/comments.sql", + user => 'postgres', + refreshonly => true, + require => Exec["create_spatial_ref_sys-${name}"], + } + exec { "grant_comments_cmd-${name}": + command => "/usr/bin/psql -d ${name} -c \"GRANT ALL ON geometry_columns TO PUBLIC;\"", + user => 'postgres', + refreshonly => true, + require => Exec["create_comments-${name}"], } Exec["create_db-${name}"] -> Exec["create_plpgsql_lang-${name}"] @@ -48,12 +75,12 @@ exec { "drop_db-${name}": command => "/usr/bin/dropdb ${name}", user => "postgres", - onlyif => $dbexists, + onlyif => $db_exists, } exec { "drop_plpgsql_lang-${name}": command => "/usr/bin/droplang plpgsql ${name}", user => "postgres", - onlyif => $plpgsqlexists, + onlyif => $plpgsql_exists, } Exec["drop_plpgsql_lang-${name}"] -> Exec["drop_db-${name}"] } diff --git a/modules/postgresql/spec/defines/postgresql_spatial_db_spec.rb b/modules/postgresql/spec/defines/postgresql_spatial_db_spec.rb index a8b9996..fa25d46 100644 --- a/modules/postgresql/spec/defines/postgresql_spatial_db_spec.rb +++ b/modules/postgresql/spec/defines/postgresql_spatial_db_spec.rb @@ -10,14 +10,8 @@ it { should contain_exec('create_db-somedb') } it { should contain_exec('create_plpgsql_lang-somedb') } it { should contain_exec('create_postgis-somedb') } - it do - pending 'not really needed yet' - should contain_exec('create_spatial_ref_sys-somedb') - end - it do - pending 'not really needed yet' - should contain_exec('create_postgis_comments-somedb') - end + it { should contain_exec('create_spatial_ref_sys-somedb') } + it { should contain_exec('create_comments-somedb') } end end @@ -30,13 +24,5 @@ context 'with ensure absent' do it { should contain_exec('drop_db-somedb') } it { should contain_exec('drop_plpgsql_lang-somedb') } - it do - pending 'not really needed yet' - should contain_exec('drop_spatial_ref_sys-somedb') - end - it do - pending 'not really needed yet' - should contain_exec('drop_postgis_comments-somedb') - end end end diff --git a/modules/postgresql/tests/spatial.pp b/modules/postgresql/tests/spatial.pp new file mode 100644 index 0000000..1ec3963 --- /dev/null +++ b/modules/postgresql/tests/spatial.pp @@ -0,0 +1,4 @@ +# + +include postgresql::server +postgresql::spatialdb { 'gis': } -- To view, visit https://gerrit.wikimedia.org/r/117920 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ibd781745ca923ea7668de15cdc62bc765eedb41b Gerrit-PatchSet: 2 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Alexandros Kosiaris <akosia...@wikimedia.org> Gerrit-Reviewer: Alexandros Kosiaris <akosia...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits