Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pg schema #24999

Merged
merged 15 commits into from
Jun 5, 2019
Merged

Pg schema #24999

merged 15 commits into from
Jun 5, 2019

Conversation

softarius
Copy link
Contributor

@softarius softarius commented May 24, 2019

Pull Request for Issue #24998 .

Summary of Changes

Method getTableColumns of JDatabaseDriverPostgresql class

Testing Instructions

  • install Joomla with PostgreSQL driver.
  • create a new schema (for example 'test')
  • create a new table in this schema
CREATE TABLE test.customer (
  id SERIAL,
  name VARCHAR(100),
  PRIMARY KEY(id)
) 
WITH (oids = false);
  • in code call getTableColumns for this table
$db = JFactory::getDBO();
$custfields=$db->getTableColumns('test.customer'); 

Expected result

Array with fields of a table

Actual result

Empty array

Documentation Changes Required

Added to param $table
For PostgreSQL may starting with a schema

@richard67
Copy link
Member

@alikon Do you think this is a new feature for 4.0, or is it a bug fix for 3.9?

@alikon
Copy link
Contributor

alikon commented May 24, 2019

quite a greyzone it dependes on how you feel that, so up to the Production Lead

schema.php Outdated
@@ -0,0 +1,23 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file from your PR since it is only for testing this PR, so it should not be checked into the Joomla CMS source code. You have that code already in the testing instructions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to convert it into a real test and integrated it into the test suite.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that would be best. If the author of this PR feels not being able to do that, we can do that later with a new PR or help him here. But anyway this files as it is should be removed from this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now file 'schema.php' simply deleted

@@ -406,6 +406,11 @@ public function getTableColumns($table, $typeOnly = true)
$result = array();

$tableSub = $this->replacePrefix($table);
$fn = explode('.', $tableSub);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style error reported by Drone for lines 409 to 413: Tabs must be used to indent lines; spaces are not allowed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -406,6 +406,11 @@ public function getTableColumns($table, $typeOnly = true)
$result = array();

