Add SQLite support as alternative database backend
Support config-driven choice between MySQL and SQLite via DB_DRIVER constant, defaulting to MySQL for backward compatibility. All SQL adaptation lives in Database.php (UDFs + query rewriting), so model files need no changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> SQLite: remove FK constraints, revert 0→null sentinel changes The SQLite schema had FOREIGN KEY constraints that don't exist in the MySQL schema. These forced a cascade of 0→null changes to satisfy FK enforcement. Removing them keeps the two backends behaviorally consistent and minimises the diff. Real SQLite compat fixes (UDFs, query rewriting, rowCount→count, Router fixes, EditAlbum guard) are preserved. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
58
seed.php
Normal file
58
seed.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/*****************************************************************************
|
||||
* seed.php
|
||||
* Seeds a fresh database with an admin user and root album.
|
||||
*
|
||||
* Usage: php seed.php
|
||||
*****************************************************************************/
|
||||
|
||||
require_once __DIR__ . '/config.php';
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
if (!defined('DB_DRIVER') || DB_DRIVER !== 'sqlite')
|
||||
{
|
||||
echo "Error: seed.php currently only supports SQLite.\n";
|
||||
echo "Set DB_DRIVER to 'sqlite' in config.php.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!file_exists(DB_FILE))
|
||||
{
|
||||
echo "Error: database file not found at " . DB_FILE . "\n";
|
||||
echo "Create it first: sqlite3 " . DB_FILE . " < schema.sqlite.sql\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$db = new Database('sqlite', ['file' => DB_FILE]);
|
||||
Registry::set('db', $db);
|
||||
|
||||
// Create admin user.
|
||||
$password = 'admin';
|
||||
$hash = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
$db->insert('insert', 'users', [], [
|
||||
'first_name' => 'Admin',
|
||||
'surname' => 'User',
|
||||
'slug' => 'admin',
|
||||
'emailaddress' => 'admin@localhost',
|
||||
'password_hash' => $hash,
|
||||
'creation_time' => time(),
|
||||
'ip_address' => '',
|
||||
'is_admin' => 1,
|
||||
'reset_key' => '',
|
||||
]);
|
||||
|
||||
echo "Created admin user (admin@localhost / admin)\n";
|
||||
|
||||
// Create root album (id_tag = 1).
|
||||
$db->insert('insert', 'tags', [], [
|
||||
'id_parent' => 0,
|
||||
'tag' => 'Albums',
|
||||
'slug' => 'albums',
|
||||
'kind' => 'Album',
|
||||
'description' => '',
|
||||
'count' => 0,
|
||||
]);
|
||||
|
||||
echo "Created root album (id_tag = 1)\n";
|
||||
echo "\nDone. You can now log in at the web UI.\n";
|
||||
Reference in New Issue
Block a user