implemented database, article cards, and parsing from markdown.

This commit is contained in:
Joshua Ashton
2025-03-19 23:27:20 -06:00
parent 3b794ae87d
commit 5af0547864
16 changed files with 426 additions and 20 deletions
+54
View File
@@ -0,0 +1,54 @@
CREATE DATABASE vintagecoding;
USE vintagecoding;
CREATE TABLE roles (
role_id INT PRIMARY KEY AUTO_INCREMENT,
role VARCHAR(16) NOT NULL
);
INSERT INTO roles (role)
VALUES ('owner'), ('admin'), ('contributor'), ('reader');
CREATE TABLE tags (
tag_id INT PRIMARY KEY AUTO_INCREMENT,
tag VARCHAR(16) NOT NULL
);
INSERT INTO tags (tag)
VALUES ('linux'), ('web-dev'), ('raspberry-pi'), ('self-hosting');
CREATE TABLE user (
user_id INT PRIMARY KEY,
username VARCHAR(32) NOT NULL UNIQUE,
email VARCHAR(64) NOT NULL UNIQUE,
password_hash VARCHAR(256) NOT NULL,
last_active TIMESTAMP DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
role_id INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
is_active BOOLEAN DEFAULT FALSE,
profile_picture VARCHAR(256),
FOREIGN KEY (role_id) REFERENCES roles (role_id)
);
CREATE TABLE articles (
article_id INT PRIMARY KEY AUTO_INCREMENT,
author_id INT NOT NULL,
markdown_file_path VARCHAR(256) NOT NULL UNIQUE,
title VARCHAR(64) NOT NULL,
slug VARCHAR(32),
read_count INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
published_at TIMESTAMP DEFAULT NULL,
published BOOLEAN DEFAULT FALSE,
excerpt VARCHAR(256),
FOREIGN KEY (author_id) REFERENCES user(user_id)
);
CREATE TABLE article_tags (
article_id INT NOT NULL,
tag_id INT NOT NULL,
PRIMARY KEY (article_id, tag_id),
FOREIGN KEY (article_id) REFERENCES articles(article_id),
FOREIGN KEY (tag_id) REFERENCES tags(tag_id)
);
+54
View File
@@ -0,0 +1,54 @@
ARGS_COUNT=$#
help () {
echo "CLI Tool used to initialize the database for vintagecoding.net."
echo "With no arguments, it creates the application user in MariaDB,"
echo "and creates the following tables:"
echo "- roles (populated);"
echo "- tags (populated);"
echo "- user;"
echo "- articles;"
echo "- article_tags;"
echo ""
echo "The following flags are accepted:"
echo " init_db.sh { --help | -h }"
echo " init_db.sh { --delete | -d } { --verbose | -v }"
}
if [[ $ARGS_COUNT > 0 ]]; then
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
help
exit
fi
# Delete the existing database and start over.
if [[ "$1" == "--delete" || "$1" == "-d" ]]; then
if [[ "$2" == "--verbose" || "$2" == "-v" ]]; then
echo "Deleting the existing database vintagecoding..."
fi
echo "vintage user pw"
mariadb -u vintage -p -e "DROP DATABASE vintagecoding;"
if [[ "$2" == "--verbose" || "$2" == "-v" ]]; then
echo "Deleting the vintage user..."
fi
echo "root user pw"
mariadb -u root -p -e "DROP USER vintage@localhost;"
if [[ "$2" == "--verbose" || "$2" == "-v" ]]; then
echo "Creating the vintage user..."
fi
echo "root user pw"
mariadb -u root -p < setup.sql;
if [[ "$2" == "--verbose" || "$2" == "-v" ]]; then
echo "Creating (and populating enum/static data) tables..."
fi
echo "vintage user pw"
mariadb -u vintage -p < init.sql;
exit
fi
fi
#mariadb -u root -p < setup.sql;
mariadb -u vintage -p < init.sql;
+3
View File
@@ -0,0 +1,3 @@
--This must be ran as the root user in MariaDB
CREATE USER vintage@localhost IDENTIFIED BY 'changeme';
GRANT ALL PRIVILEGES ON vintagecoding.* TO vintage@localhost IDENTIFIED BY 'changeme';