Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pg4wp/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
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
3 changes: 3 additions & 0 deletions pg4wp/driver_pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ function wpsqli_real_connect(&$connection, $hostname = null, $username = null, $
$pg_connstr = $GLOBALS['pg4wp_connstr'] . ' dbname=' . $dbname;
$GLOBALS['pg4wp_conn'] = $connection = pg_connect($pg_connstr);

// Set the default schema
pg_query($connection, 'SET search_path TO ' . pg_escape_literal(DB_SCHEMA));

return $connection;
}

Expand Down
4 changes: 2 additions & 2 deletions pg4wp/rewriters/DescribeSQLRewriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public function rewrite(): string
{
$sql = $this->original();
$table = $this->extractTableName($sql);
return $this->generatePostgresDescribeTable($table);
return $this->generatePostgresDescribeTable($table, DB_SCHEMA);
}

/**
Expand All @@ -31,7 +31,7 @@ protected function extractTableName($sql)
* @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
Expand Down
4 changes: 2 additions & 2 deletions pg4wp/rewriters/SelectSQLRewriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function rewrite(): string
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;
}

Expand Down Expand Up @@ -373,7 +373,7 @@ protected function convertToPostgresLimitSyntax($sql)
}

// 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
Expand Down
4 changes: 2 additions & 2 deletions pg4wp/rewriters/ShowFullColumnsSQLRewriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public function rewrite(): string
{
$sql = $this->original();
$table = $this->extractTableNameFromShowColumns($sql);
return $this->generatePostgresShowColumns($table);
return $this->generatePostgresShowColumns($table, DB_SCHEMA);
}

/**
Expand All @@ -31,7 +31,7 @@ protected function extractTableNameFromShowColumns($sql)
* @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
Expand Down
4 changes: 2 additions & 2 deletions pg4wp/rewriters/ShowTableStatusSQLRewriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ShowTableStatusSQLRewriter extends AbstractSQLRewriter
public function rewrite(): string
{
$sql = $this->original();
return $this->generatePostgresShowTableStatus();
return $this->generatePostgresShowTableStatus(DB_SCHEMA);
}


Expand All @@ -14,7 +14,7 @@ public function rewrite(): string
*
* @return string The generated SQL query
*/
public function generatePostgresShowTableStatus($schema = "public")
public function generatePostgresShowTableStatus($schema)
{
$sql = <<<SQL
SELECT
Expand Down
2 changes: 1 addition & 1 deletion pg4wp/rewriters/ShowTablesSQLRewriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\';';
}
}
19 changes: 19 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down