chore: initial database schema
This commit is contained in:
parent
1355fb09c6
commit
17b4d8aaa5
@ -1,13 +1,3 @@
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
key TEXT PRIMARY KEY,
|
||||
value TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS roles (
|
||||
name TEXT PRIMARY KEY NOT NULL,
|
||||
description TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
email TEXT PRIMARY KEY,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
@ -19,25 +9,29 @@ CREATE TABLE IF NOT EXISTS users (
|
||||
avatar_url TEXT,
|
||||
bio TEXT,
|
||||
id_document_url TEXT,
|
||||
id_verification_status TEXT DEFAULT 'pending',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (role) REFERENCES roles(name) ON UPDATE CASCADE ON DELETE SET DEFAULT
|
||||
id_verification_status TEXT DEFAULT 'pending' CHECK(id_verification_status IN ('pending', 'verified', 'rejected')),
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
key TEXT PRIMARY KEY,
|
||||
value TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS posts (
|
||||
id TEXT PRIMARY KEY,
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_email TEXT NOT NULL,
|
||||
media_url TEXT NOT NULL,
|
||||
media_type TEXT NOT NULL,
|
||||
media_type TEXT NOT NULL CHECK(media_type IN ('image', 'video')),
|
||||
caption TEXT,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_email) REFERENCES users(email) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS likes (
|
||||
id TEXT PRIMARY KEY,
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_email TEXT NOT NULL,
|
||||
post_id TEXT NOT NULL,
|
||||
post_id INTEGER NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_email) REFERENCES users(email) ON DELETE CASCADE,
|
||||
FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE,
|
||||
@ -45,31 +39,24 @@ CREATE TABLE IF NOT EXISTS likes (
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS comments (
|
||||
id TEXT PRIMARY KEY,
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_email TEXT NOT NULL,
|
||||
post_id TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
post_id INTEGER NOT NULL,
|
||||
text TEXT NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_email) REFERENCES users(email) ON DELETE CASCADE,
|
||||
FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_users_username ON users(username);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_role ON users(role);
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_user_email ON posts(user_email);
|
||||
CREATE INDEX IF NOT EXISTS idx_likes_user_email ON likes(user_email);
|
||||
CREATE INDEX IF NOT EXISTS idx_likes_post_id ON likes(post_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_comments_user_email ON comments(user_email);
|
||||
CREATE INDEX IF NOT EXISTS idx_comments_post_id ON comments(post_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_comments_user_email ON comments(user_email);
|
||||
|
||||
INSERT OR IGNORE INTO settings (key, value) VALUES
|
||||
('site_name', 'Social Media App'),
|
||||
('site_description', 'A vibrant community social media platform.'),
|
||||
('maintenance_mode', 'false'),
|
||||
('allow_registration', 'true');
|
||||
|
||||
INSERT OR IGNORE INTO roles (name, description) VALUES
|
||||
('visitor', 'Read-only access to public content.'),
|
||||
('member', 'Standard user with posting and interaction rights.'),
|
||||
('moderator', 'Can manage content and users.'),
|
||||
('admin', 'Full administrative access to the application.');
|
||||
INSERT INTO settings (key, value) VALUES
|
||||
('site_name', 'Cloudflare Social'),
|
||||
('site_description', 'A social media platform powered by Cloudflare D1.'),
|
||||
('allow_registration', 'true'),
|
||||
('default_role', 'visitor'),
|
||||
('valid_roles', '["visitor", "admin", "moderator"]');
|
||||
Loading…
Reference in New Issue
Block a user