Initial commit of the Asset Management System, including project structure, Docker configuration, database migrations, and core application files. Added user authentication, asset management features, and basic UI components.

This commit is contained in:
2025-08-22 21:41:02 +02:00
parent b43a98f0ec
commit 677f70a19c
52 changed files with 5186 additions and 2 deletions

26
scripts/entrypoint.sh Normal file
View File

@@ -0,0 +1,26 @@
#!/bin/sh
# Wait for database to be ready
echo "Waiting for database to be ready..."
while ! mysqladmin ping -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" --silent; do
sleep 1
done
echo "Database is ready!"
# Run migrations
echo "Running database migrations..."
php /var/www/html/scripts/migrate.php
# Run seeders if database is empty
echo "Checking if seeders need to be run..."
php /var/www/html/scripts/seed.php
# Set proper permissions
chown -R www-data:www-data /var/www/html/storage
chmod -R 755 /var/www/html/storage
echo "Application is ready!"
# Start PHP-FPM
exec php-fpm

87
scripts/migrate.php Normal file
View File

@@ -0,0 +1,87 @@
<?php
/**
* Database Migration Script
*/
require_once __DIR__ . '/../vendor/autoload.php';
// Load environment variables
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load();
// Load configuration
require_once __DIR__ . '/../config/config.php';
try {
$pdo = new PDO(
sprintf('mysql:host=%s;port=%d;dbname=%s;charset=utf8mb4', DB_HOST, DB_PORT, DB_NAME),
DB_USER,
DB_PASS,
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]
);
echo "Connected to database successfully.\n";
// Create migrations table if it doesn't exist
$pdo->exec("
CREATE TABLE IF NOT EXISTS migrations (
id INT AUTO_INCREMENT PRIMARY KEY,
migration VARCHAR(255) NOT NULL,
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
");
// Get all migration files
$migrationFiles = glob(__DIR__ . '/../database/migrations/*.sql');
sort($migrationFiles);
// Get executed migrations
$stmt = $pdo->query("SELECT migration FROM migrations");
$executedMigrations = $stmt->fetchAll(PDO::FETCH_COLUMN);
$executedCount = 0;
foreach ($migrationFiles as $file) {
$migrationName = basename($file);
if (in_array($migrationName, $executedMigrations)) {
echo "Migration {$migrationName} already executed.\n";
continue;
}
echo "Executing migration: {$migrationName}\n";
// Read and execute migration
$sql = file_get_contents($file);
try {
$pdo->exec($sql);
// Record migration as executed
$stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?)");
$stmt->execute([$migrationName]);
echo "Migration {$migrationName} executed successfully.\n";
$executedCount++;
} catch (PDOException $e) {
echo "Error executing migration {$migrationName}: " . $e->getMessage() . "\n";
exit(1);
}
}
if ($executedCount > 0) {
echo "Executed {$executedCount} new migrations.\n";
} else {
echo "No new migrations to execute.\n";
}
echo "Database migration completed successfully.\n";
} catch (PDOException $e) {
echo "Database connection failed: " . $e->getMessage() . "\n";
exit(1);
}

83
scripts/seed.php Normal file
View File

@@ -0,0 +1,83 @@
<?php
/**
* Database Seeder Script
*/
require_once __DIR__ . '/../vendor/autoload.php';
// Load environment variables
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load();
// Load configuration
require_once __DIR__ . '/../config/config.php';
try {
$pdo = new PDO(
sprintf('mysql:host=%s;port=%d;dbname=%s;charset=utf8mb4', DB_HOST, DB_PORT, DB_NAME),
DB_USER,
DB_PASS,
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]
);
echo "Connected to database successfully.\n";
// Check if users table has data
$stmt = $pdo->query("SELECT COUNT(*) as count FROM users");
$userCount = $stmt->fetch()['count'];
if ($userCount > 0) {
echo "Database already has data. Skipping seeders.\n";
exit(0);
}
echo "Database is empty. Running seeders...\n";
// Get all seeder files
$seederFiles = glob(__DIR__ . '/../database/seeds/*.sql');
sort($seederFiles);
foreach ($seederFiles as $file) {
$seederName = basename($file);
echo "Running seeder: {$seederName}\n";
// Read and execute seeder
$sql = file_get_contents($file);
try {
$pdo->exec($sql);
echo "Seeder {$seederName} executed successfully.\n";
} catch (PDOException $e) {
echo "Error executing seeder {$seederName}: " . $e->getMessage() . "\n";
exit(1);
}
}
// Create default admin user with proper password hash
echo "Creating default admin user...\n";
$adminPassword = 'Admin!234';
$adminHash = password_hash($adminPassword, PASSWORD_ARGON2ID);
$stmt = $pdo->prepare("
UPDATE users
SET passhash = ?
WHERE email = 'admin@example.com'
");
$stmt->execute([$adminHash]);
echo "Default admin user created:\n";
echo "Email: admin@example.com\n";
echo "Password: {$adminPassword}\n";
echo "Please change the password on first login!\n";
echo "Database seeding completed successfully.\n";
} catch (PDOException $e) {
echo "Database connection failed: " . $e->getMessage() . "\n";
exit(1);
}