summaryrefslogtreecommitdiff
path: root/bin/db.php
diff options
context:
space:
mode:
Diffstat (limited to 'bin/db.php')
-rw-r--r--bin/db.php160
1 files changed, 160 insertions, 0 deletions
diff --git a/bin/db.php b/bin/db.php
new file mode 100644
index 0000000..951c0b3
--- /dev/null
+++ b/bin/db.php
@@ -0,0 +1,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);