swap hardcoded public values for DB_SCHEMA constant

This commit is contained in:
Matthew Bucci
2024-10-18 23:07:05 -07:00
parent 129aa7f171
commit 36726124a4
7 changed files with 33 additions and 9 deletions

View File

@ -49,6 +49,11 @@ if(!defined('PG4WP_ROOT')) {
mkdir(PG4WP_LOG);
}
// Default to public schema
if (!defined('DB_SCHEMA')) {
define('DB_SCHEMA', 'public');
}
// Here happens all the magic
require_once(PG4WP_ROOT . '/core.php');
} // Protection against multiple loading

View File

@ -6,7 +6,7 @@ class DescribeSQLRewriter extends AbstractSQLRewriter
{
$sql = $this->original();
$table = $this->extractTableName($sql);
return $this->generatePostgresDescribeTable($table);
return $this->generatePostgresDescribeTable($table, DB_SCHEMA);
}
/**
@ -31,7 +31,7 @@ class DescribeSQLRewriter extends AbstractSQLRewriter
* @param string $schema The schema name
* @return string The generated SQL query
*/
public function generatePostgresDescribeTable($tableName, $schema = "public")
public function generatePostgresDescribeTable($tableName, $schema)
{
$sql = <<<SQL
SELECT

View File

@ -37,7 +37,7 @@ class SelectSQLRewriter extends AbstractSQLRewriter
if(false !== strpos($sql, 'information_schema')) {
// WP Site Health rewrites
if (false !== strpos($sql, "SELECT TABLE_NAME AS 'table', TABLE_ROWS AS 'rows', SUM(data_length + index_length)")) {
$sql = $this->postgresTableSizeRewrite();
$sql = $this->postgresTableSizeRewrite(DB_SCHEMA);
return $sql;
}
@ -373,7 +373,7 @@ class SelectSQLRewriter extends AbstractSQLRewriter
}
// This method is specifically to handle should_suggest_persistent_object_cache in wp site health
protected function postgresTableSizeRewrite($schema = 'public')
protected function postgresTableSizeRewrite($schema)
{
$sql = <<<SQL

View File

@ -6,7 +6,7 @@ class ShowFullColumnsSQLRewriter extends AbstractSQLRewriter
{
$sql = $this->original();
$table = $this->extractTableNameFromShowColumns($sql);
return $this->generatePostgresShowColumns($table);
return $this->generatePostgresShowColumns($table, DB_SCHEMA);
}
/**
@ -31,7 +31,7 @@ class ShowFullColumnsSQLRewriter extends AbstractSQLRewriter
* @param string $schema The schema name
* @return string The generated SQL query
*/
public function generatePostgresShowColumns($tableName, $schema = "public")
public function generatePostgresShowColumns($tableName, $schema)
{
$sql = <<<SQL
SELECT

View File

@ -5,7 +5,7 @@ class ShowTableStatusSQLRewriter extends AbstractSQLRewriter
public function rewrite(): string
{
$sql = $this->original();
return $this->generatePostgresShowTableStatus();
return $this->generatePostgresShowTableStatus(DB_SCHEMA);
}
@ -14,7 +14,7 @@ class ShowTableStatusSQLRewriter extends AbstractSQLRewriter
*
* @return string The generated SQL query
*/
public function generatePostgresShowTableStatus($schema = "public")
public function generatePostgresShowTableStatus($schema)
{
$sql = <<<SQL
SELECT

View File

@ -4,7 +4,7 @@ class ShowTablesSQLRewriter extends AbstractSQLRewriter
{
public function rewrite(): string
{
$schema = "public";
$schema = DB_SCHEMA;
return 'SELECT tablename FROM pg_tables WHERE schemaname = \'$schema\';';
}
}

View File

@ -68,6 +68,25 @@ This is because the database needs to be up and running before any plugin can be
1. Point your Web Browser to your WordPress installation and go through the traditional WordPress installation routine.
wp-config constants you can set
```
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** Database username */
define( 'DB_USER', 'username_here' );
/** Database password */
define( 'DB_PASSWORD', 'password_here' );
/** Database hostname */
define( 'DB_HOST', 'localhost' );
/** PG4WP specific Database schema / search path */
define( 'DB_SCHEMA', 'public' );
```
### Contributing