Initial Version (Working relay implementing basic functionality)
This commit is contained in:
commit
aeae39df4d
15 changed files with 1272 additions and 0 deletions
12
migrations/0-init.sql
Normal file
12
migrations/0-init.sql
Normal file
|
@ -0,0 +1,12 @@
|
|||
CREATE TABLE migration_history (
|
||||
migration_id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),
|
||||
migration_version INTEGER NOT NULL,
|
||||
migration_name TEXT NOT NULL,
|
||||
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
duration_ms INTEGER NOT NULL,
|
||||
status TEXT NOT NULL CHECK (status IN ('success', 'failed', 'reverted')),
|
||||
error_message TEXT
|
||||
);
|
||||
|
||||
CREATE INDEX idx_migration_history_name ON migration_history(migration_name);
|
||||
CREATE INDEX idx_migration_history_executed_at ON migration_history(executed_at);
|
36
migrations/1-createEventsStore.sql
Normal file
36
migrations/1-createEventsStore.sql
Normal file
|
@ -0,0 +1,36 @@
|
|||
CREATE TABLE events (
|
||||
id TEXT NOT NULL, -- Event ID (32-byte hex)
|
||||
original_id TEXT, -- Original (encrypted) event ID (32-byte hex)
|
||||
pubkey TEXT NOT NULL, -- Author's public key (32-byte hex)
|
||||
created_at INTEGER NOT NULL,-- Unix timestamp in seconds
|
||||
kind INTEGER NOT NULL, -- Event kind number
|
||||
content TEXT NOT NULL,
|
||||
sig TEXT NOT NULL, -- Event signature (64-byte hex)
|
||||
first_seen INTEGER,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE event_tags (
|
||||
tag_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
event_id TEXT NOT NULL,
|
||||
tag_name TEXT NOT NULL,
|
||||
tag_index INTEGER NOT NULL,
|
||||
FOREIGN KEY (event_id) REFERENCES events(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE event_tags_values (
|
||||
tag_id INTEGER NOT NULL,
|
||||
value_position INTEGER NOT NULL,
|
||||
value TEXT NOT NULL,
|
||||
FOREIGN KEY (tag_id) REFERENCES event_tags(tag_id)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_events_id ON events(id);
|
||||
CREATE INDEX idx_events_pubkey ON events(pubkey);
|
||||
CREATE INDEX idx_events_created_at ON events(created_at);
|
||||
CREATE INDEX idx_events_kind ON events(kind);
|
||||
CREATE INDEX idx_events_original_id ON events(original_id);
|
||||
|
||||
CREATE INDEX idx_event_tags_event_id ON event_tags(event_id);
|
||||
CREATE INDEX idx_event_tags_name ON event_tags(tag_name, tag_index);
|
||||
CREATE INDEX idx_event_tags_values ON event_tags_values(tag_id, value_position, value);
|
10
migrations/2-createEventsTagsView.sql
Normal file
10
migrations/2-createEventsTagsView.sql
Normal file
|
@ -0,0 +1,10 @@
|
|||
CREATE VIEW event_tags_view AS
|
||||
SELECT
|
||||
t.event_id,
|
||||
t.tag_index,
|
||||
t.tag_name,
|
||||
v.value as tag_value,
|
||||
v.value_position as tag_value_position
|
||||
FROM event_tags t
|
||||
LEFT JOIN event_tags_values v ON t.tag_id = v.tag_id
|
||||
ORDER BY t.tag_index, v.value_position;
|
Loading…
Add table
Add a link
Reference in a new issue