Skip to content

Instantly share code, notes, and snippets.

@zenithtekla
Last active February 2, 2018 17:24
Show Gist options
  • Save zenithtekla/819ddc7766761e2908b8487aa9c3cd9f to your computer and use it in GitHub Desktop.
Save zenithtekla/819ddc7766761e2908b8487aa9c3cd9f to your computer and use it in GitHub Desktop.
ECMS
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
/**
* Schema
*/
var Schema1 = new Schema({
asset_number: String,
last_cal: Date,
schedule: Number,
next_cal: Date,
files: [{
data: Buffer,
contentType: String
}],
model: String,
location: {
id: Number,
desc: String
}
});
mongoose.model('Equipment', Schema1);
/*
I don't know the data and couldn't remember after days and couldn't derive the right relationship for the tables.
Days of burying our heads into the sand writing JOIN are passed as the logic later requires testing, fixing and re-validation.
I need to derive the right relationship to tie my Sequelize data models.
So, I went ahead and combined the 3 tables into the mongo Schema in 2 assumptive cases below. Software development deals a lot with assumptions
when I don't usually see real data fly into the tables. I need nothing else than a concatenated schema object.
*/
DELIMITER //
CREATE PROCEDURE new_student_with_class_and_lession(
firstName CHAR(25), lastName CHAR(25),
className1 CHAR(25), period1 CHAR(25),
className2 CHAR(25), period2 CHAR(25),
lessionName1 CHAR(25), lessionName2 CHAR(25))
BEGIN
START TRANSACTION;
INSERT INTO student_table (firstname, lastname)
VALUES(firstName, lastName);
SET lastStudentId = (SELECT LAST_INSERT_ID());
INSERT INTO class_table (className1, period1, studentId)
VALUES(className1, period, lastStudentId);
SET lastStudentId = (SELECT LAST_INSERT_ID());
INSERT INTO class_table (className2, period2, studentId)
VALUES(className2, period, lastStudentId);
INSERT INTO lession_table (lessionName1, classId)
VALUES(lessionName1, LAST_INSERT_ID());
INSERT INTO lession_table (lessionName2, classId)
VALUES(lessionName2, LAST_INSERT_ID());
COMMIT;
END//
DELIMITER ;
SELECT
lt.lessionName as LESSION
FROM lession_table lt
LEFT JOIN class_table ct
ON ct.classId = lt.classId
LEFT JOIN student_table st
ON st.studentId = ct.studentId
WHERE st.studentId = 1
ORDER BY lt.id;
SELECT lt.lessionName as LESSION
FROM student_table as st
LEFT JOIN class_table as ct
ON st.studentId = ct.studentId
LEFT JOIN lession_table as lt
ON lt.classId = ct.classId
WHERE st.studentId = 1;
@zetekla
Copy link

zetekla commented Jan 11, 2018

let RMIT_data = {
  "Projects": [
    {
      "_id": "ID stringHash", // stands for projectId when referencing
      "name": "Project Name X",
      "icon": "icon for the project",
      "description": "desc of a Proj",
      "manager": {
        "userId": "string", // userId, as the user types, typeahead suggests all the user, their name and email
        "name": "string",
        "email": "string", // email is necessary for user to ensure the right person, because name does not ensure uniqueness,
        "badgeId": "string", // same purpose as to give visual cue and maintain uniqueness.
        "role": "manager"
      },
      "techLead": {
        "userId": "string", // userId, as the user types, typeahead suggests all the user, their name and email
        "name": "string",
        "email": "string", // email is necessary for user to ensure the right person, because name does not ensure uniqueness,
        "badgeId": "string", // same purpose as to give visual cue and maintain uniqueness.
        "role": "techLead"
      },
      "members": [
        {
          "_id": "ID stringHash",
          "userId": "hash",
          "name": "string",
          "email": "string", // email is necessary for user to ensure the right person, because name does not ensure uniqueness,
          "badgeId": "string", // same purpose as to give visual cue and maintain uniqueness.
          "role": "member"
        }
      ],
      "createdAt": "DateTime datatype",
      "updatedAt": "DateTime datatype",
      "versions": [
        {
          "_id": "ID stringHash", // stands for versionId when referencing
          "name": "version 1.0.0",
          "desc": "desc of a version",
          "tasks": [
            {},
            {}
          ],
          "tickets": [
            {
              "_id": "ID stringHash", // stands for ticketId when referencing
              "desc": "desc of a Task",
              "type": "story ticket | ui enhancement | backend crunch | backlog",
              "storyPoint": 3, // default to 3 if not set.
              "createdAt": "DateTime",
              "updatedAt": "DateTime",
              "estimate": "DateTime of EOF- estimation of delivery",
              "resolvedAt": "DateTime",
              "assignee": "the person to take care of a task",
              "reporter": "the person who reported this ticket| provided this task",
              "watchers": [],
              "validator": "UAT person | UAT resource",
              "tester": "QA resource",
              "display": " show | hide ",
              "affectVersions": [],
              "fixVersions": [],
              "labels": [],
              "note": "",
              "sprint": "",
              "priorityLevel": "P0|P1|P2",
              "attachments": [],
              "branches": [],
              "PRs": [],
              "testScripts": "reproduce an issue with the following steps",
              "status": "pending approval | awaiting requirements | unassigned | assigned | in-progress | qa-ready | uat-ready | done | archive | reopened",
              "comments": [
                {
                  "_id": "ID stringHash",
                  "author": "",
                  "taggers": [
                    "userX_ID",
                    "userY_ID"
                  ],
                  "linkedTasks": [
                    {
                      "_id": "ID stringHash",
                      "taskId": "id of an associated task",
                      "type": "child of | parent of | related to | clone of | sub-task of "
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "Users": [
    {
      "_id": "ID stringHash", // stands for userId
      "badgeId": "the actual badgeId for use system-wide, entrance access, vpn verification, etc.",
      "account": "login nick",
      "password": "hash",
      "name": "short name | nickname",
      "firstName": "actual firstName",
      "lastName": "actual lastName",
      "DOB": "",
      "email": "",
      "phone": "",
      "title": "Dr.|Mr.|Ms...",
      "workTitle": "company title: CTO | CFO | Product owner | ",
      "professional": "developer|qa|scrum master...as if working for other company at the same time/ or main career profession",
      "age": "",
      "gender": "",
      "preferences": {},
      "projects": [
        {
          "projectId": 1,
          "role": "manager | member | techLead | productOwner | viewer" // viewer is like a guest with lowest privelege; privelege goes by manager > productOwner > techLead > member > viewer; the developers are the member of a project.
        }
      ],
      "status": "pending | locked | onSiteActive | remoteActive",
      "employmentType": " salary | contract | commission | equity",
      "avatar": "icon",
      "createdAt": "DateTime when user was created",
      "updatedAt": "DateTime when user info was last updated",
      "lastSeen": "DateTime",
      "lastActivities": [],
      "online": "number of hours online",
      "vpnKey": "key for authorized access",
      "gits": [
        "git account"
      ],
      "bitbucket": [
        "bitbucket profile"
      ],
      "portfolio": [
        "portfolio link"
      ],
      "profile": "Link to a profile page",
      "about": "",
      "bio": ""
    }
  ]
}

@zetekla
Copy link

zetekla commented Feb 1, 2018

Catalogs > Subjects > Bookmarks

id: {
catalogId: string,
userId: string
}

CatalogDocument {
_id: string,
userId: string,
editors: Array,
viewers: Array,
title: string,
name: string,
description: string,
createdAt: Date,
updatedAt: Date,
keywords: string, // some keywords
tags: string, // some tags
subjects: [ISubject]
}

id: {
subjectId: string,
userId: string
}

SubjectDocument {
_id: string,
userId: string,
editors: Array,
viewers: Array,
title: string,
name: string,
description: string,
createdAt: Date,
updatedAt: Date,
keywords: string, // some keywords
tags: string, // some tags
bookmarks: [IBookmark]
}

id: {
bookmarkId: string,
userId: string
}

BookmarkDocument {
_id: string,
userId: string,
editors: Array,
viewers: Array,
title: string,
name: string,
origin: string,
url: string,
description: string,
author: string,
status: string, // live-very-fast | live-fast | live-slow | live-very-slow | dead
note: string,
createdAt: Date,
updatedAt: Date,
keywords: string, // some keywords
tags: string, // some tags
}

editors is a collection of editorDocument {
_id: string, // userId, as the user types, typeahead suggests all the user, their name and email
name: string,
email: string // email is necessary for user to ensure the right person, because name does not ensure uniqueness,
badgeId: string // same purpose as to give visual cue and maintain uniqueness.
}

visitors is a collection of editorDocument {
_id: string, // userId, as the user types, typeahead suggests all the user, their name and email
name: string,
email: string // email is necessary for user to ensure the right person, because name does not ensure uniqueness,
badgeId: string // same purpose as to give visual cue and maintain uniqueness.
}

user should be able to view all records of Catalogs, Subjects and Bookmarks
CatalogUI should display all catalogs; (later) and a sneak peak of subjects
SubjectUI should display all subjects; (later) and a sneak peak of bookmarks
BookmarkUI should display all subjects; (later) and a sneak peak of bookmarks
user should be able to add/update/delete a record of BookmarkDocument

https://stackoverflow.com/questions/26497455/mongodb-recommended-tree-structure-for-large-amount-of-data-points

NoSQL Database: The Definitive Guide to NoSQL Databases

I would encourage you to be open-minded in using the variable in your objectID, as an object instead of just string. When I discovered this cool “trick” when playing with JSON when I tree my data as pieces of html codes but grouped by ObjectId, as variable. I.e. instead of using value: ‘foo’ in Petr’s answer, use this value: { foo }.
src:
https://www.quora.com/What-is-the-most-efficient-way-to-store-a-tree-data-structure-in-MongoDB

https://www.sisense.com/blog/postgres-vs-mongodb-for-storing-json-data/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment