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

use writable directory for sqlite default location #3151

Merged
merged 9 commits into from
Jun 24, 2020
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ writable/session/*
writable/uploads/*
!writable/uploads/index.html

writable/data/*
!writable/data/index.html

writable/debugbar/*

writable/*.db
writable/*.sqlite

php_errors.log

#-------------------------
Expand Down
9 changes: 4 additions & 5 deletions system/Database/SQLite3/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ public function connect(bool $persistent = false)
}
try
{
$this->database = ($this->database === ':memory:')
? $this->database
: (strpos($this->database, DIRECTORY_SEPARATOR) === false
? WRITEPATH . 'data' . DIRECTORY_SEPARATOR . $this->database
: $this->database);
if ($this->database !== ':memory:' && strpos($this->database, DIRECTORY_SEPARATOR) === false)
{
$this->database = WRITEPATH . $this->database;
}

return (! $this->password)
? new \SQLite3($this->database)
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Database/Live/SQLite/AlterTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function setUp(): void

$config = [
'DBDriver' => 'SQLite3',
'database' => ':memory:',
'database' => 'database.db',
];

$this->db = db_connect($config);
Expand Down
5 changes: 4 additions & 1 deletion tests/system/Database/Migrations/MigrationRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function testLoadsDefaultDatabaseWhenNoneSpecified()
$db = $this->getPrivateProperty($runner, 'db');

$this->assertInstanceOf(BaseConnection::class, $db);
$this->assertEquals($dbConfig->tests['database'], $this->getPrivateProperty($db, 'database'));
$this->assertEquals(
($dbConfig->tests['DBDriver'] === 'SQLite3' ? WRITEPATH : '' ) . $dbConfig->tests['database'],
$this->getPrivateProperty($db, 'database')
);
$this->assertEquals($dbConfig->tests['DBDriver'], $this->getPrivateProperty($db, 'DBDriver'));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/travis/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'hostname' => 'localhost',
'username' => '',
'password' => '',
'database' => ':memory:',
'database' => 'database.db',
'DBDriver' => 'SQLite3',
'DBPrefix' => 'db_',
'pConnect' => false,
Expand Down
4 changes: 2 additions & 2 deletions user_guide_src/source/changelogs/v4.0.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Release Date: Unreleased

**4.0.4 release of CodeIgniter4**

The location for the SQLite3 database has changed and by default will be now located in a ``writable/data`` folder instead of the ``public`` folder.
The location for the SQLite3 database has changed and by default will be now located in a ``writable`` folder instead of the ``public`` folder.

Enhancements:


Bugs Fixed:

- Fixed location for the SQLite3 database which by default will be now located in a ``writable/data`` folder instead of the ``public`` folder.
- Fixed location for the SQLite3 database which by default will be now located in a ``writable`` folder instead of the ``public`` folder.
2 changes: 1 addition & 1 deletion user_guide_src/source/database/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ prototype::
The name of the class property is the connection name, and can be used
while connecting to specify a group name.

.. note:: The default location of the SQLite3 database is in the ``writable/data/`` folder.
.. note:: The default location of the SQLite3 database is in the ``writable`` folder.
If you want to change the location, you must set the full path to the new folder.

Some database drivers (such as PDO, PostgreSQL, Oracle, ODBC) might
Expand Down
11 changes: 0 additions & 11 deletions writable/data/index.html

This file was deleted.