From 27a0df43b33b712462ab5be65462162b9e4bcd29 Mon Sep 17 00:00:00 2001
From: fusion32 <marcopuzziello@gmail.com>
Date: Thu, 23 Oct 2025 04:26:11 -0300
Subject: change how guild data is stored

---
 sqlite/schema.sql | 44 ++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 4 deletions(-)

(limited to 'sqlite/schema.sql')

diff --git a/sqlite/schema.sql b/sqlite/schema.sql
index 0ab3a9f..2ee1a8b 100644
--- a/sqlite/schema.sql
+++ b/sqlite/schema.sql
@@ -57,9 +57,6 @@ CREATE TABLE Characters (
 	AccountID INTEGER NOT NULL,
 	Name TEXT NOT NULL COLLATE NOCASE,
 	Sex INTEGER NOT NULL,
-	Guild TEXT NOT NULL COLLATE NOCASE DEFAULT '',
-	Rank TEXT NOT NULL COLLATE NOCASE DEFAULT '',
-	Title TEXT NOT NULL DEFAULT '',
 	Level INTEGER NOT NULL DEFAULT 0,
 	Profession TEXT NOT NULL DEFAULT '',
 	Residence TEXT NOT NULL DEFAULT '',
@@ -72,7 +69,6 @@ CREATE TABLE Characters (
 );
 CREATE INDEX CharactersWorldIndex   ON Characters(WorldID, IsOnline);
 CREATE INDEX CharactersAccountIndex ON Characters(AccountID, IsOnline);
-CREATE INDEX CharactersGuildIndex   ON Characters(Guild, Rank);
 
 /*
 -- TODO(fusion): Have group rights instead of adding individual rights to characters?
@@ -123,6 +119,46 @@ CREATE TABLE LoginAttempts (
 CREATE INDEX LoginAttemptsAccountIndex ON LoginAttempts(AccountID, Timestamp);
 CREATE INDEX LoginAttemptsAddressIndex ON LoginAttempts(IPAddress, Timestamp);
 
+-- Guild Tables
+--==============================================================================
+CREATE TABLE Guilds (
+	WorldID INTEGER NOT NULL,
+	GuildID INTEGER NOT NULL,
+	Name TEXT NOT NULL COLLATE NOCASE,
+	LeaderID INTEGER NOT NULL,
+	Created INTEGER NOT NULL,
+	PRIMARY KEY (GuildID),
+	UNIQUE (Name),
+	UNIQUE (LeaderID)
+);
+
+CREATE TABLE GuildRanks (
+	GuildID INTEGER NOT NULL,
+	Rank INTEGER NOT NULL,
+	Name TEXT NOT NULL,
+	PRIMARY KEY (GuildID, Rank)
+);
+
+CREATE TABLE GuildMembers (
+	GuildID INTEGER NOT NULL,
+	CharacterID INTEGER NOT NULL,
+	Rank INTEGER NOT NULL,
+	Title TEXT NOT NULL,
+	Joined INTEGER NOT NULL,
+	PRIMARY KEY (CharacterID)
+);
+CREATE INDEX GuildMembersGuildIndex ON GuildMembers(GuildID, Rank);
+
+CREATE TABLE GuildInvites (
+	GuildID INTEGER NOT NULL,
+	CharacterID INTEGER NOT NULL,
+	RecruiterID INTEGER NOT NULL,
+	Timestamp INTEGER NOT NULL,
+	PRIMARY KEY (GuildID, CharacterID)
+);
+CREATE INDEX GuildInvitesCharacterIndex ON GuildInvites(CharacterID);
+CREATE INDEX GuildInvitesRecruiterIndex ON GuildInvites(RecruiterID);
+
 -- House Tables
 --==============================================================================
 CREATE TABLE Houses (
-- 
cgit v1.2.3

