Spaces:
Paused
Paused
Upload schema.sql
Browse files- schema.sql +79 -3
schema.sql
CHANGED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
-- ============================================================
|
| 2 |
-
-- Soldier Life 2D - Database Bootstrap (
|
| 3 |
-
--
|
|
|
|
|
|
|
|
|
|
| 4 |
-- ============================================================
|
| 5 |
|
| 6 |
-
-- دالة تنفيذ DDL عامة (يستخدمها الخادم للهجرة التلقائية) - تتطلب لصقًا واحدًا فقط
|
| 7 |
create or replace function public.exec_ddl(sql text)
|
| 8 |
returns void
|
| 9 |
language plpgsql
|
|
@@ -19,3 +21,77 @@ revoke all on function public.exec_ddl(text) from public;
|
|
| 19 |
revoke all on function public.exec_ddl(text) from anon;
|
| 20 |
revoke all on function public.exec_ddl(text) from authenticated;
|
| 21 |
grant execute on function public.exec_ddl(text) to service_role;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
-- ============================================================
|
| 2 |
+
-- Soldier Life 2D - Database Bootstrap (FULL / one paste)
|
| 3 |
+
-- 1) ينشئ دالة exec_ddl (للهجرات التلقائية المستقبلية من الخادم)
|
| 4 |
+
-- 2) ينشئ كل الجداول والفهارس كاملة فورًا
|
| 5 |
+
-- نفّذه مرة واحدة في: Supabase Dashboard -> SQL Editor -> New query -> Run
|
| 6 |
+
-- للتحقق بعد التنفيذ: SELECT to_regclass('public.players'); -- يجب أن يرجع "players"
|
| 7 |
-- ============================================================
|
| 8 |
|
|
|
|
| 9 |
create or replace function public.exec_ddl(sql text)
|
| 10 |
returns void
|
| 11 |
language plpgsql
|
|
|
|
| 21 |
revoke all on function public.exec_ddl(text) from anon;
|
| 22 |
revoke all on function public.exec_ddl(text) from authenticated;
|
| 23 |
grant execute on function public.exec_ddl(text) to service_role;
|
| 24 |
+
|
| 25 |
+
-- ----------------------------------------------------------
|
| 26 |
+
-- ترقية الجداول القديمة إن وُجدت (لا-عملية على قاعدة جديدة)
|
| 27 |
+
alter table public.players add column if not exists is_admin boolean not null default false;
|
| 28 |
+
alter table public.players add column if not exists admin_rank int not null default 0;
|
| 29 |
+
alter table public.players add column if not exists level int not null default 1;
|
| 30 |
+
alter table public.players add column if not exists xp int not null default 0;
|
| 31 |
+
alter table public.players add column if not exists money int not null default 0;
|
| 32 |
+
alter table public.players add column if not exists ip text;
|
| 33 |
+
alter table public.players add column if not exists device text;
|
| 34 |
+
alter table public.players add column if not exists cookies jsonb not null default '{}'::jsonb;
|
| 35 |
+
alter table public.players add column if not exists inventory jsonb not null default '[]'::jsonb;
|
| 36 |
+
alter table public.players add column if not exists guns jsonb not null default '{"owned":[],"equipped":null}'::jsonb;
|
| 37 |
+
alter table public.players add column if not exists stats jsonb not null default '{}'::jsonb;
|
| 38 |
+
alter table public.players add column if not exists banned_until timestamptz;
|
| 39 |
+
alter table public.players add column if not exists ban_reason text;
|
| 40 |
+
alter table public.players add column if not exists last_login_at timestamptz;
|
| 41 |
+
update public.players set is_admin = true where role = 'admin' and is_admin = false;
|
| 42 |
+
|
| 43 |
+
-- الجداول والفهارس الكاملة
|
| 44 |
+
create table if not exists public.players (
|
| 45 |
+
id bigint generated always as identity primary key,
|
| 46 |
+
username text not null,
|
| 47 |
+
username_norm text not null,
|
| 48 |
+
password_hash text not null,
|
| 49 |
+
is_admin boolean not null default false,
|
| 50 |
+
admin_rank int not null default 0,
|
| 51 |
+
rank_id int not null default 1,
|
| 52 |
+
level int not null default 1,
|
| 53 |
+
xp int not null default 0,
|
| 54 |
+
money int not null default 0,
|
| 55 |
+
ip text,
|
| 56 |
+
device text,
|
| 57 |
+
cookies jsonb not null default '{}'::jsonb,
|
| 58 |
+
character_data jsonb not null default '{}'::jsonb,
|
| 59 |
+
inventory jsonb not null default '[]'::jsonb,
|
| 60 |
+
guns jsonb not null default '{"owned":[],"equipped":null}'::jsonb,
|
| 61 |
+
stats jsonb not null default '{}'::jsonb,
|
| 62 |
+
banned_until timestamptz,
|
| 63 |
+
ban_reason text,
|
| 64 |
+
last_login_at timestamptz,
|
| 65 |
+
created_at timestamptz not null default now(),
|
| 66 |
+
updated_at timestamptz not null default now());
|
| 67 |
+
create unique index if not exists players_username_norm_uidx on public.players (username_norm);
|
| 68 |
+
create index if not exists players_is_admin_idx on public.players (is_admin);
|
| 69 |
+
create index if not exists players_admin_rank_idx on public.players (admin_rank);
|
| 70 |
+
create index if not exists players_rank_idx on public.players (rank_id);
|
| 71 |
+
create index if not exists players_level_idx on public.players (level);
|
| 72 |
+
create index if not exists players_created_idx on public.players (created_at desc);
|
| 73 |
+
create index if not exists players_ip_idx on public.players (ip);
|
| 74 |
+
create index if not exists players_login_idx on public.players (last_login_at desc);
|
| 75 |
+
create index if not exists players_inventory_gin on public.players using gin (inventory);
|
| 76 |
+
create index if not exists players_guns_gin on public.players using gin (guns);
|
| 77 |
+
create index if not exists players_stats_gin on public.players using gin (stats);
|
| 78 |
+
create table if not exists public.audit_log (
|
| 79 |
+
id bigint generated always as identity primary key,
|
| 80 |
+
admin_id bigint not null,
|
| 81 |
+
admin_name text not null,
|
| 82 |
+
action text not null,
|
| 83 |
+
target_id bigint,
|
| 84 |
+
target_name text,
|
| 85 |
+
detail text,
|
| 86 |
+
created_at timestamptz not null default now());
|
| 87 |
+
create index if not exists audit_created_idx on public.audit_log (created_at desc);
|
| 88 |
+
create index if not exists audit_admin_idx on public.audit_log (admin_id);
|
| 89 |
+
create table if not exists public.chat_log (
|
| 90 |
+
id bigint generated always as identity primary key,
|
| 91 |
+
player_id bigint not null,
|
| 92 |
+
player_name text not null,
|
| 93 |
+
msg text not null,
|
| 94 |
+
room text not null default 'global',
|
| 95 |
+
created_at timestamptz not null default now());
|
| 96 |
+
create index if not exists chat_created_idx on public.chat_log (created_at desc);
|
| 97 |
+
create index if not exists chat_player_idx on public.chat_log (player_id);
|