v0.3.0 - Complete deployment documentation and examples - Added comprehensive deployment guide, automated deployment scripts, nginx SSL proxy setup, backup automation, and monitoring tools. Includes VPS deployment, cloud platform guides, and practical examples for production deployment of event-based configuration system.
This commit is contained in:
139
src/sql_schema.h
139
src/sql_schema.h
@@ -1,6 +1,6 @@
|
||||
/* Embedded SQL Schema for C Nostr Relay
|
||||
* Generated from db/schema.sql - Do not edit manually
|
||||
* Schema Version: 3
|
||||
* Schema Version: 4
|
||||
*/
|
||||
#ifndef SQL_SCHEMA_H
|
||||
#define SQL_SCHEMA_H
|
||||
@@ -12,6 +12,7 @@
|
||||
static const char* const EMBEDDED_SCHEMA_SQL =
|
||||
"-- C Nostr Relay Database Schema\n\
|
||||
-- SQLite schema for storing Nostr events with JSON tags support\n\
|
||||
-- Event-based configuration system using kind 33334 Nostr events\n\
|
||||
\n\
|
||||
-- Schema version tracking\n\
|
||||
PRAGMA user_version = 4;\n\
|
||||
@@ -57,8 +58,8 @@ CREATE TABLE schema_info (\n\
|
||||
\n\
|
||||
-- Insert schema metadata\n\
|
||||
INSERT INTO schema_info (key, value) VALUES\n\
|
||||
('version', '3'),\n\
|
||||
('description', 'Hybrid single-table Nostr relay schema with JSON tags and configuration management'),\n\
|
||||
('version', '4'),\n\
|
||||
('description', 'Event-based Nostr relay schema with kind 33334 configuration events'),\n\
|
||||
('created_at', strftime('%s', 'now'));\n\
|
||||
\n\
|
||||
-- Helper views for common queries\n\
|
||||
@@ -79,6 +80,19 @@ SELECT \n\
|
||||
FROM events\n\
|
||||
GROUP BY event_type;\n\
|
||||
\n\
|
||||
-- Configuration events view (kind 33334)\n\
|
||||
CREATE VIEW configuration_events AS\n\
|
||||
SELECT \n\
|
||||
id,\n\
|
||||
pubkey as admin_pubkey,\n\
|
||||
created_at,\n\
|
||||
content,\n\
|
||||
tags,\n\
|
||||
sig\n\
|
||||
FROM events\n\
|
||||
WHERE kind = 33334\n\
|
||||
ORDER BY created_at DESC;\n\
|
||||
\n\
|
||||
-- Optimization: Trigger for automatic cleanup of ephemeral events older than 1 hour\n\
|
||||
CREATE TRIGGER cleanup_ephemeral_events\n\
|
||||
AFTER INSERT ON events\n\
|
||||
@@ -101,6 +115,19 @@ BEGIN\n\
|
||||
AND id != NEW.id;\n\
|
||||
END;\n\
|
||||
\n\
|
||||
-- Addressable event handling trigger (for kind 33334 configuration events)\n\
|
||||
CREATE TRIGGER handle_addressable_events\n\
|
||||
AFTER INSERT ON events\n\
|
||||
WHEN NEW.event_type = 'addressable'\n\
|
||||
BEGIN\n\
|
||||
-- For kind 33334 (configuration), replace previous config from same admin\n\
|
||||
DELETE FROM events \n\
|
||||
WHERE pubkey = NEW.pubkey \n\
|
||||
AND kind = NEW.kind \n\
|
||||
AND event_type = 'addressable'\n\
|
||||
AND id != NEW.id;\n\
|
||||
END;\n\
|
||||
\n\
|
||||
-- Persistent Subscriptions Logging Tables (Phase 2)\n\
|
||||
-- Optional database logging for subscription analytics and debugging\n\
|
||||
\n\
|
||||
@@ -190,110 +217,6 @@ WHERE event_type = 'created'\n\
|
||||
AND subscription_id NOT IN (\n\
|
||||
SELECT subscription_id FROM subscription_events\n\
|
||||
WHERE event_type IN ('closed', 'expired', 'disconnected')\n\
|
||||
);\n\
|
||||
\n\
|
||||
-- ================================\n\
|
||||
-- CONFIGURATION MANAGEMENT TABLES\n\
|
||||
-- ================================\n\
|
||||
\n\
|
||||
-- Core server configuration table\n\
|
||||
CREATE TABLE config (\n\
|
||||
key TEXT PRIMARY KEY, -- Configuration key (unique identifier)\n\
|
||||
value TEXT NOT NULL, -- Configuration value (stored as string)\n\
|
||||
description TEXT, -- Human-readable description\n\
|
||||
config_type TEXT DEFAULT 'user' CHECK (config_type IN ('system', 'user', 'runtime')),\n\
|
||||
data_type TEXT DEFAULT 'string' CHECK (data_type IN ('string', 'integer', 'boolean', 'json')),\n\
|
||||
validation_rules TEXT, -- JSON validation rules (optional)\n\
|
||||
is_sensitive INTEGER DEFAULT 0, -- 1 if value should be masked in logs\n\
|
||||
requires_restart INTEGER DEFAULT 0, -- 1 if change requires server restart\n\
|
||||
created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),\n\
|
||||
updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))\n\
|
||||
);\n\
|
||||
\n\
|
||||
-- Configuration change history table\n\
|
||||
CREATE TABLE config_history (\n\
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,\n\
|
||||
config_key TEXT NOT NULL, -- Key that was changed\n\
|
||||
old_value TEXT, -- Previous value (NULL for new keys)\n\
|
||||
new_value TEXT NOT NULL, -- New value\n\
|
||||
changed_by TEXT DEFAULT 'system', -- Who made the change (system/admin/user)\n\
|
||||
change_reason TEXT, -- Optional reason for change\n\
|
||||
changed_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),\n\
|
||||
FOREIGN KEY (config_key) REFERENCES config(key)\n\
|
||||
);\n\
|
||||
\n\
|
||||
-- Configuration validation errors log\n\
|
||||
CREATE TABLE config_validation_log (\n\
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,\n\
|
||||
config_key TEXT NOT NULL,\n\
|
||||
attempted_value TEXT,\n\
|
||||
validation_error TEXT NOT NULL,\n\
|
||||
error_source TEXT DEFAULT 'validation', -- validation/parsing/constraint\n\
|
||||
attempted_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))\n\
|
||||
);\n\
|
||||
\n\
|
||||
-- Cache for file-based configuration events\n\
|
||||
CREATE TABLE config_file_cache (\n\
|
||||
file_path TEXT PRIMARY KEY, -- Full path to config file\n\
|
||||
file_hash TEXT NOT NULL, -- SHA256 hash of file content\n\
|
||||
event_id TEXT, -- Nostr event ID from file\n\
|
||||
event_pubkey TEXT, -- Admin pubkey that signed event\n\
|
||||
loaded_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),\n\
|
||||
validation_status TEXT CHECK (validation_status IN ('valid', 'invalid', 'unverified')),\n\
|
||||
validation_error TEXT -- Error details if invalid\n\
|
||||
);\n\
|
||||
\n\
|
||||
-- Performance indexes for configuration tables\n\
|
||||
CREATE INDEX idx_config_type ON config(config_type);\n\
|
||||
CREATE INDEX idx_config_updated ON config(updated_at DESC);\n\
|
||||
CREATE INDEX idx_config_history_key ON config_history(config_key);\n\
|
||||
CREATE INDEX idx_config_history_time ON config_history(changed_at DESC);\n\
|
||||
CREATE INDEX idx_config_validation_key ON config_validation_log(config_key);\n\
|
||||
CREATE INDEX idx_config_validation_time ON config_validation_log(attempted_at DESC);\n\
|
||||
\n\
|
||||
-- Trigger to update timestamp on configuration changes\n\
|
||||
CREATE TRIGGER update_config_timestamp\n\
|
||||
AFTER UPDATE ON config\n\
|
||||
BEGIN\n\
|
||||
UPDATE config SET updated_at = strftime('%s', 'now') WHERE key = NEW.key;\n\
|
||||
END;\n\
|
||||
\n\
|
||||
-- Trigger to log configuration changes to history\n\
|
||||
CREATE TRIGGER log_config_changes\n\
|
||||
AFTER UPDATE ON config\n\
|
||||
WHEN OLD.value != NEW.value\n\
|
||||
BEGIN\n\
|
||||
INSERT INTO config_history (config_key, old_value, new_value, changed_by, change_reason)\n\
|
||||
VALUES (NEW.key, OLD.value, NEW.value, 'system', 'configuration update');\n\
|
||||
END;\n\
|
||||
\n\
|
||||
-- Runtime Statistics View\n\
|
||||
CREATE VIEW runtime_stats AS\n\
|
||||
SELECT\n\
|
||||
key,\n\
|
||||
value,\n\
|
||||
description,\n\
|
||||
updated_at\n\
|
||||
FROM config\n\
|
||||
WHERE config_type = 'runtime'\n\
|
||||
ORDER BY key;\n\
|
||||
\n\
|
||||
-- Configuration Change Summary\n\
|
||||
CREATE VIEW recent_config_changes AS\n\
|
||||
SELECT\n\
|
||||
ch.config_key,\n\
|
||||
sc.description,\n\
|
||||
ch.old_value,\n\
|
||||
ch.new_value,\n\
|
||||
ch.changed_by,\n\
|
||||
ch.change_reason,\n\
|
||||
ch.changed_at\n\
|
||||
FROM config_history ch\n\
|
||||
JOIN config sc ON ch.config_key = sc.key\n\
|
||||
ORDER BY ch.changed_at DESC\n\
|
||||
LIMIT 50;\n\
|
||||
\n\
|
||||
-- Runtime Statistics (initialized by server on startup)\n\
|
||||
-- These will be populated when configuration system initializes";
|
||||
);";
|
||||
|
||||
#endif /* SQL_SCHEMA_H */
|
||||
Reference in New Issue
Block a user