-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
151 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'sqlite3' | ||
# OS Requirements: | ||
#> sudo apt install -y postgresql-common | ||
#> sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh | ||
#> sudo apt install postgresql-16 | ||
|
||
# Open a database | ||
db = SQLite3::Database.new "XPlatform_Chat.db" | ||
|
||
# Example: Insert a new participant | ||
db.execute("INSERT INTO Personas (name, type) VALUES (?, ?)", ["John Doe", "human"]) | ||
participant_id = db.last_insert_row_id | ||
|
||
# Example: Insert participant identities for different platforms | ||
platforms = { | ||
"discord" => "john_doe#1234", | ||
"twitter" => "@john_doe", | ||
"speech_to_text" => "voice_profile_123" | ||
} | ||
|
||
platforms.each do |platform, platform_id| | ||
db.execute("INSERT INTO participant_identities (participant_id, platform, platform_id) VALUES (?, ?, ?)", | ||
[participant_id, platform, platform_id]) | ||
end | ||
|
||
# Example: Insert an AI participant | ||
db.execute("INSERT INTO Personas (name, type) VALUES (?, ?)", ["Claude", "ai"]) | ||
ai_participant_id = db.last_insert_row_id | ||
db.execute("INSERT INTO participant_identities (participant_id, platform, platform_id) VALUES (?, ?, ?)", | ||
[ai_participant_id, "anthropic", "claude_3.5"]) | ||
|
||
# Example: Create a conversation on Discord | ||
db.execute("INSERT INTO Conversations (title, platform) VALUES (?, ?)", ["Discord Chat", "discord"]) | ||
conversation_id = db.last_insert_row_id | ||
|
||
# Get participant identity IDs | ||
discord_identity_id = db.get_first_value("SELECT id FROM participant_identities WHERE participant_id = ? AND platform = ?", | ||
[participant_id, "discord"]) | ||
ai_identity_id = db.get_first_value("SELECT id FROM participant_identities WHERE participant_id = ?", [ai_participant_id]) | ||
|
||
# Link Personas to the conversation | ||
db.execute("INSERT INTO conversation_participants (conversation_id, participant_identity_id) VALUES (?, ?)", | ||
[conversation_id, discord_identity_id]) | ||
db.execute("INSERT INTO conversation_participants (conversation_id, participant_identity_id) VALUES (?, ?)", | ||
[conversation_id, ai_identity_id]) | ||
|
||
# Example: Insert messages | ||
db.execute("INSERT INTO messages (conversation_id, participant_identity_id, content) VALUES (?, ?, ?)", | ||
[conversation_id, discord_identity_id, "Hey Claude, how's it going?"]) | ||
db.execute("INSERT INTO messages (conversation_id, participant_identity_id, content) VALUES (?, ?, ?)", | ||
[conversation_id, ai_identity_id, "Hello! I'm doing well, thank you for asking. How can I assist you today?"]) | ||
|
||
# Close the database | ||
db.close |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* shikigami.sql skeleton database | ||
*/ | ||
|
||
BEGIN; | ||
|
||
-- Drop existing tables if they exist | ||
DROP TABLE IF EXISTS ConversationParticipants; | ||
DROP TABLE IF EXISTS Messages; | ||
DROP TABLE IF EXISTS PlatformIdentities; | ||
DROP TABLE IF EXISTS Personas; | ||
DROP TABLE IF EXISTS Conversations; | ||
|
||
-- Create Conversations table | ||
CREATE TABLE Conversations ( | ||
id SERIAL PRIMARY KEY, -- Use SERIAL for auto-incrementing IDs | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- DATETIME == TIMESTAMP for PostgreSQL | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
title TEXT, | ||
platform TEXT NOT NULL | ||
); | ||
|
||
-- Create Personas table | ||
CREATE TABLE Personas ( | ||
id SERIAL PRIMARY KEY, | ||
name TEXT NOT NULL, | ||
type TEXT NOT NULL | ||
); | ||
|
||
-- Create PlatformIdentities table | ||
CREATE TABLE PlatformIdentities ( | ||
id SERIAL PRIMARY KEY, | ||
participant_id INTEGER NOT NULL, | ||
platform TEXT NOT NULL, | ||
platform_id TEXT NOT NULL, | ||
FOREIGN KEY (participant_id) REFERENCES Personas(id) ON DELETE CASCADE, -- Enforce foreign key constraint | ||
UNIQUE (platform, platform_id) | ||
); | ||
|
||
-- Create Messages table | ||
CREATE TABLE Messages ( | ||
id SERIAL PRIMARY KEY, | ||
conversation_id INTEGER NOT NULL, | ||
persona_platform_id INTEGER NOT NULL, | ||
content TEXT NOT NULL, | ||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
FOREIGN KEY (conversation_id) REFERENCES Conversations(id) ON DELETE CASCADE, -- ON DELETE CASCADE ensures consistency | ||
FOREIGN KEY (persona_platform_id) REFERENCES PlatformIdentities(id) ON DELETE CASCADE | ||
); | ||
|
||
-- Create ConversationParticipants table | ||
-- + many-to-many junction table | ||
-- + tracks who is involved in which conversations | ||
CREATE TABLE ConversationParticipants ( | ||
conversation_id INTEGER NOT NULL, | ||
participant_id INTEGER NOT NULL, | ||
joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
FOREIGN KEY (conversation_id) REFERENCES Conversations(id) ON DELETE CASCADE, | ||
FOREIGN KEY (participant_id) REFERENCES PlatformIdentities(id) ON DELETE CASCADE, | ||
PRIMARY KEY (conversation_id, participant_id) | ||
); | ||
|
||
-- Create Indexes for Foreign Keys to improve query perf: | ||
CREATE INDEX idx_conversation_id ON Messages(conversation_id); | ||
CREATE INDEX idx_persona_platform_id ON Messages(persona_platform_id); | ||
CREATE INDEX idx_conversation_participants_conversation ON ConversationParticipants(conversation_id); | ||
CREATE INDEX idx_conversation_participants_participant ON ConversationParticipants(participant_id); | ||
|
||
-- Function to update each conversation according to latest activity: | ||
CREATE OR REPLACE FUNCTION update_conversation_timestamp() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
UPDATE Conversations | ||
SET updated_at = NOW() | ||
WHERE id = NEW.conversation_id; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
-- Latest activity trigger for Messages table | ||
CREATE TRIGGER update_conversation_on_new_message | ||
AFTER INSERT ON Messages | ||
FOR EACH ROW | ||
EXECUTE FUNCTION update_conversation_timestamp(); | ||
|
||
-- Latest activity trigger for ConversationParticipants table | ||
CREATE TRIGGER update_conversation_on_new_participant | ||
AFTER INSERT ON ConversationParticipants | ||
FOR EACH ROW | ||
EXECUTE FUNCTION update_conversation_timestamp(); | ||
|
||
COMMIT; | ||
-- .quit |