mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	This can happen if `machine.pgroonga` is set during initial installation. We cannot run `CREATE EXTENSION PGROONGA` because the database that we need to run that statement in does not exist yet; make the command a silent no-op that does not create the `pgroonga_setup.sql.applied` flag file, such that a later `zulip-puppet-apply` once the database exists can pick up and install the extension.
		
			
				
	
	
		
			26 lines
		
	
	
		
			805 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			805 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/env bash
 | 
						|
set -eux
 | 
						|
 | 
						|
dbversion=$(crudini --get /etc/zulip/zulip.conf postgresql version)
 | 
						|
dbname=$(crudini --get /etc/zulip/zulip.conf postgresql database_name 2>/dev/null || echo zulip)
 | 
						|
 | 
						|
if ! su postgres -c "psql -At -c 'SELECT datname FROM pg_database WHERE NOT datistemplate'" | grep -Fx "$dbname"; then
 | 
						|
    echo "No database to install into!"
 | 
						|
    exit 0
 | 
						|
fi
 | 
						|
 | 
						|
sharedir="${1:-/usr/share/postgresql/$dbversion}"
 | 
						|
applied_file="$sharedir/pgroonga_setup.sql.applied"
 | 
						|
 | 
						|
installed_version=$(dpkg-query --show --showformat='${Version}' "postgresql-$dbversion-pgdg-pgroonga")
 | 
						|
 | 
						|
if [ ! -f "$applied_file" ]; then
 | 
						|
    sql="CREATE EXTENSION PGROONGA"
 | 
						|
else
 | 
						|
    sql="ALTER EXTENSION pgroonga UPDATE"
 | 
						|
fi
 | 
						|
 | 
						|
echo "$sql" | su postgres -c "psql -v ON_ERROR_STOP=1 $dbname"
 | 
						|
 | 
						|
echo "$installed_version" >"$applied_file"
 |