Closed JIFVGWHvAseSovQ closed 2 months ago
entrypoint.sh
# Database creation
if [[ "${DB_CONNECTION}" == "sqlite" || "${DB_CONNECTION}" == "sqlite3" ]]; then
# DB_DATABASE is trimmed if necessary
if [[ $DB_DATABASE == \"* ]] && [[ $DB_DATABASE == *\" ]] ; then
dbpath=${DB_DATABASE:1:${#DB_DATABASE}-2}
else
dbpath=${DB_DATABASE}
fi
db_name=$(basename "$dbpath")
linkname="/srv/database/$db_name"
if [ $dbpath != "$linkname" ]; then
echo "DB_DATABASE sets with custom path: ${dbpath}"
if [ ! -f ${dbpath} ]; then
echo "${dbpath} does not exist, we create it"
touch ${dbpath}
fi
else
echo "DB_DATABASE sets with default path, we will use a symlink"
echo "Actual db file will be /2fauth/database.sqlite"
if [ ! -f /2fauth/$db_name ]; then
echo "/2fauth/$db_name does not exist, we create it"
touch /2fauth/$db_name
fi
rm -f $linkname
ln -s /2fauth/$db_name $linkname
echo "$linkname is now a symlink to /2fauth/$db_name"
fi
fi
database.php
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => envUnlessEmpty('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
'sqlite3' => [
'driver' => 'sqlite3',
'url' => env('DATABASE_URL'),
'database' => envUnlessEmpty('DB_DATABASE', database_path('database.sqlite3')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
Hi,
Supported version of SQLite is SQLite 3.35.0 or higher. You do not need to create a specific connection, the one provided is for SQLite3.
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => function_exists('database_path') ? (function () {
$path = envUnlessEmpty('DB_DATABASE', database_path('database'));
if (file_exists($path)) {
return $path;
}
if (file_exists($path . '.sqlite')) {
return $path . '.sqlite';
}
if (file_exists($path . '.sqlite3')) {
return $path . '.sqlite3';
}
// If none exist, return the default .sqlite path.
return $path . '.sqlite';
})() : ':memory:',
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
When self-compiling, I hope 2fauth can support both SQLite and SQLite3. I encountered errors while adjusting some code.
Besides entrypoint.sh and database.php, what other areas need adjustment?
Cannot find the error in program ConnectionFactory.php.