Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created September 3, 2012 16:39
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 anonymous/3610610 to your computer and use it in GitHub Desktop.
Save anonymous/3610610 to your computer and use it in GitHub Desktop.
Informadiko Sample Schema
#!/usr/bin/mongo informadiko
// ┏━┓┏━╸┏━╸┏━┓╻ ╻┏┓╻╺┳╸┏━┓
// ┣━┫┃ ┃ ┃ ┃┃ ┃┃┗┫ ┃ ┗━┓
// ╹ ╹┗━╸┗━╸┗━┛┗━┛╹ ╹ ╹ ┗━┛
db.dropDatabase() // BE CAREFUL
//db.createCollection("system.profile", {capped:true, size:1024000000}) // 1024 Megs
db.setProfilingLevel(2);
db.accounts.ensureIndex({ '_id' : 1, 'timestamp' : 1}); // We do this for a very fun caching reason later on.
db.accounts.ensureIndex({ '_id' : 1, 'collections._id' : 1}); // Lets find those collections quickly.
// rethink //db.accounts.ensureIndex({ '_id' : 1, 'collections.indexed' : 1}); // Lets find new batches quickly.. possibly make this a less primary index later on
db.accounts.ensureIndex({ 'shortname' : 1, '_id' : 1 }); // We do this for a very fun caching reason later on.
// For readability only
company1_account = ObjectId('4f3daa355eb9736480000000');
company1_collection_cdr = ObjectId('4f3daa355eb9736480000005');
company1_collection_cdr_criteria_department = ObjectId('4f3daa355eb973648000000b');
company1_collection_cdr_criteria_destination = ObjectId('4f3daa355eb973648000000c');
company1_collection_cdr_criteria_source = ObjectId('4f3daa355eb973648000000a');
company1_collection_cdr_criteria_direction = ObjectId('4f3daa355eb9736480000009');
company1_collection_cdr_criteria_citystate = ObjectId('4f3daa355eb973648000000f');
company1_collection_cdr_criteria_disposition = ObjectId('4f3daa355eb97364800a0000');
company1_collection_monitored = ObjectId('4f3daa355eb9736480000006');
company1_collection_chat = ObjectId('4f3daa355eb9736480000007');
company1_collection_chat_company1_tv = ObjectId('4f3daa355eb9736480000008');
company1_template_cdr_1 = ObjectId('4f3daa355eb97364800000f0');
company1_template_cdr_2 = ObjectId('4f3daa355eb97364800000f1');
company1_template_monitored_1 = ObjectId('4f3daa355eb97364800000d1');
company1_template_company1_tv_1 = ObjectId('4f3daa355eb97364800000f5');
company1_criteria_company1_tv_1_source = ObjectId('4f3daa355eb9736480000ff1');
company1_criteria_company1_tv_1_destination = ObjectId('4f3daa355eb9736480000ff2');
company1_criteria_company1_tv_1_chat = ObjectId('4f3daa355eb9736480000ff3');
company2_account = ObjectId('4f3daa355eb9736480000001');
company2_collection_cdr = ObjectId('4f3daa355eb9736480000011');
company2_collection_monitored = ObjectId('4f3daa355eb9736480000012');
shane_user = ObjectId('4f3c4dd75eb973500f000000');
// there are two templates with the same shortname. This is because they need to be timestamped and selected when reindexing documents for a new template.. multiple template support? sure... Templates should not be overwritten
db.accounts.save({
'_id' : company1_account,
'timestamp' : 1329617789.376707,
'name' : 'company1',
'shortname' : 'company10000',
'collection_shortnames': {
'cdr': company1_collection_cdr,
'monitored': company1_collection_monitored,
'chatlogs': company1_collection_chat,
'company1tv': company1_collection_chat_company1_tv,
},
'collections' : [
{
'_id' : company1_collection_cdr,
'name' : 'Call Detail Records (CDR)',
'shortname' : 'cdr',
'path' : [company1_collection_cdr],
'links' : [
{
'collection': company1_collection_monitored,
'shortname': 'monitored',
'label': 'Monitor File',
'description': 'Should the call detail record be checked first to see if it contains a monitor file link?'
}
],
'summary': 'Call from <B>{{ src }}</B> to <B>{{ dst }}</B>',
'template_shortnames': {
'default': company1_template_cdr_1,
},
'templates': [
{
'_id': company1_template_cdr_1,
'shortname': 'default',
'type': 'detailtable',
'metadata': true,
'links': true,
'elements': [
{'name': 'Date', 'date': 'effective', 'type': 'datetime'},
{'name': 'Source', 'meta': 'src', 'type': 'string'},
{'name': 'Destination', 'meta': 'dst', 'type': 'string'},
{'name': 'Duration', 'meta': 'duration', 'type': 'dms'},
{'name': 'Disposition', 'meta': 'disposition', 'type': 'string'},
{'name': 'Userfield', 'meta': 'userfield', 'type': 'string', 'full': true},
],
'timestamp': 1329790288.432687,
},
{
'_id': company1_template_cdr_2,
'shortname': 'default',
'type': 'detailtable',
'metadata': true,
'links': true,
'elements': [
['calldate', 'datetime'],
['display_source','string'],
['display_destination','display_destination'],
['duration', 'dms'],
['disposition', 'string'],
['userfield', 'string'],
],
'timestamp': 1329790289.833056,
}
],
'criteria_shortnames': {
'department': company1_collection_cdr_criteria_department,
'source': company1_collection_cdr_criteria_source,
'destination': company1_collection_cdr_criteria_destination,
'citystate': company1_collection_cdr_criteria_citystate,
'direction': company1_collection_cdr_criteria_direction,
'disposition': company1_collection_cdr_criteria_disposition,
},
'criteria' : [
{
'_id' : company1_collection_cdr_criteria_department,
'label' : 'Department',
'shortname': 'department',
'type' : 'text',
'description' : 'internal department shared by this call',
},
{
'_id' : company1_collection_cdr_criteria_source,
'label' : 'Source',
'shortname': 'source',
'type' : 'text',
'extra' : {
'exact_startswith_endswith': 'exact',
}
},
{
'_id' : company1_collection_cdr_criteria_destination,
'label' : 'Destination',
'shortname': 'destination',
'type' : 'text',
'extra' : {
'exact_startswith_endswith': 'startswith',
}
},
{
'_id' : company1_collection_cdr_criteria_citystate,
'label' : 'Caller City/State (Where did this call originate from?)',
'shortname': 'citystate',
'type' : 'text',
},
{
'_id' : company1_collection_cdr_criteria_direction,
'label' : 'Call Direction',
'shortname': 'direction',
'type' : 'select',
'ignore': ['inout'],
'default' : 'inout',
'choices' : [
['inout','Inbound and Outbound'],
['in','Inbound Only'],
['out','Outbound Only'],
['internal','Internal'],
],
},
{
'_id' : company1_collection_cdr_criteria_disposition,
'label' : 'Call disposition',
'shortname': 'disposition',
'type' : 'select',
'ignore': ['any'],
'default' : 'any',
'choices' : [
['any','No Preference'],
['answered','Answered'],
['no answer','No Answer'],
],
},
],
},
{
'_id' : company1_collection_monitored,
'name' : 'Monitored Calls',
'icon' : 'images/tango/16x16/actions/media-record.png',
'shortname' : 'monitored',
'path' : [company1_collection_cdr, company1_collection_monitored],
'hidden' : true,
'template_shortnames': {
'default': company1_template_monitored_1,
},
'templates': [
{
'_id': company1_template_monitored_1,
'shortname': 'default',
'type': 'detailtable',
'metadata': true,
'links': true,
'elements': [
{'name': 'Date', 'date': 'effective', 'type': 'datetime'},
{'name': 'Link', 'meta': 'url', 'type': 'url', 'full': true},
],
'timestamp': 1329790288.432687,
},
],
},
{
'_id' : company1_collection_chat,
'shortname' : 'chatlogs',
'path' : [company1_collection_chat],
'name' : 'Chat Logs',
'templates': []
},
{
'_id' : company1_collection_chat_company1_tv,
'shortname' : 'company1tv',
'path' : [company1_collection_chat, company1_collection_chat_company1_tv],
'name' : 'iChat Server (chat.company1.tv)',
'template_shortnames': {
'default': company1_template_company1_tv_1,
},
'templates': [
{
'_id': company1_template_company1_tv_1,
'shortname': 'default',
'type': 'detailtable',
'metadata': true,
'links': true,
'elements': [
{'name': 'Date', 'date': 'effective', 'type': 'datetime'},
{'name': 'Source', 'meta': 'src', 'type': 'string'},
{'name': 'Destination', 'meta': 'dst', 'type': 'string'},
{'name': 'Chat', 'meta': 'chat', 'type': 'string', 'wrap': true, 'full': true},
],
'timestamp': 1329790288.432687,
},
],
'criteria_shortnames': {
'source': company1_criteria_company1_tv_1_source,
'destination': company1_criteria_company1_tv_1_destination,
'chat': company1_criteria_company1_tv_1_chat,
},
'criteria' : [
{
'_id' : company1_criteria_company1_tv_1_source,
'label' : 'Source',
'shortname': 'source',
'type' : 'text',
},
{
'_id' : company1_criteria_company1_tv_1_destination,
'label' : 'Destination',
'shortname': 'destination',
'type' : 'text',
},
{
'_id' : company1_criteria_company1_tv_1_chat,
'label' : 'Chat',
'shortname': 'chat',
'type' : 'text',
'extra' : {
'exact_startswith_endswith': 'startswith',
}
},
],
}
],
'paths': [
[company1_collection_cdr],
[company1_collection_cdr, company1_collection_monitored],
[company1_collection_chat],
[company1_collection_chat, company1_collection_chat_company1_tv],
],
'timezone': 'America/Anchorage',
'timezones': {
'United States of America': {
'Alaska': {
'America/Adak': 'Adak, Alaska, USA',
'America/Anchorage': 'Anchorage, Alaska, USA',
},
'Idaho': {
'America/Los_Angeles': 'Coeur\'d Alene, Idaho, USA',
},
'Hawaii': {
'Pacific/Honolulu': 'Kapolei, Hawaii, USA',
'Pacific/Honolulu': 'Kona, Hawaii, USA',
},
},
'Misc': {
'UTC': {
'UTC': 'UTC',
},
},
},
});
db.accounts.save({
'_id' : company2_account,
'timestamp' : 1329617789.376707,
'name' : 'Liberty Telecom',
'shortname' : 'company2com0000',
'collections_shortnames': {
'cdr': company2_collection_cdr,
'monitored': company2_collection_monitored,
},
'collections' : [
{
'_id' : company2_collection_cdr,
'name' : 'Call Detail Records (CDR)',
'shortname' : 'cdr',
'path': [company2_collection_cdr],
'links' : [ company2_collection_monitored ],
'templates': []
},
{
'_id' : company2_collection_monitored,
'name' : 'Monitored Calls',
'shortname' : 'monitored',
'path': [company2_collection_cdr, company2_collection_monitored],
'hidden' : true,
'templates': []
}
],
'paths': [
[company2_collection_cdr],
[company2_collection_cdr, company2_collection_monitored],
],
'timezone': 'America/Anchorage',
'timezones': {
'United States of America': {
'Alaska': {
'America/Anchorage': 'Anchorage, Alaska, USA',
},
},
'Asia': {
'Phillipines': {
'Asia/Manila': 'Manila, Metro Manila, Phillipines',
},
},
'Misc': {
'UTC': {
'UTC': 'UTC',
},
},
},
});
// ╻ ╻┏━┓┏━╸┏━┓┏━┓
// ┃ ┃┗━┓┣╸ ┣┳┛┗━┓
// ┗━┛┗━┛┗━╸╹┗╸┗━┛
db.users.ensureIndex({ '_id' : 1, 'timestamp' : 1});
db.users.ensureIndex({ 'username' : 1, 'password' : 1, '_id' : 1});
db.users.save({
'_id': shane_user,
'timestamp' : 1329617789.376707,
'username': 'shanespencer',
'firstname': 'Shane',
'lastname': 'Spencer',
'password': '$2a$12$Z62NF.c6f38bFWnM4hf2ce2RejrPHqGsc7IvLupYXuZgDfc9bDM2u',
'nickname': 'whardier',
'accounts': [
{
'_id': company1_account,
'active': true,
'timezone': 'America/Anchorage',
},
{
'_id': company2_account,
'active': true,
'timezone': 'America/Anchorage',
}
],
'timezones': {
'United States of America': {
'Alaska': {
'America/Anchorage': 'Anchorage, Alaska, USA',
},
},
'Misc': {
'UTC': {
'UTC': 'UTC',
},
},
},
});
// TODO: Add collection level access
// ╺┳┓┏━┓┏━╸╻ ╻┏┳┓┏━╸┏┓╻╺┳╸┏━┓
// ┃┃┃ ┃┃ ┃ ┃┃┃┃┣╸ ┃┗┫ ┃ ┗━┓
// ╺┻┛┗━┛┗━╸┗━┛╹ ╹┗━╸╹ ╹ ╹ ┗━┛
db.documents.attachments.chunks.ensureIndex({'account': 1, 'collection': 1, 'files_id' : 1, 'n' : 1 }, {'unique' : true})
db.documents.ensureIndex({'account': 1, 'collection': 1, '_id': 1})
db.documents.ensureIndex({'account': 1, 'collection': 1, 'batch': 1, 'indexed': 1}) //test sparse
db.documents.ensureIndex({'account': 1, 'collection': 1, '_uuid': 1, '_id': 1})
db.documents.batches.ensureIndex({'indexed': 1, '_id': 1})
db.documents.batches.ensureIndex({'account': 1, 'collection': 1, '_id': 1}) // find it quickly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment