Skip to content

Instantly share code, notes, and snippets.

@yojimbo87
Forked from jcolebrand/Message.json
Created August 26, 2011 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yojimbo87/1174296 to your computer and use it in GitHub Desktop.
Save yojimbo87/1174296 to your computer and use it in GitHub Desktop.
DB structures
{
_id: uint, //gives us format :101123 for replies, etc
owner_id: int,
text: String,
room: int, // id of room
starred: [user_id], // ids of users
flagged: [user_id], // ids of users
timestamp: timestamp, // all timestamps are in unix from UTC
deleted: timestamp, // null indicates not deleted
deletedBy: user_id, // indicates who deleted the message
history: [ { user : user_id, text : String, edited : timestamp } ]
}
/*=====================================================================================================
- entirely in CouchDB
- views: latest_messages (n configurable), messages_range (from, to)
-----------------------------------------------------------------------------------------------------*/
{
message_id: int,
flagged: [user_id], // ids of users
}
{
message_id: int,
starred: [user_id], // ids of users
}
Users Model:
- createUser(userObject)
- authorizeUser(email, password)
-----------------------
- getUser(userID)
- getUserHistogram(userID)
- getUserIgnored(userID)
- gerUserRooms(userID)
-----------------------
- updateUser(userID, userObject)
- updateUserHistogram(userID, histogramData)
- updateUserIgnored(userID, ignoredData) - add/remove ignored user
- updateUserRooms(userID, roomsData) - add/remove room
=============================================================
Rooms Model:
- createRoom(roomData)
-----------------------
- getRooms(startIndex, count)
- getRoomOwners(roomID)
- getRoomWriteAcess(roomID)
- getRoomReadAccess(roomID)
- getRoomCurrentUsers(roomID)
-----------------------
- updateRoom(roomID, roomData)
- updateRoomOwners(roomID, ownersData)
- updateRoomWriteAcess(roomID, data) - add/remove access
- updateRoomReadAccess(roomID, data) - add/remove access
- updateRoomCurrentUsers(roomID, users) - add/remove users
=============================================================
Messages Model:
- createMessage(messageData)
-----------------------
- getLatestMessages(count)
- getMessagesRange(startIndex, count)
-----------------------
- updateMessage(messageID, data)
{
_id: uint,
owners: [user_id], // ids
name: String,
description: String,
created: timestamp,
created_by: user_id,
last_message: message_id, // we can link back all the info we need from this or denormalize later
total_messages: uint,
total_messages_24hours: uint,
total_users_ever: uint,
total_users_now: uint,
histogram: [int], // ask me about this later .. I want histograms just like SO has on everything
state: int, //locked_deleted/deleted/frozen/active
type: int, //public/gallery/private
explicit_write_access: [user_id], // don't need to be exposed to the user _per-se_
explicit_read_access: [user_id], // don't need to be exposed to the user _per-se_
}
/*=====================================================================================================
rooms (LIST - list of room ids - room:123, room:124, ...)
-----------------------------------------------------------------------------------------------------
room:{id} (HASH)
- _id: uint,
- name: String,
- description: String,
- created: timestamp,
- created_by: user_id,
- last_message: message_id, // we can link back all the info we need from this or denormalize later
- total_messages: uint,
- total_messages_24hours: uint,
- total_users_ever: uint,
- total_users_now: uint,
- state: int, //locked_deleted/deleted/frozen/active
- type: int, //public/gallery/private
-----------------------------------------------------------------------------------------------------
room:{id}:owners (SET - user:123, user:354, ...)
-----------------------------------------------------------------------------------------------------
room:{id}:write_acess (SET - user:123, user:354, ...)
-----------------------------------------------------------------------------------------------------
room:{id}:read_access (SET - user:123, user:354, ...)
-----------------------------------------------------------------------------------------------------
room:{id}:current_users (SET - user:123, user:354, ...)
-----------------------------------------------------------------------------------------------------
room:{id}:users_ever (SET - user:123, user:354, ...)
-----------------------------------------------------------------------------------------------------*/
{
submitter: user_id,
text: String,
expiry: timestamp, //may be falsy, requires a user to clear it if so
}
{
_id: int, //users can be negative. Negative users indicates a system account
name: String,
email: String,
password_hash: String,
website: String,
introduction: String,
gravatar_hash: String,
histogram: [int],
rooms_currently_in: [room_id],
last_seen: timestamp,
last_sent_message: message_id,
last_spoke_here: timestamp, // this is only for use on the client, has no need on the server, per-se
total_messages_sent: uint, // can be decremented on deletes
total_flags_ever: uint,
banned: timestamp, // may be null or falsy, indicates no ban active
banned_duration: long, // to be added to the timestamp?
ignored_users: [user_id], // to allow people to ignore others (do we need to support by room ignore?)
role: int, // admin / moderator / user / guest? / trial-admin?
can_talk: bool,
can_read: bool,
}
/*=====================================================================================================
user:{id} - (HASH)
- _id: int, //users can be negative. Negative users indicates a system account
- name: String,
- email: String,
- password_hash: String,
- website: String,
- introduction: String,
- gravatar_hash: String,
- last_seen: timestamp,
- last_sent_message: message_id,
- last_spoke_here: timestamp, // this is only for use on the client, has no need on the server, per-se
- total_messages_sent: uint, // can be decremented on deletes
- total_flags_ever: uint,
- banned: timestamp, // may be null or falsy, indicates no ban active
- banned_duration: long, // to be added to the timestamp?
- role: int, // admin / moderator / user / guest? / trial-admin?
- can_talk: bool,
- can_read: bool,
-----------------------------------------------------------------------------------------------------
user:{id}:histogram - (SET - int array)
-----------------------------------------------------------------------------------------------------
user:{id}:ignored_users - (SET - user:123, user:354, ...)
-----------------------------------------------------------------------------------------------------
user:{id}:rooms_currently_in - (SET - room:123, room:354, ...)
-----------------------------------------------------------------------------------------------------*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment