diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-09-24 13:40:25 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-09-24 13:40:25 +0200 |
commit | fa00b957378a393f8edbfc98ef111d35d18ecb09 (patch) | |
tree | 654e7dc5414f7f2795dbe996d3e1570793a5b1b8 /bin |
initial commit
Diffstat (limited to 'bin')
-rw-r--r-- | bin/villages.php | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/bin/villages.php b/bin/villages.php new file mode 100644 index 0000000..092a754 --- /dev/null +++ b/bin/villages.php @@ -0,0 +1,147 @@ +<?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, + "updated_at" timestamp(0) not null, + + 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, + "updated_at" timestamp(0) not null, + + 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, + "updated_at" timestamp(0) not null, + + 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, + "updated_at" timestamp(0) not null + ); +SQL); + +DB::query(<<<SQL + create table if not exists "events" ( + "id" bigserial primary key, + + "type" character varying(255) not null, + "time" timestamp(0) not null, + "payload" jsonb 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 "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, + "updated_at" timestamp(0) not null, + + 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, + "updated_at" timestamp(0) not null + ); +SQL); + +DB::query(<<<SQL + create table if not exists "system" ( + "key" character varying(255) primary key, + "value" jsonb + ); +SQL); |