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

[5] Sync the sequence for pgsql after the root user is created #44324

Merged
merged 5 commits into from
Oct 22, 2024

Conversation

alikon
Copy link
Contributor

@alikon alikon commented Oct 21, 2024

Pull Request for Issue # .
on installation joomla create a SuperUser whose id is generated random(1,1000)

but with postgresql the relative sequence #__users_id_seq is not setted is still 1, so as soon we create an user
whose id is equal to the id created for the Super User we got duplicate key value violates unique constraint "jos_users_pkey

Summary of Changes

set the relative sequence #__users_id_seq after the super user creation

Testing Instructions

apply pull PR
and run cypress install/installation.cy.js

and the run this test:

scripts/create 52 pgsql
cat > branch_52/tests/System/integration/install/duplicate.cy.js <<EOF
describe('Test duplicate key value error', () => {
  it('in creating 1,000 users', () => {
    for (let i = 1; i <= 1000; i++) {
        cy.db_createUser({username: \`test user \${i}\` });
    }
  });
});
EOF

scripts/test 52 system install/duplicate.cy.js

Actual result BEFORE applying this Pull Request

duplicate key value violates unique constraint "jos_users_pkey

Expected result AFTER applying this Pull Request

no more duplicate error

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@alikon alikon marked this pull request as ready for review October 21, 2024 09:42
@rdeutz
Copy link
Contributor

rdeutz commented Oct 21, 2024

Good find!

@muhme
Copy link
Contributor

muhme commented Oct 22, 2024

✅ Tested succesfully on macOS 👍

  • Installed PR 44324 with Patch Tester
  • Testing requires the installation step, as the fix applies during the installation step. Therefore, I used:
scripts/test 52 system tests/System/integration/install/Installation.cy.js,tests/System/integration/install/duplicate.cy.js
  • Additionally, all remaining System Tests (without the installation step) passed:
scripts/test 52 system


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

@laoneo laoneo changed the title [5] synch the sequence for pgsql [5] Sync the sequence for pgsql after the root user is created Oct 22, 2024
alikon and others added 3 commits October 22, 2024 11:18
Co-authored-by: Richard Fath <richard67@users.noreply.github.com>
Co-authored-by: Richard Fath <richard67@users.noreply.github.com>
@richard67
Copy link
Member

@muhme Could you repeat your test to make sure my suggested changes did not break anything? And if successful, mark your test result in the issue tracker with the blue "Text this" button in the PR details? Thanks in advance.

@richard67
Copy link
Member

richard67 commented Oct 22, 2024

I have tested this item ✅ successfully on a2feb76

I haven't tested as described with Cypress. Instead of this, I have done following.

I've made a new installation of a clean 5.2-dev branch using an empty PostgreSQL database (of course after composer install and npm ci).

Directly after that (no need to login to the backend) I have checked the ID of the superuser and the last value of the "#__users_id_seq" sequence with phpPgAdmin. (Last value is a misleading term because in fact is is the next value.)

Result: The superuser's ID has a value between 1 and 1000, e.g. 362. The last value of the sequence is 1.

Then I have done the same with the branch of this PR under the same starting conditions (clean branch, composer install, npm ci, install into empty PostgreSQL DB).

Result: The superuser's ID has a value between 1 and 1000, e.g. 362. The last value of the sequence is this ID value plus 1, e.g. 363.


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

@richard67
Copy link
Member

Additional test: After the installation and the checks in phpPgAdmin I logged in to the administrator and have created a new user.

Without the PR that new user has ID = 1 (one).

With the PR the new user has ID = ID of the super user plus one.

@muhme
Copy link
Contributor

muhme commented Oct 22, 2024

I have tested this item ✅ successfully on a2feb76

On macOS with JBT created 5.2-dev branch installation with additional test case and run the tests to see the problem:

scripts/create 52 pgsql
cat > branch_52/tests/System/integration/install/duplicate.cy.js <<EOF
describe('Test duplicate key value error', () => {
  it('in creating 1,000 users', () => {
    for (let i = 1; i <= 1000; i++) {
        cy.db_createUser({username: \`test user \${i}\` });
    }
  });
});
EOF
scripts/test 52 system tests/System/integration/install/Installation.cy.js,tests/System/integration/install/duplicate.cy.js

Problem seen:

  1) Test duplicate key value error
       in creating 1,000 users:
     CypressError: `cy.task('queryDB')` failed with the following error:

> duplicate key value violates unique constraint "jos52_users_pkey"

Checked PR with recreating 5.2-dev branch with additional test case and installing patch tester, applying PR 44324 and running same tests again plus all remaining System Tests:

scripts/create recreate 52 pgsql
scripts/patchtester 52
# Applying PR 44324 in http://host.docker.internal:7052/administrator/index.php?option=com_patchtester
cat > branch_52/tests/System/integration/install/duplicate.cy.js <<EOF
describe('Test duplicate key value error', () => {
  it('in creating 1,000 users', () => {
    for (let i = 1; i <= 1000; i++) {
        cy.db_createUser({username: \`test user \${i}\` });
    }
  });
});
EOF
scripts/test 52 system tests/System/integration/install/Installation.cy.js,tests/System/integration/install/duplicate.cy.js
scripts/test 52 system

One timeout error and repeated this single test step:

scripts/test system 52 administrator/components/com_cpanel/CPanel.cy.js

All tests are passed successfully 👍


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

@laoneo laoneo merged commit a28c352 into joomla:5.2-dev Oct 22, 2024
4 checks passed
@laoneo
Copy link
Member

laoneo commented Oct 22, 2024

Thanks you guys for the extensive testing and @alikon for fixing this long standing bug.

@laoneo laoneo added this to the Joomla! 5.2.1 milestone Oct 22, 2024
@alikon alikon deleted the patch-23 branch October 23, 2024 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants