Initial commit
This commit is contained in:
commit
c909d539bc
7178 files changed
+756624
No files matched your search
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('billing_accounts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
// Basic billing account identity
|
||||
$table->string('name'); // e.g. "Smith Family" or "Acme Ltd"
|
||||
$table->string('contact_name')->nullable(); // attachment for companies
|
||||
|
||||
// Primary parent user (nullable)
|
||||
$table->unsignedBigInteger('primary_parent_user_id')->nullable();
|
||||
$table->foreign('primary_parent_user_id')
|
||||
->references('id')->on('users')
|
||||
->nullOnDelete();
|
||||
|
||||
// Core billing communication channel
|
||||
$table->string('invoice_email');
|
||||
|
||||
// Optional phone for billing queries
|
||||
$table->string('phone')->nullable();
|
||||
|
||||
// Address fields
|
||||
$table->string('address_line1');
|
||||
$table->string('address_line2')->nullable();
|
||||
$table->string('town');
|
||||
$table->string('postcode');
|
||||
$table->string('country');
|
||||
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('billing_accounts');
|
||||
}
|
||||
};
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('student_profiles', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('billing_account_id')->nullable()->after('user_id');
|
||||
|
||||
$table->foreign('billing_account_id')
|
||||
->references('id')->on('billing_accounts')
|
||||
->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('student_profiles', function (Blueprint $table) {
|
||||
$table->dropForeign(['billing_account_id']);
|
||||
$table->dropColumn('billing_account_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('parent_profiles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
// Link to the users table
|
||||
$table->unsignedBigInteger('user_id')->unique();
|
||||
$table->foreign('user_id')
|
||||
->references('id')->on('users')
|
||||
->onDelete('cascade');
|
||||
|
||||
// Parent contact info
|
||||
$table->string('phone')->nullable();
|
||||
|
||||
// Parent address (optional, but useful)
|
||||
$table->string('address_line1')->nullable();
|
||||
$table->string('address_line2')->nullable();
|
||||
$table->string('town')->nullable();
|
||||
$table->string('postcode')->nullable();
|
||||
$table->string('country')->nullable();
|
||||
|
||||
// Notes about the parent
|
||||
$table->text('notes')->nullable();
|
||||
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('parent_profiles');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('parent_student', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
// Foreign keys
|
||||
$table->unsignedBigInteger('parent_profile_id');
|
||||
$table->unsignedBigInteger('student_profile_id');
|
||||
|
||||
$table->foreign('parent_profile_id')
|
||||
->references('id')->on('parent_profiles')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->foreign('student_profile_id')
|
||||
->references('id')->on('student_profiles')
|
||||
->onDelete('cascade');
|
||||
|
||||
// Optional descriptive relationship
|
||||
$table->string('relationship')->nullable();
|
||||
|
||||
// Optional admin notes
|
||||
$table->text('notes')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
// Ensure a parent cannot be linked to the same student twice
|
||||
$table->unique(['parent_profile_id', 'student_profile_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('parent_student');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
// Add new columns
|
||||
$table->string('first_name')->nullable()->after('id');
|
||||
$table->string('last_name')->nullable()->after('first_name');
|
||||
|
||||
// Make 'name' nullable so inserts won't fail
|
||||
$table->string('name')->nullable()->change();
|
||||
});
|
||||
|
||||
// Backfill: split existing 'name' into first and last
|
||||
$users = DB::table('users')->select('id', 'name')->get();
|
||||
|
||||
foreach ($users as $user) {
|
||||
if (!$user->name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Split the name safely
|
||||
$parts = explode(' ', $user->name, 2);
|
||||
$first = $parts[0];
|
||||
$last = $parts[1] ?? '';
|
||||
|
||||
DB::table('users')
|
||||
->where('id', $user->id)
|
||||
->update([
|
||||
'first_name' => $first,
|
||||
'last_name' => $last,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn(['first_name', 'last_name']);
|
||||
|
||||
// restore name to not null if needed
|
||||
$table->string('name')->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user