init database design using neo4j
This commit is contained in:
@@ -4,4 +4,5 @@ composer.lock
|
||||
data/profile_pictures
|
||||
data/articles
|
||||
data/tmp
|
||||
data/neo4j
|
||||
import.sql
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
CREATE
|
||||
(owner:Role {name: 'Owner'}),
|
||||
(developer:Role {name: 'Developer'}),
|
||||
(user:Role {name: 'User'}),
|
||||
(essay:essay_postType {name: 'Essay'}),
|
||||
(moment:essay_postType {name: 'Moment'}),
|
||||
(thought:essay_postType {name: 'Thought'}),
|
||||
(web_dev:essay_postCategory {name: 'Web-dev'}),
|
||||
(devlog:essay_postCategory {name: 'Devlog'}),
|
||||
(published:essay_postStatus {name: 'Published'}),
|
||||
(draft:essay_postStatus {name: 'Draft'}),
|
||||
(open:SpaceType {name: 'Open'}),
|
||||
(public:SpaceType {name: 'Public'}),
|
||||
(shared:SpaceType {name: 'Shared'}),
|
||||
(private:SpaceType {name: 'Private'}),
|
||||
(open_space:Space
|
||||
{
|
||||
name: 'Open Space',
|
||||
description: 'World Wide access, no account required.',
|
||||
created_at: datetime()
|
||||
})-
|
||||
[:SPACE_TYPE]->
|
||||
(open),
|
||||
(public_space:Space
|
||||
{
|
||||
name: 'Public Space',
|
||||
description: 'Available to everyone with an account.',
|
||||
created_at: datetime()
|
||||
})-
|
||||
[:SPACE_TYPE]->
|
||||
(public),
|
||||
(shared_space:Space
|
||||
{
|
||||
name: 'Dummy Shared Space',
|
||||
description: 'Dummy shared space. Weird.',
|
||||
created_at: datetime()
|
||||
})-
|
||||
[:SPACE_TYPE]->
|
||||
(shared),
|
||||
(owner_space:Space
|
||||
{
|
||||
name: 'Owner Space',
|
||||
description: 'My space. Wait. Is that what this is?',
|
||||
created_at: datetime()
|
||||
})-
|
||||
[:SPACE_TYPE]->
|
||||
(private),
|
||||
(dummy_space:Space
|
||||
{
|
||||
name: 'Dummy Space',
|
||||
description: 'Dummy space. Weird.',
|
||||
created_at: datetime()
|
||||
})-
|
||||
[:SPACE_TYPE]->
|
||||
(private),
|
||||
(owner_user:User
|
||||
{
|
||||
username: 'joshashton',
|
||||
email: 'me@joshashton.dev',
|
||||
password_hash:
|
||||
'057ba03d6c44104863dc7361fe4578965d1887360f90a0895882e58a6248fc86',
|
||||
created_at: datetime(),
|
||||
profile_picture: '2025.jpg'
|
||||
})-
|
||||
[:USER_TYPE]->
|
||||
(owner),
|
||||
(owner_user)-[:USER_TYPE]->(developer),
|
||||
(owner_user)-[:USER_TYPE]->(user),
|
||||
(owner_user)-[:SPACE_MEMBER]->(open_space),
|
||||
(owner_user)-[:SPACE_MEMBER]->(owner_space),
|
||||
(owner_user)-[:SPACE_MEMBER]->(shared_space),
|
||||
(dummy_user:User
|
||||
{
|
||||
username: 'dummy',
|
||||
email: 'joshuatashton@gmail.com',
|
||||
password_hash:
|
||||
'057ba03d6c44104863dc7361fe4578965d1887360f90a0895882e58a6248fc86',
|
||||
created_at: datetime(),
|
||||
profile_picture: '2025.jpg'
|
||||
})-
|
||||
[:USER_TYPE]->
|
||||
(user),
|
||||
(dummy_user)-[:FOLLOWS {start_at: datetime()}]->(owner_user),
|
||||
(dummy_user)-[:SPACE_MEMBER]->(open_space),
|
||||
(dummy_user)-[:SPACE_MEMBER]->(dummy_space),
|
||||
(dummy_user)-[:SPACE_MEMBER]->(shared_space),
|
||||
(essay_post:Post
|
||||
{
|
||||
title: 'Building vintagecoding.net',
|
||||
view_count: 0,
|
||||
excerpt:
|
||||
'Follow the journey of the creation of vintagecoding.net, where I discuss roadblocks and solutions. Hello world!',
|
||||
content:
|
||||
"
|
||||
#### Overview:
|
||||
This site is built in PHP with MariaDB and a Golang HTTP server. Composer is being used to supply the following PHP packages:
|
||||
|
||||
- `vlucas/phpdotenv`
|
||||
- `erusev/parsedown`
|
||||
- `wildbit/postmark-php`
|
||||
|
||||
---
|
||||
#### 19/03/2025 - Foundations:
|
||||
Tonight, I [pushed](https://github.com/quaxlyqueen/vintagecoding.net/tree/5af0547864f730091c98d64cc18014bc69d0a041) the first major feature implementation. The database is designed, and a component has been created for article cards, and markdown parsing into HTML for the articles themselves.
|
||||
|
||||
---
|
||||
#### 20/03/2025 - Refining UX:
|
||||
Just now, I [pushed](https://github.com/quaxlyqueen/vintagecoding.net/tree/c0fc9e9d0053975837ae48fa1db93b5095d33146) the second major feature implementation. I've narrowed in on the database design with small tweaks, setup some dynamic page loading on articles.php, created a navigation bar, a dark/light mode button, and styled everything up. It's shaping up pretty well!
|
||||
|
||||
There's a lot more work to be done. The entire login system needs to be implemented, user homepages, account management, admin panels, the article composer...the list goes on.
|
||||
|
||||
---
|
||||
#### 25/03/2025 - Account Management:
|
||||
Just now, I [pushed](https://github.com/quaxlyqueen/vintagecoding.net/tree/9a45075010434a4dedd0c5d48a78ff6be3bcfddc) the third major feature implementation: account management! Not the most exciting thing ever, but it is important for the long term success of this project. With that completed, v0.0.9 is completed! Though I prematurely labeled the commit v0.1.0...But in any case there's a lot to go before release.
|
||||
|
||||
There is now a sign up and login user flow, a user page with basic settings, and authorization for accessing things like the article composer. Oh yeah, I got a basic version of that running in [this commit](https://github.com/quaxlyqueen/vintagecoding.net/tree/0a27cd1f5cd02735d06a64090a05937a5d6bcf3a) a few hours ago.
|
||||
|
||||
Two major tasks remain prior to v0.1.0. First, I still need to finish implementing the image upload on new sign ups (and for changing a profile picture), but that should be relatively minor. Second, I need to use author information to flesh out article pages.
|
||||
|
||||
I'm now setting my sights on v0.2.0, and the myriad of features I'm planning on implementing for that. It'll be the account and customization overhaul. Tools for the owner and administrator(s), enabling users to request their role to be changed to contributor or administrator, user home pages with their own custom CSS, the ability to theme the site however they please, and mobile support! I'm excited just thinking about it. It'll require a MAJOR overhaul of the CSS, but thanks to the minimalist aesthetic, the CSS file is only a few hundred disorganized lines.
|
||||
|
||||
I've put maybe 30 hours into this project so far. I'm not sure if that's good or bad, but not getting crazy with the CSS has saved a **ton** of time. And, I really like how it's looking. I'm really excited about this project and I am giddy to see how much I can get implemented by the release on 25/05/2025 -- two months! I'm starting an *unpaid* internship tomorrow, so I probably won't have the time to put 30 hours a week into this. For now, I'm just excited to see what the future holds.
|
||||
|
||||
---
|
||||
#### 01/04/2025 - Basic Security & Administration:
|
||||
Earlier today, I [pushed](https://github.com/quaxlyqueen/vintagecoding.net/tree/cec9091ee01839b133ecbbc5616463a759837dda) a major security fix along with getting CI/CD setup, and last night I [pushed](https://github.com/quaxlyqueen/vintagecoding.net/tree/b9bb620ae01134431ff1941e7577ba58eee84e42) a secure overhaul of the 'Remember Me' functionality. I didn't write about it then, but a few days ago I also [pushed](https://github.com/quaxlyqueen/vintagecoding.net/tree/ff7e799b7fd2822cf27e0afe47274de222b2b508) the image upload along with a image cropper. Still buggy as hell, but its a start. And a couple days ago I [committed](https://github.com/quaxlyqueen/vintagecoding.net/tree/e6735a9a206a207b6fab704785451a6309944ddd) admin functionality to manage users and articles. I would've thought I'd slow down, but I'm just trucking along.
|
||||
|
||||
Specifically, the 'Remember Me' functionality is now using a token system, a randomly generated 1024 bit string, associated with the user ID and hashed values of both the remote address and (if used) forwarded for headers. If these don't match what is stored in the database, this should mean that the client browser/device is not the original browser/device used to create the token.
|
||||
|
||||
For the other security fix, I converted all of the `mysqli` statements to prepared statements. This is to mitigate the risk of SQL Injection attacks. Particularly since this site is live (though I'm not promoting it so it is still 'unreleased'), it is important to ensure that despite the lack of sensitive information, would-be attackers are unable to access user information, gain admin access, or compromise the server in any way.
|
||||
|
||||
Onto the user home pages! Here's a general breakdown of what I have in mind. Every user has a homepage that they can customize the CSS for. Effectively, give the users a place to make their own. Eventually even change the layout and structure of their page. For now, the page is going to have some pretty simple information: a list of articles written by the user, the number of articles they have read, and the number their articles have been read. More is to come in the future, but that's a long way out.
|
||||
|
||||
---
|
||||
#### 08/04/2025 - Image Cropping & Editing Articles:
|
||||
Yesterday, I [pushed](https://github.com/quaxlyqueen/vintagecoding.net/tree/e5b3e048b8dc6731fa383778c26eba47186e5310) an update to the image cropper. In other words, it *actually* works now lol. I was driving home from class and I just realized that I needed to both offset the position from the window to the image, and scale the coordinates based on the size of the image. And just a moment ago, I [pushed](https://github.com/quaxlyqueen/vintagecoding.net/tree/e829e2e56695af5b77074f926c8d0c270e501f4b) editing articles. And here and there, I've worked on some basic Cross Site Scripting preventative measures, honeypots on signup to help prevent bots, and basic mobile responsiveness.
|
||||
|
||||
With some work being done with security now, I'm having second thoughts about allowing users to have custom CSS on their homepages. I'll punt that off till later.
|
||||
|
||||
All in all, things are going smoothly! I'm pretty proud of what I've built so far, and it has been quite educational. From prepared SQL statements, to XSS, form processing, and secure 'remember me' functionality. I'm not sure how much this site will be used by anyone else, and if that is the case I'll eventually just use this as a personal blog.
|
||||
|
||||
---
|
||||
#### 12/04/2025 - Enhanced Markdown Editing Experience:
|
||||
This was my first foray into the world of AJAX. I just [pushed](https://github.com/quaxlyqueen/vintagecoding.net/tree/fb35e9322647878386bcc3be572cd404b38fd91b) the implementation of a markdown preview while composing or editing articles. The possibilities are **very** exciting, I'm already thinking of other places that the AJAX would be useful for.
|
||||
|
||||
Next, I'm looking to introduce Vim motions to the site, for general navigation and also for article composition and editing. It'll be an interesting challenge I think, and I could use the JavaScript practice.
|
||||
|
||||
I haven't said this previously, but I am *loving* PHP. Such a joy to work with, and pair that with AJAX for a very interactive experience? Phenomenal DX. I've been looking at an interesting project, [NativePHP](https://nativephp.com), that I'd like to eventually use for another project.
|
||||
"
|
||||
})-
|
||||
[:STATUS]->
|
||||
(published),
|
||||
(essay_post)-[:POST_TYPE]->(essay),
|
||||
(essay_post)-[:POST_CATEGORY]->(web_dev),
|
||||
(essay_post)-[:POST_CATEGORY]->(devlog),
|
||||
(essay_post)-[:IN_SPACE]->(open_space),
|
||||
(owner_user)-[:WRITTEN {created_at: datetime(), updated_at: datetime()}]->
|
||||
(essay_post),
|
||||
(moment_post:Post
|
||||
{
|
||||
media_filepath: 'moments/open.png',
|
||||
text_content:
|
||||
'A hub for everything. A social network and messaging hub. A documentation hub. A photos and video hub. A note taking and task management hub. A private hub. An AI hub. Welcome to the.hub.'
|
||||
})-
|
||||
[:STATUS]->
|
||||
(published),
|
||||
(moment_post)-[:POST_TYPE]->(moment),
|
||||
(moment_post)-[:POST_CATEGORY]->(devlog),
|
||||
(moment_post)-[:IN_SPACE]->(shared_space),
|
||||
(moment_post_2:Post
|
||||
{
|
||||
media_filepath: 'moments/test.png',
|
||||
text_content:
|
||||
'Here is a photo from a hike I went on a while back. Nothing quite beats the look over a long trail.'
|
||||
})-
|
||||
[:STATUS]->
|
||||
(published),
|
||||
(moment_post_2)-[:POST_TYPE]->(moment),
|
||||
(moment_post_2)-[:POST_CATEGORY]->(devlog),
|
||||
(moment_post_2)-[:IN_SPACE]->(shared_space),
|
||||
(owner_user)-[:WRITTEN {created_at: datetime(), updated_at: datetime()}]->
|
||||
(moment_post_2),
|
||||
(thought_post:Post
|
||||
{
|
||||
content:
|
||||
'I wonder if this is really smart or really dumb. Guess we will see...'
|
||||
})-
|
||||
[:STATUS]->
|
||||
(published),
|
||||
(thought_post)-[:POST_TYPE]->(thought),
|
||||
(thought_post)-[:POST_CATEGORY]->(devlog),
|
||||
(thought_post)-[:IN_SPACE]->(owner_space),
|
||||
(owner_user)-[:WRITTEN {created_at: datetime(), updated_at: datetime()}]->
|
||||
(thought_post),
|
||||
(thought_post_2:Post
|
||||
{content: 'I wonder if it was a bad idea to share my idea with Izzi.'})-
|
||||
[:STATUS]->
|
||||
(draft),
|
||||
(thought_post_2)-[:POST_TYPE]->(thought),
|
||||
(thought_post_2)-[:POST_CATEGORY]->(devlog),
|
||||
(thought_post_2)-[:IN_SPACE]->(owner_space),
|
||||
(owner_user)-[:WRITTEN {created_at: datetime(), updated_at: datetime()}]->
|
||||
(thought_post_2),
|
||||
(thought_post_3:Post {content: 'Hello cruel world!'})-[:STATUS]->(published),
|
||||
(thought_post_3)-[:POST_TYPE]->(thought),
|
||||
(thought_post_3)-[:POST_CATEGORY]->(devlog),
|
||||
(thought_post_3)-[:IN_SPACE]->(public_space),
|
||||
(owner_user)-[:WRITTEN {created_at: datetime(), updated_at: datetime()}]->
|
||||
(thought_post_3);
|
||||
+72
-27
@@ -6,10 +6,8 @@ CREATE TABLE roles (
|
||||
role VARCHAR(16) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE tags (
|
||||
tag_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
tag VARCHAR(16) NOT NULL
|
||||
);
|
||||
INSERT INTO roles (role)
|
||||
VALUES ('owner'), ('developer'), ('user');
|
||||
|
||||
CREATE TABLE user (
|
||||
user_id INT PRIMARY KEY,
|
||||
@@ -22,25 +20,34 @@ CREATE TABLE user (
|
||||
is_active BOOLEAN DEFAULT FALSE,
|
||||
profile_picture VARCHAR(256),
|
||||
bio VARCHAR(256),
|
||||
x_username VARCHAR(32),
|
||||
fb_username VARCHAR(32),
|
||||
ig_username VARCHAR(32),
|
||||
website VARCHAR(64),
|
||||
FOREIGN KEY (role_id) REFERENCES roles (role_id)
|
||||
FOREIGN KEY (role_id) REFERENCES roles (role_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
INSERT INTO user (user_id, username, email, password_hash, role_id, profile_picture)
|
||||
VALUES (1, 'quaxlyqueen', 'me@joshashton.dev', '057ba03d6c44104863dc7361fe4578965d1887360f90a0895882e58a6248fc86', 1, '2025.jpg');
|
||||
|
||||
CREATE TABLE remember_user (
|
||||
token VARCHAR(128) PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
remote_addr VARCHAR(64) NOT NULL,
|
||||
http_forward VARCHAR(64),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES user (user_id)
|
||||
FOREIGN KEY (user_id) REFERENCES user (user_id) ON DELETE CASCADE
|
||||
); -- TODO: Need cron job to auto-delete after 30 days of inactivity
|
||||
|
||||
CREATE TABLE post_types (
|
||||
post_type_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
post_type VARCHAR(16)
|
||||
);
|
||||
|
||||
CREATE TABLE article (
|
||||
article_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
INSERT INTO post_types (post_type)
|
||||
VALUES ('article'), ('moment'), ('thought');
|
||||
|
||||
CREATE TABLE post (
|
||||
post_id INT PRIMARY KEY,
|
||||
author_id INT NOT NULL,
|
||||
post_type INT NOT NULL,
|
||||
title VARCHAR(26) NOT NULL,
|
||||
slug VARCHAR(32),
|
||||
read_count INT DEFAULT 0,
|
||||
@@ -49,17 +56,31 @@ CREATE TABLE article (
|
||||
published_at TIMESTAMP DEFAULT NULL,
|
||||
published BOOLEAN DEFAULT TRUE,
|
||||
excerpt VARCHAR(256),
|
||||
FOREIGN KEY (author_id) REFERENCES user(user_id)
|
||||
FOREIGN KEY (author_id) REFERENCES user(user_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (post_type) REFERENCES post_types(post_type_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 article(article_id),
|
||||
FOREIGN KEY (tag_id) REFERENCES tags(tag_id)
|
||||
INSERT INTO post (author_id, post_type, title, excerpt, published_at)
|
||||
VALUES (1, 1, 'Building vintagecoding.net', 'A devlog of the creation of vintagecoding.net and a test at the formatting of post cards and posts. Let the great experiment begin!', CURRENT_TIMESTAMP);
|
||||
|
||||
CREATE TABLE categories (
|
||||
category_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
category VARCHAR(16) NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO categories (category)
|
||||
VALUES ('web-dev'), ('devlog');
|
||||
|
||||
CREATE TABLE post_categories (
|
||||
post_id INT NOT NULL,
|
||||
category_id INT NOT NULL,
|
||||
PRIMARY KEY (post_id, category_id),
|
||||
FOREIGN KEY (post_id) REFERENCES post(post_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (category_id) REFERENCES categories(category_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
INSERT INTO post_tags (post_id, tag_id) VALUES (1, 1), (1, 2);
|
||||
|
||||
CREATE TABLE follows (
|
||||
follower_user_id INT NOT NULL,
|
||||
following_user_id INT NOT NULL,
|
||||
@@ -70,16 +91,40 @@ CREATE TABLE follows (
|
||||
FOREIGN KEY (following_user_id) REFERENCES user(user_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
INSERT INTO roles (role)
|
||||
VALUES ('owner'), ('admin'), ('contributor'), ('reader');
|
||||
CREATE TABLE space_types (
|
||||
space_type_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
space_type VARCHAR(16)
|
||||
);
|
||||
|
||||
INSERT INTO tags (tag)
|
||||
VALUES ('linux'), ('web-dev'), ('raspberry-pi'), ('self-hosting'), ('devlog'), ('testing');
|
||||
INSERT INTO space_types (space_type)
|
||||
VALUES ('open', 'public', 'shared', 'private');
|
||||
|
||||
INSERT INTO user (user_id, username, email, password_hash, role_id, profile_picture)
|
||||
VALUES (2025, 'quaxlyqueen', 'me@joshashton.dev', '057ba03d6c44104863dc7361fe4578965d1887360f90a0895882e58a6248fc86', 1, '2025.jpg');
|
||||
CREATE TABLE spaces (
|
||||
space_id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
space_type INT NOT NULL,
|
||||
name VARCHAR(64) NOT NULL,
|
||||
slug VARCHAR(64) UNIQUE,
|
||||
description TEXT,
|
||||
parent_space_id INT DEFAULT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (parent_space_id) REFERENCES spaces(space_id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (space_type) REFERENCES space_types(space_type_id)
|
||||
);
|
||||
|
||||
INSERT INTO article (author_id, title, excerpt, published_at)
|
||||
VALUES (2025, 'Building vintagecoding.net', 'A devlog of the creation of vintagecoding.net and a test at the formatting of article cards and articles. Let the great experiment begin!', CURRENT_TIMESTAMP);
|
||||
CREATE TABLE space_posts (
|
||||
post_id INT NOT NULL,
|
||||
space_id INT NOT NULL,
|
||||
PRIMARY KEY (post_id, space_id),
|
||||
FOREIGN KEY (post_id) REFERENCES post(post_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (space_id) REFERENCES spaces(space_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
INSERT INTO article_tags (article_id, tag_id) VALUES (1, 2), (1, 4), (1, 5);
|
||||
CREATE TABLE space_members (
|
||||
space_id INT NOT NULL,
|
||||
user_id INT NOT NULL,
|
||||
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (space_id, user_id),
|
||||
FOREIGN KEY (space_id) REFERENCES spaces(space_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES user(user_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user