inverse-inc / packetfence

PacketFence is a fully supported, trusted, Free and Open Source network access control (NAC) solution. Boasting an impressive feature set including a captive-portal for registration and remediation, centralized wired and wireless management, powerful BYOD management options, 802.1X support, layer-2 isolation of problematic devices; PacketFence can be used to effectively secure networks small to very large heterogeneous networks.
https://packetfence.org
GNU General Public License v2.0
1.39k stars 291 forks source link

14.1 (Devel) upgrade script always fails at DB upgrade due to hard-coded DB version (14.0) #8390

Closed E-ThanG closed 2 days ago

E-ThanG commented 1 week ago

Describe the bug

  1. The development PF branch fails to upgrade the database with the error message "PREVIOUS VERSION 14.1 DOES NOT MATCH 14.0" regardless of which previous DB version is entered. The upgrade script asks for that information, but then ignores it and uses the hard-coded values. The issue probably exists because 14.1 is not the released version, the DB script upgrade-X.X-X.Y.sql has 14.0 as the hard coded previous version. That's the only version that we can possibly be upgrading from? This means that an upgrade from 14.0 to 14.1 works. But "upgrading" from 14.1 to 14.1 doesn't.

    upgrade-X.X-X.Y.sql  contents:
    SET @PREV_MAJOR_VERSION = 14;
    SET @PREV_MINOR_VERSION = 0;
  2. Why does it ask for the old version but then ignore the input?

  3. Why is it asking questions at all? It can programmatically determine the old DB version since it's in the database and it already knows the version that the upgrade IS.

  4. The text "You need to input the PF version that comes before $UPGRADE_TO" is not clear. It should say "What database version are you upgrading from? :" or something to that effect. But as I mention above, it really shouldn't be asking at all.

  5. If I am staying in 14.1, it shouldn't be trying to upgrade the database at all, unless it really needs to.

To Reproduce Steps to reproduce the behavior:

  1. Update 14.1 with the upgrade script
  2. See error "PREVIOUS VERSION 14.1 DOES NOT MATCH 14.0" failure.
Upgrade to a devel package detected. Renaming DB upgrade schema accordingly
---------------------------------------------------------------------------------
You need to input the PF version that comes before 14.1. This will replace X.X in the upgrade-X.X-X.Y.sql filename. Only input the minor version (ex: 11.2): 14.1
=================================================================================
Database pf runs version 14.1
Found upgrade path: /usr/local/pf/db/upgrade-14.1-14.1.sql
---------------------------------------------------------------------------------
Running /usr/local/pf/db/upgrade-14.1-14.1.sql
--------------
SET sql_mode = "NO_ENGINE_SUBSTITUTION"
--------------

--------------
SET @MAJOR_VERSION = 14
--------------

--------------
SET @MINOR_VERSION = 1
--------------

--------------
SET @PREV_MAJOR_VERSION = 14
--------------

--------------
SET @PREV_MINOR_VERSION = 0
--------------

--------------
SET @VERSION_INT = @MAJOR_VERSION << 16 | @MINOR_VERSION << 8
--------------

--------------
SET @PREV_VERSION_INT = @PREV_MAJOR_VERSION << 16 | @PREV_MINOR_VERSION << 8
--------------

--------------
DROP PROCEDURE IF EXISTS ValidateVersion
--------------

--------------
CREATE PROCEDURE ValidateVersion()
BEGIN
    DECLARE PREVIOUS_VERSION int(11);
    DECLARE PREVIOUS_VERSION_STRING varchar(11);
    DECLARE _message varchar(255);
    SELECT id, version INTO PREVIOUS_VERSION, PREVIOUS_VERSION_STRING FROM pf_version ORDER BY id DESC LIMIT 1;

      IF PREVIOUS_VERSION != @PREV_VERSION_INT THEN
        SELECT CONCAT('PREVIOUS VERSION ', PREVIOUS_VERSION_STRING, ' DOES NOT MATCH ', CONCAT_WS('.', @PREV_MAJOR_VERSION, @PREV_MINOR_VERSION)) INTO _message;
        SIGNAL SQLSTATE VALUE '99999'
              SET MESSAGE_TEXT = _message;
      END IF;
END
--------------

Checking PacketFence schema version...
--------------
call ValidateVersion
--------------

ERROR 1644 (99999) at line 50: PREVIOUS VERSION 14.1 DOES NOT MATCH 14.0

Expected behavior dev->dev branch upgrade should work

satkunas commented 2 days ago

@E-ThanG the script is not meant to be run consecutively. But can be done so if the pf_version table is modified manually.

UPDATE `pf_version` SET `version`='X.Y';
E-ThanG commented 1 day ago

That's fine, but Is there an issue with the logic that triggers it then? Ultimately I'd like to be able to complete an update of 14.1 without a failure. Whether I've correctly identified the root cause or not, I'd also like to have the other points considered.