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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
<?php
use App\DB;
use Symfony\Component\Dotenv\Dotenv;
require dirname(__DIR__) . '/vendor/autoload.php';
$dotenv = new Dotenv();
$dotenv->load(dirname(__DIR__) . '/.env');
DB::init();
DB::query(<<<SQL
create table if not exists "villages" (
"id" bigserial primary key,
"name" character varying(255) not null,
"x" integer not null,
"y" integer not null,
"wood" bigint not null,
"clay" bigint not null,
"iron" bigint not null,
"food" bigint not null,
"satisfaction" bigint not null,
"created_at" timestamp(0) not null default current_timestamp,
"updated_at" timestamp(0) not null default current_timestamp,
unique ("x", "y")
);
SQL);
DB::query(<<<SQL
create table if not exists "village_buildings" (
"id" bigserial primary key,
"level" smallint not null,
"type" character varying(255) not null,
"village_id" bigint not null,
constraint "relation_village"
foreign key ("village_id") references villages("id") on delete cascade,
"created_at" timestamp(0) not null default current_timestamp,
"updated_at" timestamp(0) not null default current_timestamp,
unique ("type", "village_id")
);
SQL);
DB::query(<<<SQL
create table if not exists "village_units" (
"id" bigserial primary key,
"amount" bigint not null,
"type" character varying(255) not null,
"is_traveling" boolean not null default false,
"home_village_id" bigint not null,
constraint "relation_village_home"
foreign key ("home_village_id") references villages("id") on delete cascade,
"residence_village_id" bigint not null,
constraint "relation_village_residence"
foreign key ("residence_village_id") references villages("id") on delete cascade,
"created_at" timestamp(0) not null default current_timestamp,
"updated_at" timestamp(0) not null default current_timestamp,
unique ("type", "home_village_id", "residence_village_id")
);
SQL);
DB::query(<<<SQL
create table if not exists "village_storage_config" (
"id" bigserial primary key,
"wood" smallint not null,
"clay" smallint not null,
"iron" smallint not null,
"food" smallint not null,
"village_id" bigint not null,
constraint "relation_village"
foreign key ("village_id") references villages("id") on delete cascade,
"created_at" timestamp(0) not null default current_timestamp,
"updated_at" timestamp(0) not null default current_timestamp
);
SQL);
DB::query(<<<SQL
create table if not exists "events" (
"id" bigserial primary key,
"time" timestamp(0) not null,
"village_id" bigint not null,
constraint "relation_village"
foreign key ("village_id") references villages("id") on delete cascade,
"created_at" timestamp(0) not null default current_timestamp,
"updated_at" timestamp(0) not null default current_timestamp
);
SQL);
DB::query(<<<SQL
create table if not exists "events_upgrade_building" (
"id" bigserial primary key,
"event_id" bigint not null,
constraint "relation_event"
foreign key ("event_id") references events("id") on delete cascade,
"type" character varying(255) not null,
"created_at" timestamp(0) not null default current_timestamp,
"updated_at" timestamp(0) not null default current_timestamp
);
SQL);
DB::query(<<<SQL
create table if not exists "users" (
"id" bigserial primary key,
"username" character varying(255) not null,
"password" character varying(255) not null,
"email" character varying(255) not null,
"created_at" timestamp(0) not null default current_timestamp,
"updated_at" timestamp(0) not null default current_timestamp,
unique ("username")
);
SQL);
DB::query(<<<SQL
create table if not exists "user_settings" (
"id" bigserial primary key,
"display_name" character varying(255) not null,
"user_id" bigint not null,
constraint "relation_user"
foreign key ("user_id") references users("id") on delete cascade,
"created_at" timestamp(0) not null default current_timestamp,
"updated_at" timestamp(0) not null default current_timestamp
);
SQL);
DB::query(<<<SQL
create table if not exists "system" (
"key" character varying(255) primary key,
"value" jsonb
);
SQL);
|