Skip to content

Bug: createTable() method in Forge class checks for table existence using cache and causes problems #6351

Description

@AnakinA1

PHP Version

8.1

CodeIgniter4 Version

4.2.2

CodeIgniter4 Installation Method

Composer (as dependency to an existing project)

Which operating systems have you tested for this bug?

macOS, Linux

Which server did you use?

fpm-fcgi

Database

MariaDB 10.8

What happened?

In the new minor version of CI Database/Forge class has now:

// If table exists lets stop here
if ($ifNotExists === true && $this->db->tableExists($table)) {
    $this->reset();

    return true;
}

Let's focus on $this->db->tableExists($table) if flag $ifNotExists is true

Will give a real example of issue:

For tests I have a migration which fully drop current database and restore it from the provided SQL file. I'm doing it with direct db connection ($this->db->mysqli) using multi_query(). Then I need to create a migration table in order for the migration system to work. I'm doing it with Forge class, because it's a framework technical table and should not be included into project SQL scheme.

Steps to Reproduce

In the migration file:

  • drop db
  • add db
  • then try to create migration table if it doesn't exist (to prevent possible error on failing)
  • table is not created, because the check $this->db->tableExists($table) uses cache

This example only applies to my case, but let's assume the following:

Just drop any table with query method and then try to restore it via forge class

Expected Output

Forge class shouldn't rely on cache, or should be highlighted in the documentation that Forge class relies on the cache in its work and should not be used (or it is necessary to clear the cache) when working with direct querying, not through the builder

Anything else?

Ref #6249

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions