init
This commit is contained in:
232 files changed
+25416
No files matched your search
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\BazaarApiRequest;
|
||||
use App\Models\MobileApp;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<BazaarApiRequest>
|
||||
*/
|
||||
class BazaarApiRequestFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'mobile_app_id' => MobileApp::factory(),
|
||||
'operation' => 'purchase.validate',
|
||||
'method' => 'GET',
|
||||
'url' => 'https://pardakht.cafebazaar.ir/devapi/v2/api/example',
|
||||
'status_code' => 200,
|
||||
'successful' => true,
|
||||
'duration_ms' => 100,
|
||||
'request_metadata' => [],
|
||||
'response_body' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\BazaarPurchase;
|
||||
use App\Models\MobileApp;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<BazaarPurchase>
|
||||
*/
|
||||
class BazaarPurchaseFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'mobile_app_id' => MobileApp::factory(),
|
||||
'product_id' => fake()->word(),
|
||||
'purchase_token' => fake()->unique()->uuid(),
|
||||
'status' => 'purchased',
|
||||
'is_consumed' => false,
|
||||
'purchased_at' => now(),
|
||||
'validated_at' => now(),
|
||||
'bazaar_response' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\BazaarRelease;
|
||||
use App\Models\MobileApp;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<BazaarRelease>
|
||||
*/
|
||||
class BazaarReleaseFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'mobile_app_id' => MobileApp::factory(),
|
||||
'status' => 'draft',
|
||||
'artifact_type' => 'apk',
|
||||
'staged_rollout_percentage' => 100,
|
||||
'auto_publish' => false,
|
||||
'bazaar_response' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\BazaarReview;
|
||||
use App\Models\MobileApp;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<BazaarReview>
|
||||
*/
|
||||
class BazaarReviewFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'mobile_app_id' => MobileApp::factory(),
|
||||
'bazaar_review_id' => fake()->unique()->numberBetween(1, 99999999),
|
||||
'user_account_id' => fake()->uuid(),
|
||||
'rate' => fake()->numberBetween(1, 5),
|
||||
'text' => fake()->sentence(),
|
||||
'is_edited' => false,
|
||||
'published_at' => now(),
|
||||
'bazaar_response' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\BazaarSubscription;
|
||||
use App\Models\MobileApp;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<BazaarSubscription>
|
||||
*/
|
||||
class BazaarSubscriptionFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'mobile_app_id' => MobileApp::factory(),
|
||||
'subscription_id' => fake()->word(),
|
||||
'purchase_token' => fake()->unique()->uuid(),
|
||||
'linked_subscription_token' => fake()->uuid(),
|
||||
'status' => 'active',
|
||||
'auto_renewing' => true,
|
||||
'starts_at' => now()->subDay(),
|
||||
'valid_until' => now()->addMonth(),
|
||||
'validated_at' => now(),
|
||||
'bazaar_response' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\MobileApp;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<MobileApp>
|
||||
*/
|
||||
class MobileAppFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->company(),
|
||||
'package_name' => 'ir.'.fake()->unique()->domainWord().'.'.fake()->word(),
|
||||
'client_key' => Str::random(48),
|
||||
'management_key' => Str::random(64),
|
||||
'is_active' => true,
|
||||
'maintenance_mode' => false,
|
||||
'latest_version_name' => '1.0.0',
|
||||
'latest_version_code' => 1,
|
||||
'minimum_version_code' => 1,
|
||||
'configuration' => [],
|
||||
'feature_flags' => [],
|
||||
'bazaar_api_secret' => Str::random(64),
|
||||
'bazaar_comments_header' => 'CAFEBAZAAR-PISHKHAN-API-SECRET',
|
||||
'bazaar_comments_secret' => Str::random(64),
|
||||
'bazaar_sync_enabled' => true,
|
||||
'bazaar_sync_interval_minutes' => 15,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
};
|
||||
@@ -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');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
<?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->unsignedSmallInteger('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->string('connection');
|
||||
$table->string('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
|
||||
$table->index(['connection', 'queue', 'failed_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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('mobile_apps', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('package_name')->unique();
|
||||
$table->text('client_key');
|
||||
$table->text('management_key');
|
||||
$table->boolean('is_active')->default(true)->index();
|
||||
$table->boolean('maintenance_mode')->default(false);
|
||||
$table->string('latest_version_name')->nullable();
|
||||
$table->unsignedBigInteger('latest_version_code')->nullable();
|
||||
$table->unsignedBigInteger('minimum_version_code')->nullable();
|
||||
$table->text('store_url')->nullable();
|
||||
$table->text('privacy_url')->nullable();
|
||||
$table->string('support_email')->nullable();
|
||||
$table->json('configuration')->nullable();
|
||||
$table->json('feature_flags')->nullable();
|
||||
$table->text('bazaar_api_secret')->nullable();
|
||||
$table->string('bazaar_comments_header')->nullable();
|
||||
$table->text('bazaar_comments_secret')->nullable();
|
||||
$table->string('bazaar_login_client_id')->nullable();
|
||||
$table->text('bazaar_login_client_secret')->nullable();
|
||||
$table->text('bazaar_login_redirect_url')->nullable();
|
||||
$table->text('bazaar_billing_public_key')->nullable();
|
||||
$table->boolean('bazaar_sync_enabled')->default(true)->index();
|
||||
$table->unsignedSmallInteger('bazaar_sync_interval_minutes')->default(15);
|
||||
$table->string('bazaar_sync_status')->default('idle')->index();
|
||||
$table->timestamp('bazaar_sync_started_at')->nullable();
|
||||
$table->timestamp('bazaar_last_synced_at')->nullable()->index();
|
||||
$table->text('bazaar_sync_error')->nullable();
|
||||
$table->json('bazaar_sync_summary')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('mobile_apps');
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('mobile_app_user', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mobile_app_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('role')->default('admin');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['mobile_app_id', 'user_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('mobile_app_user');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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('bazaar_purchases', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mobile_app_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('product_id')->index();
|
||||
$table->text('purchase_token');
|
||||
$table->char('purchase_token_hash', 64);
|
||||
$table->string('status')->default('unknown')->index();
|
||||
$table->boolean('is_consumed')->nullable();
|
||||
$table->timestamp('purchased_at')->nullable()->index();
|
||||
$table->timestamp('validated_at')->nullable();
|
||||
$table->json('bazaar_response')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['mobile_app_id', 'purchase_token_hash']);
|
||||
$table->index(['mobile_app_id', 'validated_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('bazaar_purchases');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
<?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('bazaar_subscriptions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mobile_app_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('subscription_id')->index();
|
||||
$table->text('purchase_token');
|
||||
$table->char('purchase_token_hash', 64);
|
||||
$table->string('linked_subscription_token')->nullable()->index();
|
||||
$table->string('status')->default('unknown')->index();
|
||||
$table->boolean('auto_renewing')->nullable();
|
||||
$table->timestamp('starts_at')->nullable();
|
||||
$table->timestamp('valid_until')->nullable()->index();
|
||||
$table->timestamp('validated_at')->nullable();
|
||||
$table->json('bazaar_response')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['mobile_app_id', 'purchase_token_hash']);
|
||||
$table->index(['mobile_app_id', 'validated_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('bazaar_subscriptions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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('bazaar_releases', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mobile_app_id')->constrained()->cascadeOnDelete();
|
||||
$table->unsignedBigInteger('bazaar_release_id')->nullable()->index();
|
||||
$table->string('status')->index();
|
||||
$table->string('artifact_type')->nullable();
|
||||
$table->unsignedInteger('staged_rollout_percentage')->default(100);
|
||||
$table->boolean('auto_publish')->default(false);
|
||||
$table->text('changelog_fa')->nullable();
|
||||
$table->text('changelog_en')->nullable();
|
||||
$table->text('developer_note')->nullable();
|
||||
$table->json('bazaar_response')->nullable();
|
||||
$table->timestamp('committed_at')->nullable();
|
||||
$table->timestamp('published_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('bazaar_releases');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
<?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('bazaar_reviews', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mobile_app_id')->constrained()->cascadeOnDelete();
|
||||
$table->unsignedBigInteger('bazaar_review_id');
|
||||
$table->string('user_account_id')->nullable();
|
||||
$table->unsignedTinyInteger('rate')->index();
|
||||
$table->text('text');
|
||||
$table->unsignedBigInteger('app_version_code')->nullable()->index();
|
||||
$table->boolean('is_edited')->default(false);
|
||||
$table->timestamp('published_at')->nullable()->index();
|
||||
$table->text('developer_reply_text')->nullable();
|
||||
$table->string('developer_reply_email')->nullable();
|
||||
$table->timestamp('developer_replied_at')->nullable();
|
||||
$table->json('bazaar_response')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['mobile_app_id', 'bazaar_review_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('bazaar_reviews');
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('bazaar_api_requests', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('mobile_app_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('operation')->index();
|
||||
$table->string('method', 10);
|
||||
$table->text('url');
|
||||
$table->unsignedSmallInteger('status_code')->nullable()->index();
|
||||
$table->boolean('successful')->default(false)->index();
|
||||
$table->unsignedInteger('duration_ms')->nullable();
|
||||
$table->json('request_metadata')->nullable();
|
||||
$table->json('response_body')->nullable();
|
||||
$table->text('error_message')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('bazaar_api_requests');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$this->call(LocalDevelopmentSeeder::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\BazaarApiRequest;
|
||||
use App\Models\BazaarPurchase;
|
||||
use App\Models\BazaarRelease;
|
||||
use App\Models\BazaarReview;
|
||||
use App\Models\BazaarSubscription;
|
||||
use App\Models\MobileApp;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Sequence;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LocalDevelopmentSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
if (! app()->environment(['local', 'testing'])) {
|
||||
$this->command?->warn('Local development data was not seeded outside the local or testing environment.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
DB::transaction(fn () => $this->seedLocalData());
|
||||
}
|
||||
|
||||
private function seedLocalData(): void
|
||||
{
|
||||
$packageNames = ['ir.local.cafe', 'ir.local.wallet'];
|
||||
|
||||
MobileApp::query()
|
||||
->whereIn('package_name', $packageNames)
|
||||
->get()
|
||||
->each(fn (MobileApp $app) => $app->delete());
|
||||
|
||||
$ownerAttributes = User::factory()->make([
|
||||
'name' => 'Local Admin',
|
||||
'email' => 'admin@example.test',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$owner = User::query()->updateOrCreate(
|
||||
['email' => $ownerAttributes->email],
|
||||
$ownerAttributes->only(['name', 'password', 'email_verified_at']),
|
||||
);
|
||||
|
||||
$cafeApp = MobileApp::factory()
|
||||
->has(
|
||||
BazaarPurchase::factory()->count(8)->sequence(
|
||||
fn (Sequence $sequence): array => [
|
||||
'product_id' => $sequence->index % 2 === 0 ? 'coffee_credits_100' : 'premium_theme',
|
||||
'status' => $sequence->index === 6 ? 'refunded' : 'purchased',
|
||||
'is_consumed' => $sequence->index % 3 === 0,
|
||||
'purchased_at' => now()->subDays($sequence->index + 1),
|
||||
],
|
||||
),
|
||||
'bazaarPurchases',
|
||||
)
|
||||
->has(
|
||||
BazaarSubscription::factory()->count(6)->sequence(
|
||||
['subscription_id' => 'monthly_pro', 'status' => 'active', 'valid_until' => now()->addMonth(), 'auto_renewing' => true],
|
||||
['subscription_id' => 'yearly_pro', 'status' => 'active', 'valid_until' => now()->addYear(), 'auto_renewing' => true],
|
||||
['subscription_id' => 'monthly_pro', 'status' => 'expired', 'valid_until' => now()->subMonth(), 'auto_renewing' => false],
|
||||
['subscription_id' => 'yearly_pro', 'status' => 'cancelled', 'valid_until' => now()->addDays(12), 'auto_renewing' => false],
|
||||
),
|
||||
'bazaarSubscriptions',
|
||||
)
|
||||
->has(
|
||||
BazaarRelease::factory()->count(3)->sequence(
|
||||
['bazaar_release_id' => 1001, 'status' => 'draft'],
|
||||
['bazaar_release_id' => 1002, 'status' => 'committed', 'committed_at' => now()->subWeek()],
|
||||
['bazaar_release_id' => 1003, 'status' => 'published', 'committed_at' => now()->subMonth(), 'published_at' => now()->subWeeks(3)],
|
||||
),
|
||||
'bazaarReleases',
|
||||
)
|
||||
->has(
|
||||
BazaarReview::factory()->count(12)->sequence(
|
||||
fn (Sequence $sequence): array => [
|
||||
'bazaar_review_id' => 100_000 + $sequence->index,
|
||||
'rate' => ($sequence->index % 5) + 1,
|
||||
'text' => "Local review number {$sequence->index}",
|
||||
'app_version_code' => $sequence->index < 6 ? 10 : 11,
|
||||
'published_at' => now()->subDays($sequence->index),
|
||||
'developer_reply_text' => $sequence->index % 3 === 0 ? 'Thank you for your feedback.' : null,
|
||||
'developer_replied_at' => $sequence->index % 3 === 0 ? now()->subDays($sequence->index)->addHour() : null,
|
||||
],
|
||||
),
|
||||
'bazaarReviews',
|
||||
)
|
||||
->has(
|
||||
BazaarApiRequest::factory()->count(15)->sequence(
|
||||
fn (Sequence $sequence): array => [
|
||||
'operation' => ['purchase.validate', 'subscription.show', 'reviews.list', 'release.last_published'][$sequence->index % 4],
|
||||
'successful' => $sequence->index % 5 !== 0,
|
||||
'status_code' => $sequence->index % 5 === 0 ? 502 : 200,
|
||||
'duration_ms' => 80 + ($sequence->index * 17),
|
||||
],
|
||||
),
|
||||
'bazaarApiRequests',
|
||||
)
|
||||
->create([
|
||||
'name' => 'Local Cafe',
|
||||
'package_name' => $packageNames[0],
|
||||
'client_key' => 'local-cafe-client-key',
|
||||
'management_key' => 'local-cafe-management-key',
|
||||
'latest_version_name' => '1.1.0',
|
||||
'latest_version_code' => 11,
|
||||
'minimum_version_code' => 9,
|
||||
'support_email' => 'support@example.test',
|
||||
'configuration' => ['welcome_message' => 'Welcome to the local Cafe demo'],
|
||||
'feature_flags' => ['new_checkout' => true, 'recommendations' => false],
|
||||
'bazaar_sync_status' => 'succeeded',
|
||||
'bazaar_last_synced_at' => now()->subMinutes(5),
|
||||
]);
|
||||
|
||||
BazaarApiRequest::factory()
|
||||
->for($cafeApp)
|
||||
->create([
|
||||
'operation' => 'subscription.show',
|
||||
'successful' => false,
|
||||
'status_code' => 400,
|
||||
'error_message' => 'Seeded invalid subscription token response.',
|
||||
]);
|
||||
|
||||
$walletApp = MobileApp::factory()
|
||||
->has(BazaarPurchase::factory()->count(3), 'bazaarPurchases')
|
||||
->has(BazaarSubscription::factory()->count(2), 'bazaarSubscriptions')
|
||||
->has(BazaarRelease::factory()->count(1)->state(['status' => 'published', 'published_at' => now()->subDay()]), 'bazaarReleases')
|
||||
->has(BazaarReview::factory()->count(4), 'bazaarReviews')
|
||||
->has(BazaarApiRequest::factory()->count(5), 'bazaarApiRequests')
|
||||
->create([
|
||||
'name' => 'Local Wallet',
|
||||
'package_name' => $packageNames[1],
|
||||
'client_key' => 'local-wallet-client-key',
|
||||
'management_key' => 'local-wallet-management-key',
|
||||
'maintenance_mode' => true,
|
||||
'latest_version_name' => '2.4.1',
|
||||
'latest_version_code' => 241,
|
||||
'minimum_version_code' => 230,
|
||||
'feature_flags' => ['new_checkout' => false],
|
||||
'bazaar_sync_status' => 'partial',
|
||||
'bazaar_sync_error' => 'Seeded partial synchronization for UI testing.',
|
||||
'bazaar_last_synced_at' => now()->subHour(),
|
||||
]);
|
||||
|
||||
$owner->mobileApps()->syncWithoutDetaching([
|
||||
$cafeApp->id => ['role' => 'owner'],
|
||||
$walletApp->id => ['role' => 'owner'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user