initial commit
This commit is contained in:
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->integer('expiration')->index();
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->integer('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,57 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Tpetry\PostgresqlEnhanced\Schema\Blueprint;
|
||||
use Tpetry\PostgresqlEnhanced\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::createFunctionOrReplace(
|
||||
name: 'update_contacts_ts_name',
|
||||
parameters: [],
|
||||
return: 'trigger',
|
||||
language: 'plpgsql',
|
||||
body: <<<'SQL'
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT'
|
||||
OR NEW.first_name IS DISTINCT FROM OLD.first_name
|
||||
OR NEW.last_name IS DISTINCT FROM OLD.last_name THEN
|
||||
NEW.ts_name =
|
||||
to_tsvector('simple',
|
||||
coalesce(NEW.first_name, '') || ' ' || coalesce(NEW.last_name, '')
|
||||
);
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
SQL);
|
||||
|
||||
Schema::createExtensionIfNotExists('pg_trgm');
|
||||
|
||||
Schema::create('contacts', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('first_name', 100)->nullable();
|
||||
$table->string('last_name', 100)->nullable();
|
||||
$table->string('email', 254)->unique();
|
||||
$table->tsvector('ts_name');
|
||||
$table->trigger('ts_name_contacts_build_vector', 'update_contacts_ts_name()', 'BEFORE INSERT OR UPDATE')->forEachRow(); // mising indexes (GIN!!! etc.)
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
DB::statement('CREATE INDEX idx_contacts_email_trgm ON contacts USING GIN (email gin_trgm_ops)');
|
||||
DB::statement('CREATE INDEX idx_contacts_ts_name ON contacts USING GIN (ts_name);');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('contacts');
|
||||
Schema::dropFunctionIfExists('update_contacts_ts_name');
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('contact_imports', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->timestamp('queue_at')->default(DB::raw('CURRENT_TIMESTAMP'));
|
||||
$table->timestamp('started_at')->nullable();
|
||||
$table->timestamp('finished_at')->nullable();
|
||||
$table->unsignedInteger('total_processed')->default(0);
|
||||
$table->unsignedInteger('errors')->default(0);
|
||||
$table->unsignedInteger('duplicates')->default(0);
|
||||
$table->string('file');
|
||||
$table->enum('state', ['PENDING', 'RUNNING', 'DONE', 'FAILED'])->default('PENDING');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('contact_imports');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user