This repository has been archived by the owner on Aug 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stubs-generator.php
97 lines (82 loc) · 2.64 KB
/
stubs-generator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
use Faker\Factory;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
use Wandu\Laravel\Repository\Stubs\Model\Article;
use Wandu\Laravel\Repository\Stubs\Model\ArticleHit;
use Wandu\Laravel\Repository\Stubs\Model\Category;
use Wandu\Laravel\Repository\Stubs\Model\User;
require __DIR__ . '/vendor/autoload.php';
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'sqlite',
'database' => './stubs.sqlite',
'prefix' => '',
]);
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
$capsule->schema()->dropIfExists('article_hits');
$capsule->schema()->dropIfExists('categories');
$capsule->schema()->dropIfExists('articles');
$capsule->schema()->dropIfExists('users');
$capsule->schema()->create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('username', 100)->unique();
$table->string('password', 100);
$table->timestamps();
});
$capsule->schema()->create('articles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('username', 100);
$table->string('content', 100)->unique();
$table->integer('vote')->default(0);
$table->timestamps();
});
/*
CREATE TABLE `comments` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`content` varchar(100),
`vote` INTEGER DEFAULT 0,
`ancestor_vote` INTEGER DEFAULT 0,
`order` VARBINARY(255) DEFAULT 000,
`ancestor_order` VARBINARY(255) DEFAULT 000
);
*/
$capsule->schema()->create('article_hits', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('article_id')->unsingied();
$table->bigInteger('user_id')->unsingied();
$table->timestamps();
});
$capsule->schema()->create('categories', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('article_id')->unsigned();
$table->string('name', 100);
});
$faker = Factory::create();
for ($i = 0; $i < 100; $i++) {
User::create([
'username' => $faker->userName,
'password' => $faker->password,
]);
}
for ($i = 0; $i < 200; $i++) {
Article::create([
'username' => User::find(rand(1, 100))['username'],
'content' => $faker->text
]);
}
for ($i = 0; $i < 200; $i++) {
Category::create([
'article_id' => rand(1, 200),
'name' => ['Q&A', 'PHP', 'FreeBoard', 'Javascript', 'Go'][rand(0, 4)]
]);
}
for ($i = 0; $i < 400; $i++) {
ArticleHit::create([
'article_id' => rand(1, 200),
'user_id' => rand(1, 100),
]);
}