e949/docs/DB.md

38 lines
1.3 KiB
Markdown

# 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.
```bash
mysql -u root -p
```
```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
```
```bash
mysql -u e949 -p
```
```mysql
USE e949;
CREATE TABLE posts (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique identifier of post',
author_id BIGINT UNSIGNED NOT NULL COMMENT 'Identifier of post author',
comment_section_id BIGINT UNSIGNED NULL COMMENT 'Identifier of post comment section',
posted_at TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'When post was published',
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',
views BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Amount of post views',
pic_path VARCHAR(256) NOT NULL COMMENT 'Path or URL of picture',
preview_path VARCHAR(256) NULL COMMENT 'Path or URL of preview version of picture'
);
```