$tableSub = $this->replacePrefix($table);
$fn = explode('.', $tableSub);
if (count($fn) == 2) {
Copy link
Member

@richard67 richard67 May 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind the Joomla CMS code style rules or check the Drone report.
An "if" with "else" should look as follows, where "..." means some code:

if (...)
{
...
}
else
{
...
}

Please correct that to make Drone happy.

Copy link
Member

@richard67 richard67 May 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P.S. And indent with tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@richard67
Copy link
Member

@HLeithner Do you think this PR is a bug fix for 3.9 or a new feature for 4.0? From my point of view it is a bug fix since it is not good practice to use the public schema for everything in PostgreSQL, as far as I know, like it has to be without this PR. But I might be wrong, so I'd like to know your opinion, and @alikon 's, too, because he is doing much with PostgreSQL.

@@ -427,7 +432,7 @@ public function getTableColumns($table, $typeOnly = true)
WHERE a.attrelid =
(SELECT oid FROM pg_catalog.pg_class WHERE relname=' . $this->quote($tableSub) . '
AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE
nspname = \'public\')
nspname = \'' . $schema . '\')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use $this->quote() for quoting please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@HLeithner
Copy link
Member

@HLeithner Do you think this PR is a bug fix for 3.9 or a new feature for 4.0? From my point of view it is a bug fix since it is not good practice to use the public schema for everything in PostgreSQL, as far as I know, like it has to be without this PR. But I might be wrong, so I'd like to know your opinion, and @alikon 's, too, because he is doing much with PostgreSQL.

It's a bugfix.

@alikon
Copy link
Contributor

alikon commented May 24, 2019

to me too it's a bugfix

@ghost
Copy link

ghost commented May 24, 2019

@softarius
Copy link
Contributor Author

@HLeithner Do you think this PR is a bug fix for 3.9 or a new feature for 4.0? From my point of view it is a bug fix since it is not good practice to use the public schema for everything in PostgreSQL, as far as I know, like it has to be without this PR. But I might be wrong, so I'd like to know your opinion, and @alikon 's, too, because he is doing much with PostgreSQL.

My PR isn't only bug-fix. It's a feature request for a future version of Joomla.
Best practice for PostgresSQL is using different schemas for logical subsystems into a database.
Proof - https://www.postgresql.org/docs/10/ddl-schemas.html#DDL-SCHEMAS-PATTERNS
Simple RDBS (not supported schemas, such as MySQL) use surrogate solving with a prefix for tables.
When I write a new component for Joomla with PostgreSQL, I wont to use for this separate schema.
In another side, in big and complex system Joomla could use schema. called other than "public". But Joomla can't do it.
Third, with good schemas supporting Joomla could switching between schemas just different databases.

@HLeithner
Copy link
Member

I'm not sure what you mean with "Simple RDBS (not supported schemas, such as MySQL)" is the schema support of MySQL different then the support form PostgresSQL?

@softarius
Copy link
Contributor Author

I'm not sure what you mean with "Simple RDBS (not supported schemas, such as MySQL)" is the schema support of MySQL different then the support form PostgresSQL?

Using the term 'schema' completely different in other systems.
In MySQL and Firebird command CREATE SCHEMA is a synonym for CREATE DATABASE -

In more powerful RDBMS (Oracle, SQL Server, PostgreSQL ) a schema is essentially a namespace.
Proofs:

$tableSub = $this->replacePrefix($table);
$fn = explode('.', $tableSub);
if (count($fn) == 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (count($fn) == 2)
if (count($fn) == 2)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

$fn = explode('.', $tableSub);
if (count($fn) == 2)
{
$schema = $fn[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent lines 411, 412, and 416.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -391,7 +391,7 @@ public function getTableCreate($tables)
/**
* Retrieves field information about a given table.
*
* @param string $table The name of the database table.
* @param string $table The name of the database table. For PostgreSQL may starting with a schema
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param string $table The name of the database table. For PostgreSQL may starting with a schema
* @param string $table The name of the database table. For PostgreSQL may start with a schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@HLeithner
Copy link
Member

I'm not sure what you mean with "Simple RDBS (not supported schemas, such as MySQL)" is the schema support of MySQL different then the support form PostgresSQL?

Using the term 'schema' completely different in other systems.
In MySQL and Firebird command CREATE SCHEMA is a synonym for CREATE DATABASE -

ok thx, anyway in this case it's only a bugfix because it's should handle this and don't break.

@alikon
Copy link
Contributor

alikon commented May 24, 2019

I have tested this item ✅ successfully on d16b754


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24999.

@richard67
Copy link
Member

@softarius I've changed the "Actual result" in your testing instructions to the value from the issue. I guess that was a copy and paste thing from "Expected result", so it was the same as that, and in the issue it was correct, right?

@richard67
Copy link
Member

@HLeithner I can fully confirm @softarius 's explanations above.

@richard67
Copy link
Member

I have tested this item ✅ successfully on d16b754


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24999.

@alikon
Copy link
Contributor

alikon commented May 25, 2019

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24999.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label May 25, 2019
@richard67
Copy link
Member

@alikon Have there ever been discussions in past about full db schema support in Joomla, i.e. you can specify a schema like you can specify user and database names when installing on PostgreSQL, so Joomla can be installed using a different schema than "Public"? If so, what was the result of these discussions?

@richard67
Copy link
Member

For the one who will merge: Drone failure is not related to this PR.

@softarius
Copy link
Contributor Author

@softarius I've changed the "Actual result" in your testing instructions to the value from the issue. I guess that was a copy and paste thing from "Expected result", so it was the same as that, and in the issue it was correct, right?

Yes.

@alikon
Copy link
Contributor

alikon commented May 27, 2019

@richard67

Have there ever been discussions in past about full db schema support in Joomla

not that i'm aware of

Co-Authored-By: SharkyKZ <sharkykz@gmail.com>
@richard67
Copy link
Member

I have tested this item ✅ successfully on 3da16d1


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24999.

@HLeithner HLeithner merged commit 4db621f into joomla:staging Jun 5, 2019
@HLeithner
Copy link
Member

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants