Added pretty much everything except discussion forums
This commit is contained in:
53
api/migrations/20260222232949-discussion-posts.js
Normal file
53
api/migrations/20260222232949-discussion-posts.js
Normal file
@@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
var dbm;
|
||||
var type;
|
||||
var seed;
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var Promise;
|
||||
|
||||
/**
|
||||
* We receive the dbmigrate dependency from dbmigrate initially.
|
||||
* This enables us to not have to rely on NODE_PATH.
|
||||
*/
|
||||
exports.setup = function(options, seedLink) {
|
||||
dbm = options.dbmigrate;
|
||||
type = dbm.dataType;
|
||||
seed = seedLink;
|
||||
Promise = options.Promise;
|
||||
};
|
||||
|
||||
exports.up = function(db) {
|
||||
var filePath = path.join(__dirname, 'sqls', '20260222232949-discussion-posts-up.sql');
|
||||
return new Promise( function( resolve, reject ) {
|
||||
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
|
||||
if (err) return reject(err);
|
||||
console.log('received data: ' + data);
|
||||
|
||||
resolve(data);
|
||||
});
|
||||
})
|
||||
.then(function(data) {
|
||||
return db.runSql(data);
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function(db) {
|
||||
var filePath = path.join(__dirname, 'sqls', '20260222232949-discussion-posts-down.sql');
|
||||
return new Promise( function( resolve, reject ) {
|
||||
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
|
||||
if (err) return reject(err);
|
||||
console.log('received data: ' + data);
|
||||
|
||||
resolve(data);
|
||||
});
|
||||
})
|
||||
.then(function(data) {
|
||||
return db.runSql(data);
|
||||
});
|
||||
};
|
||||
|
||||
exports._meta = {
|
||||
"version": 1
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
/* Replace with your SQL commands */
|
||||
DROP TABLE discussion_posts;
|
||||
DROP TABLE discussion_comments;
|
||||
34
api/migrations/sqls/20260222232949-discussion-posts-up.sql
Normal file
34
api/migrations/sqls/20260222232949-discussion-posts-up.sql
Normal file
@@ -0,0 +1,34 @@
|
||||
/* Replace with your SQL commands */
|
||||
CREATE TABLE discussion_posts (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
type VARCHAR(50) NOT NULL,
|
||||
poster_id INT NOT NULL,
|
||||
title VARCHAR(100) NOT NULL,
|
||||
content JSON NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
is_deleted BOOLEAN DEFAULT FALSE,
|
||||
is_locked BOOLEAN DEFAULT FALSE,
|
||||
is_open BOOLEAN GENERATED ALWAYS AS (
|
||||
NOT is_deleted
|
||||
AND NOT is_locked
|
||||
) STORED,
|
||||
FOREIGN KEY (poster_id) REFERENCES members(id) ON DELETE CASCADE
|
||||
);
|
||||
CREATE TABLE discussion_comments (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
post_id INT NOT NULL,
|
||||
poster_id INT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
is_deleted BOOLEAN DEFAULT FALSE,
|
||||
FOREIGN KEY (post_id) REFERENCES discussion_posts(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (poster_id) REFERENCES members(id) ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX idx_discussion_posts_title ON discussion_posts(title);
|
||||
CREATE INDEX idx_discussion_posts_type ON discussion_posts(type);
|
||||
CREATE INDEX idx_discussion_posts_poster_id ON discussion_posts(poster_id);
|
||||
CREATE INDEX idx_discussion_comments_post_id ON discussion_comments(post_id);
|
||||
CREATE INDEX idx_discussion_comments_poster_id ON discussion_comments(poster_id);
|
||||
CREATE INDEX idx_discussion_posts_is_open ON discussion_posts(is_open);
|
||||
Reference in New Issue
Block a user