2023-08-05 08:56:09 +05:30
|
|
|
# Databases
|
|
|
|
|
|
|
|
## How to setup DB
|
|
|
|
|
|
|
|
We are using MariaDB, but any MySQL-compatible database should be enough. There are instructions how to setup it for using with E949.
|
|
|
|
|
2023-12-20 08:38:13 +05:30
|
|
|
1. Login to your SQL database with admin account:
|
|
|
|
|
2023-08-05 08:56:09 +05:30
|
|
|
```bash
|
|
|
|
mysql -u root -p
|
|
|
|
```
|
|
|
|
|
2023-12-20 08:38:13 +05:30
|
|
|
2. Setup new user and database:
|
|
|
|
|
2023-08-05 08:56:09 +05:30
|
|
|
```mysql
|
|
|
|
CREATE USER e949@localhost IDENTIFIED BY 'password';
|
|
|
|
CREATE DATABASE e949 CHARACTER SET = 'utf8';
|
|
|
|
GRANT ALL PRIVILEGES ON e949.* TO e949@localhost;
|
|
|
|
FLUSH PRIVILEGES;
|
|
|
|
EXIT
|
|
|
|
```
|
|
|
|
|
2023-12-20 08:38:13 +05:30
|
|
|
3. Login with new account:
|
|
|
|
|
2023-08-05 08:56:09 +05:30
|
|
|
```bash
|
|
|
|
mysql -u e949 -p
|
|
|
|
```
|
|
|
|
|
2023-12-20 08:38:13 +05:30
|
|
|
4. Create tables:
|
|
|
|
|
2023-08-05 08:56:09 +05:30
|
|
|
```mysql
|
|
|
|
USE e949;
|
2023-08-06 05:43:17 +05:30
|
|
|
CREATE TABLE users (
|
|
|
|
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique identifier of user',
|
2023-08-12 04:09:17 +05:30
|
|
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'When account was created',
|
2024-01-27 04:13:27 +05:30
|
|
|
login VARCHAR(255) NOT NULL UNIQUE COMMENT 'User login',
|
|
|
|
email VARCHAR(255) NULL UNIQUE COMMENT 'User e-mail address',
|
2023-08-06 05:43:17 +05:30
|
|
|
password_hash BINARY(32) NOT NULL COMMENT 'User password hash',
|
|
|
|
salt VARCHAR(8) NOT NULL COMMENT 'User salt, used for password hash',
|
|
|
|
avatar_path VARCHAR(255) NULL COMMENT 'Path or URL to avatar picture',
|
|
|
|
role ENUM('newbie', 'verified', 'mod', 'admin') NOT NULL COMMENT 'Assigned role',
|
|
|
|
banned BOOL NOT NULL DEFAULT FALSE COMMENT 'If user is banned',
|
|
|
|
invite_id CHAR(32) NULL COMMENT 'Invite ID used for account registration'
|
|
|
|
);
|
2023-08-05 08:56:09 +05:30
|
|
|
CREATE TABLE posts (
|
2023-08-06 05:43:17 +05:30
|
|
|
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique identifier of post',
|
|
|
|
author_id INT UNSIGNED NOT NULL COMMENT 'Identifier of post author',
|
|
|
|
comment_section_id INT UNSIGNED NULL COMMENT 'Identifier of post comment section',
|
2023-08-12 04:09:17 +05:30
|
|
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'When post was published',
|
2023-08-05 08:56:09 +05:30
|
|
|
tags VARCHAR(2048) NOT NULL COMMENT 'Comma-delimited list of post tags',
|
|
|
|
title VARCHAR(8192) NULL COMMENT 'Caption for the post',
|
|
|
|
votes_up INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Amount of positive reactions',
|
|
|
|
votes_down INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Amount of negative reactions',
|
2023-08-06 05:43:17 +05:30
|
|
|
views INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Amount of post views',
|
|
|
|
pic_path VARCHAR(255) NOT NULL COMMENT 'Path or URL of picture',
|
2023-08-12 04:09:17 +05:30
|
|
|
preview_path VARCHAR(255) NULL COMMENT 'Path or URL of preview version of picture',
|
2023-08-06 05:43:17 +05:30
|
|
|
comments_enabled BOOL NOT NULL COMMENT 'If comments are enabled',
|
|
|
|
edit_lock BOOL NOT NULL DEFAULT FALSE COMMENT 'If redaction of post is locked for anyone, except mods and admins'
|
|
|
|
);
|
|
|
|
CREATE TABLE comments (
|
|
|
|
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique identifier of comment',
|
|
|
|
author_id INT UNSIGNED NOT NULL COMMENT 'Identifier of comment author',
|
|
|
|
comment_section_id INT UNSIGNED NOT NULL COMMENT 'Identifier of comment section to which the comment belongs',
|
2023-08-12 04:09:17 +05:30
|
|
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'When comment was published',
|
2023-08-06 05:43:17 +05:30
|
|
|
contents VARCHAR(8192) NOT NULL COMMENT 'Text of comment',
|
|
|
|
needs_check BOOL NOT NULL DEFAULT FALSE COMMENT 'If comment needs approval of moderation'
|
|
|
|
);
|
|
|
|
CREATE TABLE actions (
|
|
|
|
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique identifier of action',
|
|
|
|
author_id INT UNSIGNED NULL COMMENT 'ID of user, who performed action',
|
2023-08-12 04:09:17 +05:30
|
|
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'When action was performed',
|
2023-08-06 05:43:17 +05:30
|
|
|
category ENUM('acc_mod', 'publ_mod', 'post', 'comment', 'admin', 'other') NOT NULL COMMENT 'Category of performed action: accounts/publications moderation, etc.',
|
|
|
|
description VARCHAR(8192) NOT NULL COMMENT 'Description of action'
|
|
|
|
);
|
|
|
|
CREATE TABLE invites (
|
|
|
|
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique identifier of invite',
|
|
|
|
author_id INT UNSIGNED NULL COMMENT 'ID of user, who created invite',
|
|
|
|
uses_last SMALLINT UNSIGNED NOT NULL COMMENT 'Remaining uses of invite'
|
|
|
|
);
|
2023-09-06 08:08:18 +05:30
|
|
|
CREATE TABLE approved_tags (
|
2024-01-27 04:13:27 +05:30
|
|
|
value VARCHAR(255) NOT NULL UNIQUE COMMENT 'The tag itself',
|
|
|
|
author_id INT UNSIGNED NULL COMMENT 'ID of user who added this tag to list of approved',
|
|
|
|
added_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'When this tag was added'
|
2023-09-06 08:08:18 +05:30
|
|
|
);
|
2023-12-20 08:38:13 +05:30
|
|
|
```
|
|
|
|
|
|
|
|
5. Profit!!!
|