first commit
This commit is contained in:
49
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
49
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignId('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->longText('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
};
|
||||
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->bigInteger('expiration')->index();
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->bigInteger('expiration')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cache');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
}
|
||||
};
|
||||
57
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
57
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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('source_databases', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('host');
|
||||
$table->integer('port')->default(5432);
|
||||
$table->string('database');
|
||||
$table->string('username');
|
||||
$table->string('password');
|
||||
$table->string('driver')->default('pgsql');
|
||||
$table->text('description')->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamp('last_synced_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['host', 'port', 'database'], 'unique_source_connection');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('source_databases');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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('target_databases', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('host');
|
||||
$table->integer('port')->default(5432);
|
||||
$table->string('database');
|
||||
$table->string('username');
|
||||
$table->string('password');
|
||||
$table->string('driver')->default('pgsql');
|
||||
$table->text('description')->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['host', 'port', 'database'], 'unique_target_connection');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('target_databases');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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('tables', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('source_database_id')->constrained('source_databases')->cascadeOnDelete();
|
||||
$table->string('schema_name')->default('public');
|
||||
$table->string('table_name');
|
||||
$table->text('comment')->nullable();
|
||||
$table->json('options')->nullable();
|
||||
$table->timestamp('last_checked_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['source_database_id', 'schema_name', 'table_name'], 'unique_table');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tables');
|
||||
}
|
||||
};
|
||||
@@ -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('columns', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('table_id')->constrained('tables')->cascadeOnDelete();
|
||||
$table->string('column_name');
|
||||
$table->string('data_type');
|
||||
$table->string('udt_name')->nullable();
|
||||
$table->integer('ordinal_position');
|
||||
$table->boolean('is_nullable')->default(true);
|
||||
$table->string('column_default')->nullable();
|
||||
$table->integer('character_maximum_length')->nullable();
|
||||
$table->integer('numeric_precision')->nullable();
|
||||
$table->integer('numeric_scale')->nullable();
|
||||
$table->string('datetime_precision')->nullable();
|
||||
$table->text('comment')->nullable();
|
||||
$table->boolean('is_primary_key')->default(false);
|
||||
$table->boolean('is_foreign_key')->default(false);
|
||||
$table->boolean('is_indexed')->default(false);
|
||||
// Column mapping for target database
|
||||
$table->string('target_column_name')->nullable();
|
||||
$table->string('target_data_type')->nullable();
|
||||
$table->boolean('exclude_from_migration')->default(false);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['table_id', 'column_name'], 'unique_column');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('columns');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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('indexes', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('table_id')->constrained('tables')->cascadeOnDelete();
|
||||
$table->string('index_name');
|
||||
$table->json('columns'); // Array of column names
|
||||
$table->boolean('is_unique')->default(false);
|
||||
$table->boolean('is_primary')->default(false);
|
||||
$table->string('index_type')->default('btree');
|
||||
$table->text('definition')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['table_id', 'index_name'], 'unique_index');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('indexes');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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('foreign_keys', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('table_id')->constrained('tables')->cascadeOnDelete();
|
||||
$table->string('constraint_name');
|
||||
$table->string('column_name');
|
||||
$table->string('referenced_table');
|
||||
$table->string('referenced_column');
|
||||
$table->string('on_update')->nullable();
|
||||
$table->string('on_delete')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['table_id', 'constraint_name', 'column_name'], 'unique_foreign_key');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('foreign_keys');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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('migration_schedules', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->foreignId('source_database_id')->constrained('source_databases')->cascadeOnDelete();
|
||||
$table->foreignId('target_database_id')->constrained('target_databases')->cascadeOnDelete();
|
||||
$table->json('tables'); // Array of table IDs to migrate
|
||||
$table->string('cron_expression'); // e.g., "0 * * * *" for hourly
|
||||
$table->string('timezone')->default('UTC');
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->boolean('run_in_parallel')->default(false);
|
||||
$table->integer('batch_size')->default(1000);
|
||||
$table->boolean('truncate_before_migration')->default(false);
|
||||
$table->boolean('create_indexes_after')->default(true);
|
||||
$table->text('python_script_path')->nullable();
|
||||
$table->json('python_script_args')->nullable();
|
||||
$table->text('description')->nullable();
|
||||
$table->timestamp('last_run_at')->nullable();
|
||||
$table->timestamp('next_run_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('migration_schedules');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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('migration_runs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('schedule_id')->constrained('migration_schedules')->cascadeOnDelete();
|
||||
$table->string('status')->default('pending'); // pending, running, completed, failed
|
||||
$table->integer('total_tables')->default(0);
|
||||
$table->integer('processed_tables')->default(0);
|
||||
$table->integer('total_rows')->default(0);
|
||||
$table->integer('migrated_rows')->default(0);
|
||||
$table->integer('failed_rows')->default(0);
|
||||
$table->text('error_message')->nullable();
|
||||
$table->json('logs')->nullable();
|
||||
$table->timestamp('started_at')->nullable();
|
||||
$table->timestamp('completed_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['schedule_id', 'status']);
|
||||
$table->index('created_at');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('migration_runs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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('schema_changes', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('table_id')->constrained('tables')->cascadeOnDelete();
|
||||
$table->string('change_type'); // column_added, column_dropped, column_modified, index_added, index_dropped
|
||||
$table->json('old_value')->nullable();
|
||||
$table->json('new_value')->nullable();
|
||||
$table->text('description');
|
||||
$table->boolean('is_applied')->default(false);
|
||||
$table->timestamp('detected_at');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['table_id', 'is_applied']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('schema_changes');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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('migration_schedule_tables', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('migration_schedule_id')->constrained('migration_schedules')->cascadeOnDelete();
|
||||
$table->foreignId('table_id')->constrained('tables')->cascadeOnDelete();
|
||||
$table->integer('order')->default(0);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['migration_schedule_id', 'table_id']);
|
||||
$table->index('order');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('migration_schedule_tables');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<?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('migration_schedules', function (Blueprint $table) {
|
||||
$table->boolean('is_incremental')->default(false)->after('is_active');
|
||||
$table->string('incremental_column')->nullable()->after('is_incremental');
|
||||
$table->timestamp('last_successful_migration_at')->nullable()->after('next_run_at');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('migration_schedules', function (Blueprint $table) {
|
||||
$table->dropColumn(['is_incremental', 'incremental_column', 'last_successful_migration_at']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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('migration_schedules', function (Blueprint $table) {
|
||||
$table->boolean('use_life_table')->default(false)->after('is_incremental');
|
||||
$table->string('life_table_name')->nullable()->after('use_life_table');
|
||||
$table->string('life_id_column')->nullable()->after('life_table_name');
|
||||
$table->string('base_id_column')->nullable()->after('life_id_column');
|
||||
$table->string('operation_column')->default('x_Operation')->after('base_id_column');
|
||||
$table->string('datetime_column')->default('x_DateTime')->after('operation_column');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('migration_schedules', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'use_life_table',
|
||||
'life_table_name',
|
||||
'life_id_column',
|
||||
'base_id_column',
|
||||
'operation_column',
|
||||
'datetime_column',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user